Browse Source

[typer] cache nonexistent module lookups

see #10678
Simon Krajewski 3 years ago
parent
commit
d97de43317
2 changed files with 8 additions and 1 deletions
  1. 2 0
      src/context/common.ml
  2. 6 1
      src/typing/typeloadModule.ml

+ 2 - 0
src/context/common.ml

@@ -376,6 +376,7 @@ type context = {
 	stored_typed_exprs : (int, texpr) lookup;
 	overload_cache : ((path * string),(Type.t * tclass_field) list) lookup;
 	module_lut : (path,module_def) lookup;
+	module_nonexistent_lut : (path,bool) lookup;
 	type_to_module : (path,path) lookup;
 	mutable has_error : bool;
 	pass_debug_messages : string DynArray.t;
@@ -790,6 +791,7 @@ let create compilation_step cs version args =
 		callbacks = new compiler_callbacks;
 		modules = [];
 		module_lut = new hashtbl_lookup;
+		module_nonexistent_lut = new hashtbl_lookup;
 		type_to_module = new hashtbl_lookup;
 		main = None;
 		flash_version = 10.;

+ 6 - 1
src/typing/typeloadModule.ml

@@ -795,6 +795,10 @@ let load_module' ctx g m p =
 		| Some m ->
 			m
 		| None ->
+			let raise_not_found () =
+				raise (Error (Module_not_found m,p))
+			in
+			if ctx.com.module_nonexistent_lut#mem m then raise_not_found();
 			let is_extern = ref false in
 			let file, decls = try
 				(* Try parsing *)
@@ -803,7 +807,8 @@ let load_module' ctx g m p =
 				(* Nothing to parse, try loading extern type *)
 				let rec loop = function
 					| [] ->
-						raise (Error (Module_not_found m,p))
+						ctx.com.module_nonexistent_lut#add m true;
+						raise_not_found()
 					| (file,load) :: l ->
 						match load m p with
 						| None -> loop l