Răsfoiți Sursa

[macro] flush pass in typing-timer

Also make `cast_of_unify` go through typing-timer. Closes #6402
Simon Krajewski 8 ani în urmă
părinte
comite
35ae6be170

+ 2 - 3
src/macro/macroApi.ml

@@ -45,7 +45,7 @@ type 'value compiler_api = {
 	delayed_macro : int -> (unit -> (unit -> 'value));
 	use_cache : unit -> bool;
 	format_string : string -> Globals.pos -> Ast.expr;
-	cast_or_unify : Type.t -> texpr -> Globals.pos -> Type.texpr;
+	cast_or_unify : Type.t -> texpr -> Globals.pos -> bool;
 	add_global_metadata : string -> string -> (bool * bool * bool) -> unit;
 	add_module_check_policy : string list -> int list -> bool -> int -> unit;
 	decode_expr : 'value -> Ast.expr;
@@ -1558,8 +1558,7 @@ let macro_api ccom get_api =
 		);
 		"unify", vfun2 (fun t1 t2 ->
 			let e1 = mk (TObjectDecl []) (decode_type t1) Globals.null_pos in
-			try ignore(((get_api()).cast_or_unify) (decode_type t2) e1 Globals.null_pos); vbool true
-			with Error.Error (Error.Unify _,_) -> vbool false
+			vbool (((get_api()).cast_or_unify) (decode_type t2) e1 Globals.null_pos)
 		);
 		"typeof", vfun1 (fun v ->
 			encode_type ((get_api()).type_expr (decode_expr v)).etype

+ 11 - 2
src/macro/macroContext.ml

@@ -92,7 +92,10 @@ let typing_timer ctx need_type f =
 	*)
 	(*if ctx.com.display = DMNone then ctx.com.error <- (fun e p -> raise (Error(Custom e,p)));*) (* TODO: review this... *)
 	ctx.com.error <- (fun e p -> raise (Error(Custom e,p)));
-	if need_type && ctx.pass < PTypeField then ctx.pass <- PTypeField;
+	if need_type && ctx.pass < PTypeField then begin
+		ctx.pass <- PTypeField;
+		flush_pass ctx PBuildClass "typing_timer";
+	end;
 	let exit() =
 		t();
 		ctx.com.error <- old;
@@ -337,7 +340,13 @@ let make_macro_api ctx p =
 			ctx.g.do_format_string ctx s p
 		);
 		MacroApi.cast_or_unify = (fun t e p ->
-			AbstractCast.cast_or_unify_raise ctx t e p
+			typing_timer ctx true (fun () ->
+				try
+					ignore(AbstractCast.cast_or_unify_raise ctx t e p);
+					true
+				with Error (Unify _,_) ->
+					false
+			)
 		);
 		MacroApi.add_global_metadata = (fun s1 s2 config ->
 			let meta = (match Parser.parse_string ctx.com (s2 ^ " typedef T = T") null_pos error false with

+ 39 - 0
tests/misc/projects/Issue6402/Main.hx

@@ -0,0 +1,39 @@
+import haxe.macro.Expr;
+import haxe.macro.*;
+
+class Base {}
+class Extended extends Base {}
+
+class Builder {
+    #if macro
+    static public function checkUnify():Void {
+        var baseType = ComplexTypeTools.toType(macro:Base);
+        var extendedType = ComplexTypeTools.toType(macro:Extended);
+        var unify = Context.unify(extendedType, baseType);
+        Sys.stderr().writeString("Extended unifies Base? " + unify + "\n");
+    }
+    #end
+    macro static public function build():Array<Field> {
+        Sys.stderr().writeString("in @:build\n");
+        checkUnify();
+        var fields = Context.getBuildFields();
+        return fields;
+    }
+}
+
+#if !macro
+@:build(Builder.build())
+#end
+class Main {
+    var extended:Extended;
+
+    macro static function checkUnify() {
+        Sys.stderr().writeString("in macro function\n");
+        Builder.checkUnify();
+        return macro {};
+    }
+
+    static function main() {
+        checkUnify();
+    }
+}

+ 1 - 0
tests/misc/projects/Issue6402/compile.hxml

@@ -0,0 +1 @@
+-main Main

+ 4 - 0
tests/misc/projects/Issue6402/compile.hxml.stderr

@@ -0,0 +1,4 @@
+in @:build
+Extended unifies Base? true
+in macro function
+Extended unifies Base? true