Browse Source

Merge branch 'development' into coroutines_2024

Simon Krajewski 1 year ago
parent
commit
d52d1b663b

+ 1 - 1
src/compiler/hxb/hxbReader.ml

@@ -963,7 +963,7 @@ class hxb_reader
 			| 5 -> VUser TVOLocalFunction
 			| 6 -> VGenerated
 			| 7 -> VInlined
-			| 8 -> VInlinedConstructorVariable
+			| 8 -> VInlinedConstructorVariable (self#read_list (fun () -> self#read_string))
 			| 9 -> VExtractorVariable
 			| 10 -> VAbstractThis
 			| _ -> assert false

+ 16 - 14
src/compiler/hxb/hxbWriter.ml

@@ -980,20 +980,22 @@ module HxbWriter = struct
 			Chunk.write_uleb128 writer.chunk (Pool.add writer.enum_fields key (en,ef))
 
 	let write_var_kind writer vk =
-		let b = match vk with
-			| VUser TVOLocalVariable -> 0
-			| VUser TVOArgument -> 1
-			| VUser TVOForVariable -> 2
-			| VUser TVOPatternVariable -> 3
-			| VUser TVOCatchVariable -> 4
-			| VUser TVOLocalFunction -> 5
-			| VGenerated -> 6
-			| VInlined -> 7
-			| VInlinedConstructorVariable -> 8
-			| VExtractorVariable -> 9
-			| VAbstractThis -> 10
-		in
-		Chunk.write_u8 writer.chunk b
+		let b,sl = match vk with
+			| VUser TVOLocalVariable -> 0, []
+			| VUser TVOArgument -> 1, []
+			| VUser TVOForVariable -> 2, []
+			| VUser TVOPatternVariable -> 3, []
+			| VUser TVOCatchVariable -> 4, []
+			| VUser TVOLocalFunction -> 5, []
+			| VGenerated -> 6, []
+			| VInlined -> 7, []
+			| VInlinedConstructorVariable sl -> 8, sl
+			| VExtractorVariable -> 9, []
+			| VAbstractThis -> 10, []
+		in begin
+			Chunk.write_u8 writer.chunk b;
+			if (b == 8) then Chunk.write_list writer.chunk sl (Chunk.write_string writer.chunk);
+		end
 
 	let write_var writer fctx v =
 		Chunk.write_uleb128 writer.chunk v.v_id;

+ 1 - 1
src/core/tPrinting.ml

@@ -601,7 +601,7 @@ module Printer = struct
 			| TVOLocalFunction -> "TVOLocalFunction") ^ ")"
 		| VGenerated -> "VGenerated"
 		| VInlined -> "VInlined"
-		| VInlinedConstructorVariable -> "VInlinedConstructorVariable"
+		| VInlinedConstructorVariable sl -> "VInlinedConstructorVariable" ^ "(" ^ (String.concat ", " sl) ^ ")"
 		| VExtractorVariable -> "VExtractorVariable"
 		| VAbstractThis -> "VAbstractThis"
 

+ 1 - 1
src/core/tType.ml

@@ -144,7 +144,7 @@ and tvar_kind =
 	| VUser of tvar_origin
 	| VGenerated
 	| VInlined
-	| VInlinedConstructorVariable
+	| VInlinedConstructorVariable of string list
 	| VExtractorVariable
 	| VAbstractThis
 

+ 1 - 1
src/filters/filters.ml

@@ -103,7 +103,7 @@ let check_local_vars_init ctx e =
 		| TVar (v,eo) ->
 			begin
 				match eo with
-				| None when v.v_kind = VInlinedConstructorVariable ->
+				| None when (match v.v_kind with VInlinedConstructorVariable _ -> true | _ -> false) ->
 					()
 				| None ->
 					declared := v.v_id :: !declared;

+ 6 - 3
src/generators/genhl.ml

@@ -1001,14 +1001,17 @@ let real_name v =
 	in
 	match loop v.v_meta with
 	| "_gthis" -> "this"
