Переглянути джерело

remove g.std_types, instead clone root resolution list directly

Simon Krajewski 6 місяців тому
батько
коміт
df6422eb60

+ 11 - 0
src/context/resolution.ml

@@ -180,6 +180,17 @@ class resolution_list (id : string list) = object(self)
 	method get_list =
 		l
 
+	method set_list l' =
+		l <- l';
+		cached_type_imports <- false
+
+	method clone_as (id : string list) =
+		self#resolve_lazies;
+		let rl = new resolution_list id in
+		rl#set_list l;
+		rl#cache_type_imports;
+		rl
+
 	method cache_type_imports =
 		let rec loop = function
 		| [] ->

+ 0 - 1
src/context/typecore.ml

@@ -97,7 +97,6 @@ type typer_globals = {
 	retain_meta : bool;
 	mutable core_api : typer option;
 	mutable macros : ((unit -> unit) * typer) option;
-	mutable std_types : module_def;
 	mutable module_check_policies : (string list * module_check_policy list * bool) list;
 	mutable global_using : (tclass * pos) list;
 	(* Indicates that Typer.create() finished building this instance *)

+ 1 - 10
src/typing/typeloadModule.ml

@@ -686,10 +686,7 @@ module TypeLevel = struct
 end
 
 let make_curmod com g m =
-	let rl = new resolution_list ["import";s_type_path m.m_path] in
-	List.iter (fun mt ->
-		rl#add (module_type_resolution mt None null_pos))
-	(List.rev g.std_types.m_types);
+	let rl = g.root_typer.m.import_resolution#clone_as ["import";s_type_path m.m_path] in
 	{
 		curmod = m;
 		import_resolution = rl;
@@ -706,12 +703,6 @@ let make_curmod com g m =
 let type_types_into_module com g m tdecls p =
 	let ctx_m = TyperManager.clone_for_module g.root_typer (make_curmod com g m) in
 	let imports_and_usings,decls = ModuleLevel.create_module_types ctx_m m tdecls p in
-	(* define the per-module context for the next pass *)
-	if ctx_m.g.std_types != null_module then begin
-		add_dependency m ctx_m.g.std_types MDepFromTyping;
-		(* this will ensure both String and (indirectly) Array which are basic types which might be referenced *)
-		ignore(load_instance ctx_m (make_ptp (mk_type_path (["std"],"String")) null_pos) ParamNormal LoadNormal)
-	end;
 	ModuleLevel.init_type_params ctx_m decls;
 	List.iter (TypeLevel.init_imports_or_using ctx_m) imports_and_usings;
 	(* setup module types *)

+ 4 - 8
src/typing/typerEntry.ml

@@ -7,17 +7,14 @@ open Resolution
 open Error
 
 let load_std_types ctx =
-	ctx.g.std_types <- (try
+	let std_types = try
 		TypeloadModule.load_module ctx ([],"StdTypes") null_pos
 	with
 		Error { err_message = Module_not_found ([],"StdTypes") } ->
 			Error.raise_std_not_found ()
-	);
-	(* We always want core types to be available so we add them as default imports (issue #1904 and #3131). *)
-	List.iter (fun mt ->
-		ctx.m.import_resolution#add (module_type_resolution mt None null_pos))
-	(List.rev ctx.g.std_types.m_types);
+	in
 	List.iter (fun t ->
+		ctx.m.import_resolution#add (module_type_resolution t None null_pos);
 		match t with
 		| TAbstractDecl a ->
 			(match snd a.a_path with
@@ -64,7 +61,7 @@ let load_std_types ctx =
 			end
 		| TEnumDecl _ | TClassDecl _ ->
 			()
-	) ctx.g.std_types.m_types
+	) (List.rev std_types.m_types)
 
 let load_string ctx =
 	let m = TypeloadModule.load_module ctx ([],"String") null_pos in
@@ -139,7 +136,6 @@ let create com macros =
 			delayed_min_index = 0;
 			debug_delayed = [];
 			retain_meta = Common.defined com Define.RetainUntypedMeta;
-			std_types = null_module;
 			global_using = [];
 			complete = false;
 			type_hints = [];