Răsfoiți Sursa

[typer] move build_count to typer globals

Simon Krajewski 1 an în urmă
părinte
comite
07918a068a

+ 1 - 0
src/context/typecore.ml

@@ -116,6 +116,7 @@ type typer_globals = {
 	mutable load_only_cached_modules : bool;
 	functional_interface_lut : (path,tclass_field) lookup;
 	mutable return_partial_type : bool;
+	mutable build_count : int;
 	(* api *)
 	do_macro : typer -> macro_mode -> path -> string -> expr list -> pos -> macro_result;
 	do_load_macro : typer -> bool -> path -> string -> pos -> ((string * bool * t) list * t * tclass * Type.tclass_field);

+ 0 - 2
src/typing/typeload.ml

@@ -33,8 +33,6 @@ open Typecore
 open Error
 open Globals
 
-let build_count = ref 0
-
 let type_function_params_ref = ref (fun _ _ _ _ _ -> die "" __LOC__)
 
 let check_field_access ctx cff =

+ 4 - 4
src/typing/typeloadModule.ml

@@ -393,7 +393,7 @@ module TypeLevel = struct
 				add_class_flag c CFinal;
 			end
 		) d.d_meta;
-		let prev_build_count = ref (!build_count - 1) in
+		let prev_build_count = ref (ctx.g.build_count - 1) in
 		let build() =
 			c.cl_build <- (fun()-> Building [c]);
 			let fl = TypeloadCheck.Inheritance.set_heritance ctx c herits p in
@@ -403,7 +403,7 @@ module TypeLevel = struct
 					List.iter (fun f -> f()) fl;
 					TypeloadFields.init_class ctx c p d.d_flags d.d_data;
 					c.cl_build <- (fun()-> Built);
-					incr build_count;
+					ctx.g.build_count <- ctx.g.build_count + 1;
 					List.iter (fun tp -> ignore(follow tp.ttp_type)) c.cl_params;
 					Built;
 				with TypeloadCheck.Build_canceled state ->
@@ -414,8 +414,8 @@ module TypeLevel = struct
 					(match state with
 					| Built -> die "" __LOC__
 					| Building cl ->
-						if !build_count = !prev_build_count then raise_typing_error ("Loop in class building prevent compiler termination (" ^ String.concat "," (List.map (fun c -> s_type_path c.cl_path) cl) ^ ")") c.cl_pos;
-						prev_build_count := !build_count;
+						if ctx.g.build_count = !prev_build_count then raise_typing_error ("Loop in class building prevent compiler termination (" ^ String.concat "," (List.map (fun c -> s_type_path c.cl_path) cl) ^ ")") c.cl_pos;
+						prev_build_count := ctx.g.build_count;
 						rebuild();
 						Building (c :: cl)
 					| BuildMacro f ->

+ 1 - 0
src/typing/typerEntry.ml

@@ -26,6 +26,7 @@ let create com macros =
 			type_hints = [];
 			load_only_cached_modules = false;
 			return_partial_type = false;
+			build_count = 0;
 			functional_interface_lut = new Lookup.pmap_lookup;
 			do_macro = MacroContext.type_macro;
 			do_load_macro = MacroContext.load_macro';