-	| name -> name
+	| name -> match v.v_kind with
+		| VInlinedConstructorVariable sl -> String.concat "." sl
+		| _ -> name
 
-let is_gen_local ctx v = match v.v_kind with
+let not_debug_var ctx v = match v.v_kind with
 	| VUser _ -> false
+	| VInlinedConstructorVariable _ -> false
 	| _ -> true
 
 let add_assign ctx v =
-	if is_gen_local ctx v then () else
+	if not_debug_var ctx v then () else
 	let name = real_name v in
 	ctx.m.massign <- (alloc_string ctx name, current_pos ctx - 1) :: ctx.m.massign
 

+ 1 - 1
src/macro/eval/evalJit.ml

@@ -655,7 +655,7 @@ and jit_expr jit return e =
 				wrap()
 			| TUnop((Increment | Decrement),_,e1) | TBinop((OpAssign | OpAssignOp _),e1,_) ->
 				begin match (Texpr.skip e1).eexpr with
-				| TLocal {v_kind = VGenerated | VInlined | VInlinedConstructorVariable | VExtractorVariable} ->
+				| TLocal {v_kind = VGenerated | VInlined | VInlinedConstructorVariable _ | VExtractorVariable} ->
 					f
 				| _ ->
 					wrap()

+ 1 - 1
src/optimization/analyzer.ml

@@ -664,7 +664,7 @@ module LocalDce = struct
 			has_var_flag v VAnalyzed
 		in
 		let keep v =
-			is_used v || ((match v.v_kind with VUser _ | VInlined -> true | _ -> false) && not ctx.config.local_dce) || ExtType.has_reference_semantics v.v_type || has_var_flag v VCaptured || Meta.has Meta.This v.v_meta
+			is_used v || ((match v.v_kind with VUser _ | VInlined | VInlinedConstructorVariable _ -> true | _ -> false) && not ctx.config.local_dce) || ExtType.has_reference_semantics v.v_type || has_var_flag v VCaptured || Meta.has Meta.This v.v_meta
 		in
 		let rec use v =
 			if not (is_used v) then begin

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -790,7 +790,7 @@ module Fusion = struct
 			let num_uses = state#get_reads v in
 			let num_writes = state#get_writes v in
 			let can_be_used_as_value = can_be_used_as_value com e in
-			let is_compiler_generated = match v.v_kind with VUser _ | VInlined -> false | _ -> true in
+			let is_compiler_generated = match v.v_kind with VUser _ | VInlined | VInlinedConstructorVariable _ -> false | _ -> true in
 			let has_type_params = match v.v_extra with Some ve when ve.v_params <> [] -> true | _ -> false in
 			let rec is_impure_extern e = match e.eexpr with
 				| TField(ef,(FStatic(cl,cf) | FInstance(cl,_,cf))) when has_class_flag cl CExtern ->

+ 18 - 5
src/optimization/inlineConstructors.ml

@@ -731,22 +731,35 @@ let inline_constructors ctx original_e =
 		let cf = ctx.f.curfield in
 		if !included_untyped && not (Meta.has Meta.HasUntyped cf.cf_meta) then cf.cf_meta <- (Meta.HasUntyped,[],e.epos) :: cf.cf_meta;
 		let e = make_expr_for_rev_list el e.etype e.epos in
-		let rec get_pretty_name iv = match iv.iv_kind with
+		let rec get_pretty_name iv : string list = match iv.iv_kind with
 			| IVKField(io,fname,None) ->
 				begin try
 					let is_user_variable iv = match iv.iv_var.v_kind with VUser _ | VInlined -> true | _ -> false in
 					let iv = List.find is_user_variable io.io_aliases in
-					(get_pretty_name iv) ^ "_" ^ fname;
+					fname :: (get_pretty_name iv);
 				with Not_found ->
-					(get_pretty_name (List.hd io.io_aliases)) ^ "_" ^ fname;
+					fname :: (get_pretty_name (List.hd io.io_aliases));
 				end
