Browse Source

Merge branch 'development' into fix/hxml-not-found

Simon Krajewski 5 months ago
parent
commit
393f0fafea

+ 3 - 3
src/codegen/dump.ml

@@ -123,7 +123,7 @@ let dump_types com pretty =
 		close()
 	in
 	Parallel.run_in_new_pool (fun pool ->
-		Parallel.run_parallel_on_array pool (Array.of_list com.types) f
+		Parallel.ParallelArray.iter pool f (Array.of_list com.types)
 	)
 
 let dump_record com =
@@ -139,7 +139,7 @@ let dump_record com =
 		close()
 	in
 	Parallel.run_in_new_pool (fun pool ->
-		Parallel.run_parallel_on_array pool (Array.of_list com.types) f
+		Parallel.ParallelArray.iter pool f (Array.of_list com.types)
 	)
 
 let dump_position com =
@@ -164,7 +164,7 @@ let dump_position com =
 				()
 	in
 	Parallel.run_in_new_pool (fun pool ->
-		Parallel.run_parallel_on_array pool (Array.of_list com.types) f
+		Parallel.ParallelArray.iter pool f (Array.of_list com.types)
 	)
 
 let dump_types com =

+ 11 - 7
src/context/parallel.ml

@@ -3,14 +3,18 @@ let run_parallel_for num_domains ?(chunk_size=0) length f =
 	Domainslib.Task.run pool (fun _ -> Domainslib.Task.parallel_for pool ~chunk_size ~start:0 ~finish:(length-1) ~body:f);
 	Domainslib.Task.teardown_pool pool
 