-			| _ -> iv.iv_var.v_name
+			| _ -> [iv.iv_var.v_name]
+		in
+		let is_user_kind iv = match iv.iv_var.v_kind with VUser _ -> true | _ -> false in
+		let rec was_user iv = match iv.iv_kind with
+			| IVKField(io,_,_) ->
+				begin try
+					let iv = List.find is_user_kind io.io_aliases in
+					(was_user iv);
+				with Not_found ->
+					(was_user (List.hd io.io_aliases)) ;
+				end
+			| _ -> is_user_kind iv
 		in
 		IntMap.iter (fun _ iv ->
 			let v = iv.iv_var in
 			if v.v_id < 0 then begin
 				v.v_id <- -v.v_id;
-				v.v_name <- get_pretty_name iv
+				let vnames = List.rev (get_pretty_name iv) in
+				v.v_name <- String.concat "_" vnames;
+				if (was_user iv) then v.v_kind <- VInlinedConstructorVariable vnames;
 			end
 		) !vars;
 		e

+ 7 - 3
src/typing/operators.ml

@@ -866,6 +866,10 @@ let type_unop ctx op flag e with_type p =
 			| None -> vr#to_texpr e
 			| Some e' -> vr#to_texpr_el [e] e'
 		in
+		let make_op vr binop e1 e2 p =
+			let result = make_binop ctx binop e1 e2 false p in
+			BinopResult.to_texpr vr result (fun _ -> raise Not_found)
+		in
 		let rec loop access_set = match access_set with
 			| AKNo(acc,p) ->
 				begin try
@@ -887,7 +891,7 @@ let type_unop ctx op flag e with_type p =
 					let e_set = FieldAccess.get_field_expr {fa with fa_on = ef} FWrite in
 					let e_lhs = acc_get ctx access_get in
 					let e_lhs,e_out = maybe_tempvar_postfix vr e_lhs in
-					let e_op = mk (TBinop(binop,e_lhs,e_one)) e_lhs.etype p in
+					let e_op = make_op vr binop e_lhs e_one p in
 					mk (TBinop(OpAssign,e_set,e_op)) e_set.etype p,e_out
 				in
 				generate vr e_out e
@@ -896,14 +900,14 @@ let type_unop ctx op flag e with_type p =
 				let ef = vr#get_expr_part "fh" fa.fa_on in
 				let fa = {fa with fa_on = ef} in
 				let e_lhs,e_out = read_on vr ef fa in
-				let e_op = mk (TBinop(binop,e_lhs,e_one)) e_lhs.etype p in
+				let e_op = make_op vr binop e_lhs e_one p in
 				let dispatcher = new call_dispatcher ctx (MSet None) WithType.value p in
 				let e = dispatcher#accessor_call fa [e_op] [] in
 				generate vr e_out e
 			| AKUsingAccessor sea ->
 				let ef,vr = process_lhs_expr ctx "fh" sea.se_this in
 				let e_lhs,e_out = read_on vr ef sea.se_access in
-				let e_op = mk (TBinop(binop,e_lhs,e_one)) e_lhs.etype p in
+				let e_op = make_op vr binop e_lhs e_one p in
 				let dispatcher = new call_dispatcher ctx (MSet None) WithType.value p in
 				let e = dispatcher#accessor_call sea.se_access [ef;e_op] [] in
 				generate vr e_out e

+ 1 - 1
src/typing/typeloadCheck.ml

@@ -519,7 +519,7 @@ module Inheritance = struct
 				match m with
 				| Meta.AutoBuild, el, p -> c.cl_meta <- (Meta.Build,el,{ c.cl_pos with pmax = c.cl_pos.pmin }(* prevent display metadata *)) :: m :: c.cl_meta
 				| _ -> ()
-			) csup.cl_meta;
+			) (List.rev csup.cl_meta);
 			if has_class_flag csup CFinal && not (((has_class_flag csup CExtern) && Meta.has Meta.Hack c.cl_meta) || (match c.cl_kind with KTypeParameter _ -> true | _ -> false)) then
 				raise_typing_error ("Cannot extend a final " ^ if (has_class_flag c CInterface) then "interface" else "class") p;
 		in