-let run_parallel_on_array pool a f =
-	let f' idx = f a.(idx) in
-	let old = Atomic.exchange Timer.in_parallel true in
-	Domainslib.Task.run pool (fun _ -> Domainslib.Task.parallel_for pool ~start:0 ~finish:(Array.length a - 1) ~body:f');
-	Atomic.set Timer.in_parallel old
+module ParallelArray = struct
+	let iter pool f a =
+		let f' idx = f a.(idx) in
+		let old = Atomic.exchange Timer.in_parallel true in
+		Domainslib.Task.run pool (fun _ -> Domainslib.Task.parallel_for pool ~start:0 ~finish:(Array.length a - 1) ~body:f');
+		Atomic.set Timer.in_parallel old
+end
 
-let run_parallel_on_seq pool seq f =
-	run_parallel_on_array pool (Array.of_seq seq) f
+module ParallelSeq = struct
+	let iter pool f seq =
+		ParallelArray.iter pool f (Array.of_seq seq)
+end
 
 let run_in_new_pool f =
 	let pool = Domainslib.Task.setup_pool ~num_domains:(Domain.recommended_domain_count() - 1) () in

+ 3 - 3
src/core/tFunctions.ml

@@ -71,14 +71,14 @@ let has_var_flag v (flag : flag_tvar) =
 (* ======= General utility ======= *)
 
 let alloc_var' =
-	let uid = ref 0 in
+	let uid = Atomic.make 0 in
 	uid,(fun kind n t p ->
-		incr uid;
+		Atomic.incr uid;
 		{
 			v_kind = kind;
 			v_name = n;
 			v_type = t;
-			v_id = !uid;
+			v_id = Atomic.get uid;
 			v_extra = None;
 			v_meta = [];
 			v_pos = p;

+ 3 - 3
src/generators/genjvm.ml

@@ -2974,7 +2974,7 @@ let generate_anons gctx pool =
 		write_class gctx path (jc#export_class gctx.default_export_config)
 	in
 	let seq = Hashtbl.to_seq gctx.anon_identification#get_pfms in
-	Parallel.run_parallel_on_seq pool seq run
+	Parallel.ParallelSeq.iter pool run seq
 
 let generate_typed_functions gctx =
 	let jc_function = gctx.typed_functions#generate in
@@ -3168,11 +3168,11 @@ let generate jvm_flag gctx =
 
 	let generate pool =
 		let generate_real_types () =
-			Parallel.run_parallel_on_array pool (Array.of_list gctx.gctx.types) (generate_module_type gctx)
+			Parallel.ParallelArray.iter pool (generate_module_type gctx) (Array.of_list gctx.gctx.types)
 		in
 		let generate_typed_interfaces () =
 			let seq = Hashtbl.to_seq gctx.typedef_interfaces#get_interfaces in
-			Parallel.run_parallel_on_seq pool seq (fun (_,c) -> generate_module_type gctx (TClassDecl c));
+			Parallel.ParallelSeq.iter pool (fun (_,c) -> generate_module_type gctx (TClassDecl c)) seq;
 		in
 		run_timed gctx false "preprocess" (fun () -> Preprocessor.preprocess gctx);
 		run_timed gctx false "real types" generate_real_types;

+ 4 - 3
src/generators/hl2c.ml

@@ -1413,16 +1413,17 @@ let generate_module_types ctx m =
 		match t with
 		| HObj o | HStruct o ->
 			let name = tname o.pname in
+			let td_name = tname ("_" ^ o.pname) in
 			ctx.defined_types <- PMap.add t () ctx.defined_types;
-			define ctx (sprintf "typedef struct _%s *%s;" name name);
+			define ctx (sprintf "typedef struct %s *%s;" td_name name);
 		| _ -> ()
 	) types;
 	line "";
 	List.iter (fun t ->
 		match t with
 		| HObj op | HStruct op ->
-			let name = tname op.pname in
-			line ("struct _" ^ name ^ " {");
+			let name = tname ("_" ^ op.pname) in
+			line ("struct " ^ name ^ " {");
 			block ctx;
 			let rec loop o =
 				(match o.psuper with

+ 16 - 9
src/optimization/analyzer.ml

@@ -1119,7 +1119,7 @@ module Run = struct
 		let e = Type.map_expr (reduce_control_flow com) e in
 		Optimizer.reduce_control_flow com e
 
-	let run_on_field com config c cf = match cf.cf_expr with
+	let run_on_field' com config c cf = match cf.cf_expr with
 		| Some e when not (is_ignored cf.cf_meta) && not (Typecore.is_removable_field com cf) && not (has_class_field_flag cf CfPostProcessed) ->
 			let config = update_config_from_meta com config cf.cf_meta in
 			let actx = create_analyzer_context com config (Printf.sprintf "%s.%s" (s_type_path c.cl_path) cf.cf_name) e in
@@ -1154,14 +1154,18 @@ module Run = struct
 		| _ -> ()
 
 	let run_on_field com config c cf =
-		run_on_field com config c cf;
-		List.iter (run_on_field com config c) cf.cf_overloads
+		run_on_field' com config c cf;
+		List.iter (run_on_field' com config c) cf.cf_overloads
 
-	let run_on_class com config c =
+	let run_on_class com pool config c =
 		let config = update_config_from_meta com config c.cl_meta in
+		let fields = DynArray.create () in
 		let process_field stat cf = match cf.cf_kind with
-			| Var _ when not stat -> ()
-			| _ -> run_on_field com config c cf
+			| Var _ when not stat ->
+				()
+			| _ ->
+				DynArray.add fields cf;
+				List.iter (DynArray.add fields) cf.cf_overloads
 		in
 		List.iter (process_field false) c.cl_ordered_fields;
 		List.iter (process_field true) c.cl_ordered_statics;
@@ -1169,6 +1173,7 @@ module Run = struct
 			| None -> ()
 			| Some f -> process_field false f;
 		end;
+		Parallel.ParallelArray.iter pool (run_on_field' com config c) (DynArray.to_array fields);
 		begin match TClass.get_cl_init c with
 			| None ->
 				()
@@ -1184,10 +1189,10 @@ module Run = struct
 				TClass.set_cl_init c e
 		end
 
-	let run_on_type com config t =
+	let run_on_type com pool config t =
 		match t with
 		| TClassDecl c when (is_ignored c.cl_meta) -> ()
-		| TClassDecl c -> run_on_class com config c
+		| TClassDecl c -> run_on_class com pool config c
 		| TEnumDecl _ -> ()
 		| TTypeDecl _ -> ()
 		| TAbstractDecl _ -> ()
@@ -1197,7 +1202,9 @@ module Run = struct
 		with_timer config.detail_times "" ["other"] (fun () ->
 			if config.optimize && config.purity_inference then
 				with_timer config.detail_times "" ["optimize";"purity-inference"] (fun () -> Purity.infer com);
-			List.iter (run_on_type com config) types
+			Parallel.run_in_new_pool (fun pool ->
+				Parallel.ParallelArray.iter pool (run_on_type com pool config) (Array.of_list types);
+			)
 		)
 end
 ;;

+ 3 - 3
src/optimization/analyzerTypes.ml

@@ -343,10 +343,10 @@ module Graph = struct
 		Hashtbl.add g.g_functions bb.bb_id (bb,t,p,tf)
 
 	let alloc_id =
-		let r = ref 1 in
+		let r = Atomic.make 1 in
 		(fun () ->
-			incr r;
-			!r
+			Atomic.incr r;
+			Atomic.get r
 		)
 
 	let create_node g kind t p =

+ 1 - 1
src/typing/typeloadFields.ml

@@ -1781,7 +1781,7 @@ let init_class ctx_c cctx c p herits fields =
 		| _ ->
 			()
 	end;
-	if not has_struct_init && not (has_class_flag c CAbstract) then
+	if not has_struct_init then
 		(* add_constructor does not deal with overloads correctly *)
 		if not com.config.pf_overload then TypeloadFunction.add_constructor ctx_c c cctx.force_constructor p;
 	finalize_class cctx

+ 2 - 2
src/typing/typeloadModule.ml

@@ -762,8 +762,8 @@ class hxb_reader_api_typeload
 	method get_var_id (i : int) =
 		(* The v_id in .hxb has no relation to this context, make a new one. *)
 		let uid = fst alloc_var' in
-		incr uid;
-		!uid
+		Atomic.incr uid;
+		Atomic.get uid
 
 	method read_expression_eagerly (cf : tclass_field) =
 		com.is_macro_context || match cf.cf_kind with

+ 1 - 1
std/python/_std/sys/thread/Thread.hx

@@ -124,7 +124,7 @@ private class HxThread {
 			}
 			dropThread(nt);
 		}
-		nt = new NativeThread({target:wrappedCallB});
+		nt = new NativeThread({target:wrappedCallB, daemon: true});
 		t = new HxThread(nt);
 		if(withEventLoop)
 			t.events = new EventLoop();

+ 0 - 22
tests/misc/projects/Issue12023/Macro.hx

@@ -1,22 +0,0 @@
-import haxe.macro.Context;
-import haxe.macro.Expr.Field;
-import haxe.macro.Type.ClassType;
-
-using haxe.macro.TypeTools;
-
-class Macro {
-	public static macro function build():Array<Field> {
-		var fields:Array<Field> = Context.getBuildFields();
-		var classType:ClassType = Context.getLocalClass().get();
-
-		if (classType.isAbstract) {
-			fields.push({
-				name: "someFieldToAbstractClass",
-				pos: Context.currentPos(),
-				kind: FVar(macro :Int, macro $v{1})
-			});
-		}
-
-		return fields;
-	}
-}

+ 0 - 16
tests/misc/projects/Issue12023/Main.hx

@@ -1,16 +0,0 @@
-class Main extends MyAbstractClass {
-	static function main() {
-		trace('myVar = ${new Main().myVar}');
-	}
-
-	public function new() {}
-}
-
-abstract class MyAbstractClass implements MyInterface {
-	public final myVar:Int;
-}
-
-@:autoBuild(Macro.build())
-interface MyInterface {
-	public final myVar:Int;
-}

+ 0 - 2
tests/misc/projects/Issue12023/compile-fail.hxml

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

+ 0 - 2
tests/misc/projects/Issue12023/compile-fail.hxml.stderr

@@ -1,2 +0,0 @@
-Main.hx:1: characters 7-11 : Some final fields are uninitialized in this class
-Main.hx:10: characters 15-20 : Uninitialized field

+ 1 - 1
tests/unit/compile-each.hxml

@@ -11,4 +11,4 @@
 -D analyzer-optimize
 -D analyzer-user-var-fusion
 -D message.reporting=pretty
--D haxe-next
+-D haxe-next

+ 9 - 0
tests/unit/src/Complex.hx

@@ -0,0 +1,9 @@
+class Complex {
+	public var i:Float;
+	public var j:Float;
+
+	public function new(inI:Float, inJ:Float) {
+		i = inI;
+		j = inJ;
+	}
+}

+ 9 - 0
tests/unit/src/unit/issues/Issue12089.hx

@@ -0,0 +1,9 @@
+package unit.issues;
+
+class Issue12089 extends Test {
+	function test() {
+		var c = new Complex(1, 2);
+		feq(1., c.i);
+		feq(2., c.j);
+	}
+}