+ 27 - 0
tests/misc/projects/Issue11582/Macro.macro.hx

@@ -0,0 +1,27 @@
+class Macro {
+	static var id = 0;
+	static function build(i:String) {
+		if (haxe.macro.Context.getLocalClass().get().isInterface) return null;
+
+		var hasMacros = false;
+		var fields = haxe.macro.Context.getBuildFields();
+		for (f in fields) {
+			if (f.name == "macros") {
+				hasMacros = true;
+				break;
+			}
+		}
+
+		if (!hasMacros)
+			fields = (macro class A {
+				public static var macros = [];
+			}).fields.concat(fields);
+
+		var id = '_' + id++;
+		fields.push((macro class A {
+			 static var $id = {macros.push($v{i}); 0;};
+		}).fields[0]);
+
+		return fields;
+	}
+}

+ 51 - 0
tests/misc/projects/Issue11582/Main.hx

@@ -0,0 +1,51 @@
+class Main {
+	static function main() {
+		trace("Foo");
+		trace(Foo1.macros);
+		trace(Foo2.macros);
+		trace(Foo3.macros);
+		trace(Foo4.macros);
+
+		trace("Bar");
+		trace(Bar1.macros);
+		trace(Bar2.macros);
+		trace(Bar3.macros);
+
+		trace("Baz");
+		trace(Baz1.macros);
+		trace(Baz2.macros);
+		trace(Baz3.macros);
+	}
+}
+
+@:autoBuild(Macro.build("I1"))
+interface I1 {}
+
+@:autoBuild(Macro.build("I2"))
+interface I2 {}
+
+@:autoBuild(Macro.build("auto Foo1 (1)"))
+@:autoBuild(Macro.build("auto Foo1 (2)"))
+@:build(Macro.build("Foo1"))
+class Foo1 implements I1 implements I2 {}
+
+@:build(Macro.build("Foo2"))
+class Foo2 extends Foo1 {}
+
+@:build(Macro.build("Foo3 (1)"))
+@:build(Macro.build("Foo3 (2)"))
+class Foo3 extends Foo2 {}
+
+@:build(Macro.build("Foo4"))
+class Foo4 extends Foo3 {}
+
+class Bar1 implements I2 implements I1 {}
+class Bar2 extends Bar1 {}
+class Bar3 extends Bar2 {}
+
+@:autoBuild(Macro.build("I3"))
+interface I3 extends I1 {}
+
+class Baz1 implements I3 implements I2 {}
+class Baz2 extends Baz1 {}
+class Baz3 extends Baz2 {}

+ 2 - 0
tests/misc/projects/Issue11582/compile.hxml

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

+ 13 - 0
tests/misc/projects/Issue11582/compile.hxml.stdout

@@ -0,0 +1,13 @@
+Main.hx:3: Foo
+Main.hx:4: [I2,I1,Foo1]
+Main.hx:5: [I2,I1,auto Foo1 (1),auto Foo1 (2),Foo2]
+Main.hx:6: [I2,I1,auto Foo1 (1),auto Foo1 (2),Foo3 (1),Foo3 (2)]
+Main.hx:7: [I2,I1,auto Foo1 (1),auto Foo1 (2),Foo4]
+Main.hx:9: Bar
+Main.hx:10: [I1,I2]
+Main.hx:11: [I1,I2]
+Main.hx:12: [I1,I2]
+Main.hx:14: Baz
+Main.hx:15: [I2,I1,I3]
+Main.hx:16: [I2,I1,I3]
+Main.hx:17: [I2,I1,I3]

+ 3 - 1
tests/server/src/TestCase.hx

@@ -18,7 +18,9 @@ using StringTools;
 using Lambda;
 
 @:autoBuild(utils.macro.BuildHub.build())
-class TestCase implements ITest {
+interface ITestCase {}
+
+class TestCase implements ITest implements ITestCase {
 	static public var debugLastResult:{
 		hasError:Bool,
 		stdout:String,