Parcourir la source

[typer] abstract some common lookups

Simon Krajewski il y a 3 ans
Parent
commit
f9475a4461

+ 2 - 2
src/codegen/overloads.ml

@@ -84,10 +84,10 @@ let collect_overloads map c i =
 
 let get_overloads (com : Common.context) c i =
 	try
-		Hashtbl.find com.overload_cache (c.cl_path,i)
+		com.overload_cache#find (c.cl_path,i)
 	with Not_found ->
 		let l = collect_overloads (fun t -> t) c i in
-		Hashtbl.add com.overload_cache (c.cl_path,i) l;
+		com.overload_cache#add (c.cl_path,i) l;
 		l
 
 (** Overload resolution **)

+ 5 - 5
src/compiler/displayProcessing.ml

@@ -194,13 +194,13 @@ let load_display_module_in_macro tctx display_file_dot_path clear = match displa
 				display mode. This covers some cases like --macro typing it in non-display mode (issue #7017). *)
 			if clear then begin
 				begin try
-					let m = Hashtbl.find mctx.com.module_lut cpath in
-					Hashtbl.remove mctx.com.module_lut cpath;
-					Hashtbl.remove mctx.com.type_to_module cpath;
+					let m = mctx.com.module_lut#find cpath in
+					mctx.com.module_lut#remove cpath;
+					mctx.com.type_to_module#remove cpath;
 					List.iter (fun mt ->
 						let ti = Type.t_infos mt in
-						Hashtbl.remove mctx.com.module_lut ti.mt_path;
-						Hashtbl.remove mctx.com.type_to_module ti.mt_path;
+						mctx.com.module_lut#remove ti.mt_path;
+						mctx.com.type_to_module#remove ti.mt_path;
 					) m.m_types
 				with Not_found ->
 					()

+ 96 - 34
src/context/common.ml

@@ -265,6 +265,68 @@ type report_mode =
 	| RMDiagnostics of Path.UniqueKey.t list
 	| RMStatistics
 
+class virtual ['key,'value] lookup = object(self)
+	method virtual add : 'key -> 'value -> unit
+	method virtual remove : 'key -> unit
+	method virtual find : 'key -> 'value
+	method virtual iter : ('key -> 'value -> unit) -> unit
+	method virtual fold : 'acc . ('key -> 'value -> 'acc -> 'acc) -> 'acc -> 'acc
+	method virtual mem : 'key -> bool
+	method virtual clear : unit
+end
+
+class ['key,'value] pmap_lookup = object(self)
+	inherit ['key,'value] lookup
+	val mutable lut : ('key,'value) PMap.t = PMap.empty
+
+	method add (key : 'key) (value : 'value) =
+		lut <- PMap.add key value lut
+
+	method remove (key : 'key) =
+		lut <- PMap.remove key lut
+
+	method find (key : 'key) : 'value =
+		PMap.find key lut
+
+	method iter (f : 'key -> 'value -> unit) =
+		PMap.iter f lut
+
+	method fold : 'acc . ('key -> 'value -> 'acc -> 'acc) -> 'acc -> 'acc = fun f acc ->
+		PMap.foldi f lut acc
+
+	method mem (key : 'key) =
+		PMap.mem key lut
+
+	method clear =
+		lut <- PMap.empty
+end
+
+class ['key,'value] hashtbl_lookup = object(self)
+	inherit ['key,'value] lookup
+	val lut : ('key,'value) Hashtbl.t = Hashtbl.create 0
+
+	method add (key : 'key) (value : 'value) =
+		Hashtbl.replace lut key value
+
+	method remove (key : 'key) =
+		Hashtbl.remove lut key
+
+	method find (key : 'key) : 'value =
+		Hashtbl.find lut key
+
+	method iter (f : 'key -> 'value -> unit) =
+		Hashtbl.iter f lut
+
+	method fold : 'acc . ('key -> 'value -> 'acc -> 'acc) -> 'acc -> 'acc = fun f acc ->
+		Hashtbl.fold f lut acc
+
+	method mem (key : 'key) =
+		Hashtbl.mem lut key
+
+	method clear =
+		Hashtbl.clear lut
+end
+
 type context = {
 	compilation_step : int;
 	mutable stage : compiler_stage;
@@ -305,18 +367,18 @@ type context = {
 	(* typing state *)
 	shared : shared_context;
 	display_information : display_information;
-	file_lookup_cache : (string,string option) Hashtbl.t;
+	file_lookup_cache : (string,string option) lookup;
 	file_keys : file_keys;
-	readdir_cache : (string * string,(string array) option) Hashtbl.t;
-	parser_cache : (string,(type_def * pos) list) Hashtbl.t;
-	module_to_file : (path,string) Hashtbl.t;
-	cached_macros : (path * string,(((string * bool * t) list * t * tclass * Type.tclass_field) * module_def)) Hashtbl.t;
-	mutable stored_typed_exprs : (int, texpr) PMap.t;
-	pass_debug_messages : string DynArray.t;
-	overload_cache : ((path * string),(Type.t * tclass_field) list) Hashtbl.t;
+	readdir_cache : (string * string,(string array) option) lookup;
+	parser_cache : (string,(type_def * pos) list) lookup;
+	module_to_file : (path,string) lookup;
+	cached_macros : (path * string,(((string * bool * t) list * t * tclass * Type.tclass_field) * module_def)) lookup;
+	stored_typed_exprs : (int, texpr) lookup;
+	overload_cache : ((path * string),(Type.t * tclass_field) list) lookup;
+	module_lut : (path,module_def) lookup;
+	type_to_module : (path,path) lookup;
 	mutable has_error : bool;
-	module_lut : (path , module_def) Hashtbl.t;
-	type_to_module : (path, path) Hashtbl.t;
+	pass_debug_messages : string DynArray.t;
 	(* output *)
 	mutable file : string;
 	mutable features : (string,bool) Hashtbl.t;
@@ -727,8 +789,8 @@ let create compilation_step cs version args =
 		types = [];
 		callbacks = new compiler_callbacks;
 		modules = [];
-		module_lut = Hashtbl.create 0;
-		type_to_module = Hashtbl.create 0;
+		module_lut = new hashtbl_lookup;
+		type_to_module = new hashtbl_lookup;
 		main = None;
 		flash_version = 10.;
 		resources = Hashtbl.create 0;
@@ -752,7 +814,6 @@ let create compilation_step cs version args =
 		get_messages = (fun() -> []);
 		filter_messages = (fun _ -> ());
 		pass_debug_messages = DynArray.create();
-		overload_cache = Hashtbl.create 0;
 		basic = {
 			tvoid = m;
 			tint = m;
@@ -762,14 +823,15 @@ let create compilation_step cs version args =
 			tstring = m;
 			tarray = (fun _ -> die "" __LOC__);
 		};
-		file_lookup_cache = Hashtbl.create 0;
+		file_lookup_cache = new hashtbl_lookup;
 		file_keys = new file_keys;
-		readdir_cache = Hashtbl.create 0;
-		module_to_file = Hashtbl.create 0;
-		stored_typed_exprs = PMap.empty;
-		cached_macros = Hashtbl.create 0;
+		readdir_cache = new hashtbl_lookup;
+		module_to_file = new hashtbl_lookup;
+		stored_typed_exprs = new hashtbl_lookup;
+		cached_macros = new hashtbl_lookup;
 		memory_marker = memory_marker;
-		parser_cache = Hashtbl.create 0;
+		parser_cache = new hashtbl_lookup;
+		overload_cache = new hashtbl_lookup;
 		json_out = None;
 		has_error = false;
 		report_mode = RMNone;
@@ -796,10 +858,6 @@ let clone com is_macro_context =
 		basic = { t with tvoid = t.tvoid };
 		main_class = None;
 		features = Hashtbl.create 0;
-		file_lookup_cache = Hashtbl.create 0;
-		readdir_cache = Hashtbl.create 0;
-		parser_cache = Hashtbl.create 0;
-		module_to_file = Hashtbl.create 0;
 		callbacks = new compiler_callbacks;
 		display_information = {
 			unresolved_identifiers = [];
@@ -811,10 +869,14 @@ let clone com is_macro_context =
 			defines_signature = com.defines.defines_signature;
 		};
 		native_libs = create_native_libs();
-		overload_cache = Hashtbl.create 0;
 		is_macro_context = is_macro_context;
-		module_lut = Hashtbl.create 0;
-		type_to_module = Hashtbl.create 0;
+		file_lookup_cache = new hashtbl_lookup;
+		readdir_cache = new hashtbl_lookup;
+		parser_cache = new hashtbl_lookup;
+		module_to_file = new hashtbl_lookup;
+		overload_cache = new hashtbl_lookup;
+		module_lut = new hashtbl_lookup;
+		type_to_module = new hashtbl_lookup;
 	}
 
 let file_time file = Extc.filetime file
@@ -957,7 +1019,7 @@ let cache_directory ctx class_path dir f_dir =
 		try Some (Sys.readdir dir);
 		with Sys_error _ -> None
 	in
-	Hashtbl.add ctx.readdir_cache (class_path,dir) dir_listing;
+	ctx.readdir_cache#add (class_path,dir) dir_listing;
 	(*
 		This function is invoked for each file in the `dir`.
 		Each file is checked if it's specific for current platform
@@ -991,23 +1053,23 @@ let cache_directory ctx class_path dir f_dir =
 			- or this is a platform-specific file for `representation`
 			- this `representation` was never found before
 		*)
-		if is_loading_core_api || is_platform_specific || not (Hashtbl.mem ctx.file_lookup_cache representation) then begin
+		if is_loading_core_api || is_platform_specific || not (ctx.file_lookup_cache#mem representation) then begin
 			let full_path = if dir = "." then file_own_name else dir ^ "/" ^ file_own_name in
-			Hashtbl.replace ctx.file_lookup_cache representation (Some full_path);
+			ctx.file_lookup_cache#add representation (Some full_path);
 		end
 	in
 	Option.may (Array.iter prepare_file) dir_listing
 
 let find_file ctx f =
 	try
-		match Hashtbl.find ctx.file_lookup_cache f with
+		match ctx.file_lookup_cache#find f with
 		| None -> raise Exit
 		| Some f -> f
 	with
 	| Exit ->
 		raise Not_found
 	| Not_found when Path.is_absolute_path f ->
-		Hashtbl.add ctx.file_lookup_cache f (Some f);
+		ctx.file_lookup_cache#add f (Some f);
 		f
 	| Not_found ->
 		let f_dir = Filename.dirname f in
@@ -1019,13 +1081,13 @@ let find_file ctx f =
 				let dir = Filename.dirname file in
 				(* If we have seen the directory before, we can assume that the file isn't in there because the else case
 				   below would have added it to `file_lookup_cache`, which we check before we get here. *)
-				if Hashtbl.mem ctx.readdir_cache (p,dir) then
+				if ctx.readdir_cache#mem (p,dir) then
 					loop (had_empty || p = "") l
 				else begin
 					cache_directory ctx p dir f_dir;
 					(* Caching might have located the file we're looking for, so check the lookup cache again. *)
 					try
-						begin match Hashtbl.find ctx.file_lookup_cache f with
+						begin match ctx.file_lookup_cache#find f with
 						| Some f -> f
 						| None -> raise Not_found
 						end
@@ -1034,7 +1096,7 @@ let find_file ctx f =
 				end
 		in
 		let r = try Some (loop false ctx.class_path) with Not_found -> None in
-		Hashtbl.add ctx.file_lookup_cache f r;
+		ctx.file_lookup_cache#add f r;
 		match r with
 		| None -> raise Not_found
 		| Some f -> f

+ 1 - 1
src/context/display/displayFields.ml

@@ -28,7 +28,7 @@ open DisplayTypes
 open Display
 
 let get_submodule_fields ctx path =
-	let m = Hashtbl.find ctx.com.module_lut path in
+	let m = ctx.com.module_lut#find path in
 	let tl = List.filter (fun t -> path <> (t_infos t).mt_path && not (t_infos t).mt_private) m.m_types in
 	let tl = List.map (fun mt ->
 		make_ci_type (CompletionItem.CompletionModuleType.of_module_type mt) ImportStatus.Imported None

+ 1 - 1
src/context/display/displayToplevel.ml

@@ -488,7 +488,7 @@ let collect ctx tk with_type sort =
 		end else if (List.exists (fun e -> ExtString.String.starts_with dot_path (e ^ ".")) !exclude) then
 			()
 		else begin
-			Hashtbl.replace ctx.com.module_to_file (cfile.c_package,module_name) cfile.c_file_path;
+			ctx.com.module_to_file#add (cfile.c_package,module_name) cfile.c_file_path;
 			if process_decls cfile.c_package module_name cfile.c_decls then check_package cfile.c_package;
 		end
 	) files;

+ 3 - 3
src/context/typecore.ml

@@ -435,7 +435,7 @@ let create_fake_module ctx file =
 		Hashtbl.add fake_modules key mdep;
 		mdep
 	) in
-	Hashtbl.replace ctx.com.module_lut mdep.m_path mdep;
+	ctx.com.module_lut#add mdep.m_path mdep;
 	mdep
 
 let push_this ctx e = match e.eexpr with
@@ -704,12 +704,12 @@ let get_next_stored_typed_expr_id =
 	(fun() -> incr uid; !uid)
 
 let get_stored_typed_expr com id =
-	let e = PMap.find id com.stored_typed_exprs in
+	let e = com.stored_typed_exprs#find id in
 	Texpr.duplicate_tvars e
 
 let store_typed_expr com te p =
 	let id = get_next_stored_typed_expr_id() in
-	com.stored_typed_exprs <- PMap.add id te com.stored_typed_exprs;
+	com.stored_typed_exprs#add id te;
 	let eid = (EConst (Int (string_of_int id, None))), p in
 	(EMeta ((Meta.StoredTypedExpr,[],p), eid)), p
 

+ 1 - 1
src/filters/filters.ml

@@ -380,7 +380,7 @@ let remove_extern_fields com t = match t with
 let check_private_path ctx t = match t with
 	| TClassDecl c when c.cl_private ->
 		let rpath = (fst c.cl_module.m_path,"_" ^ snd c.cl_module.m_path) in
-		if Hashtbl.mem ctx.com.type_to_module rpath then typing_error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
+		if ctx.com.type_to_module#mem rpath then typing_error ("This private class name will clash with " ^ s_type_path rpath) c.cl_pos;
 	| _ ->
 		()
 

+ 4 - 4
src/macro/macroApi.ml

@@ -1777,8 +1777,8 @@ let macro_api ccom get_api =
 		);
 		"flush_disk_cache", vfun0 (fun () ->
 			let com = (get_api()).get_com() in
-			Hashtbl.clear com.file_lookup_cache;
-			Hashtbl.clear com.readdir_cache;
+			com.file_lookup_cache#clear;
+			com.readdir_cache#clear;
 			vnull
 		);
 		"get_pos_infos", vfun1 (fun p ->
@@ -1882,8 +1882,8 @@ let macro_api ccom get_api =
 				mcom.class_path <- cp :: mcom.class_path;
 			| None ->
 				());
-			Hashtbl.clear com.file_lookup_cache;
-			Hashtbl.clear com.readdir_cache;
+			com.file_lookup_cache#clear;
+			com.readdir_cache#clear;
 			vnull
 		);
 		"add_native_lib", vfun1 (fun file ->

+ 1 - 1
src/optimization/inline.ml

@@ -112,7 +112,7 @@ let api_inline2 com c field params p =
 
 let api_inline ctx c field params p =
 	let mk_typeexpr path =
-		let m = (try Hashtbl.find ctx.com.module_lut path with Not_found -> die "" __LOC__) in
+		let m = (try ctx.com.module_lut#find path with Not_found -> die "" __LOC__) in
 		add_dependency ctx.m.curmod m;
 		Option.get (ExtList.List.find_map (function
 			| TClassDecl cl when cl.cl_path = path -> Some (make_static_this cl p)

+ 3 - 3
src/typing/finalization.ml

@@ -86,7 +86,7 @@ let finalize ctx =
 			()
 		| fl ->
 			let rec loop handled_types =
-				let all_types = Hashtbl.fold (fun _ m acc -> m.m_types @ acc) ctx.com.module_lut [] in
+				let all_types = ctx.com.module_lut#fold (fun _ m acc -> m.m_types @ acc) [] in
 				match (List.filter (fun mt -> not (List.memq mt handled_types)) all_types) with
 				| [] ->
 					()
@@ -102,7 +102,7 @@ type state =
 	| Done
 	| NotYet
 
-let sort_types com modules =
+let sort_types com (modules : (path,module_def) lookup) =
 	let types = ref [] in
 	let states = Hashtbl.create 0 in
 	let state p = try Hashtbl.find states p with Not_found -> NotYet in
@@ -193,7 +193,7 @@ let sort_types com modules =
 		) c.cl_statics
 
 	in
-	let sorted_modules = List.sort (fun m1 m2 -> compare m1.m_path m2.m_path) (Hashtbl.fold (fun _ m acc -> m :: acc) modules []) in
+	let sorted_modules = List.sort (fun m1 m2 -> compare m1.m_path m2.m_path) (modules#fold (fun _ m acc -> m :: acc) []) in
 	List.iter (fun m -> List.iter loop m.m_types) sorted_modules;
 	List.rev !types, sorted_modules
 

+ 4 - 4
src/typing/generic.ml

@@ -157,7 +157,7 @@ let static_method_container gctx c cf p =
 		| TInst(cg,_) -> cg
 		| _ -> typing_error ("Cannot specialize @:generic static method because the generated type name is already used: " ^ name) p
 	with Error(Module_not_found path,_) when path = (pack,name) ->
-		let m = (try Hashtbl.find ctx.com.module_lut (Hashtbl.find ctx.com.type_to_module c.cl_path) with Not_found -> die "" __LOC__) in
+		let m = (try ctx.com.module_lut#find (ctx.com.type_to_module#find c.cl_path) with Not_found -> die "" __LOC__) in
 		let mg = {
 			m_id = alloc_mid();
 			m_path = (pack,name);
@@ -168,7 +168,7 @@ let static_method_container gctx c cf p =
 		gctx.mg <- Some mg;
 		let cg = mk_class mg (pack,name) c.cl_pos c.cl_name_pos in
 		mg.m_types <- [TClassDecl cg];
-		Hashtbl.add ctx.com.module_lut mg.m_path mg;
+		ctx.com.module_lut#add mg.m_path mg;
 		add_dependency mg m;
 		add_dependency ctx.m.curmod mg;
 		cg
@@ -232,7 +232,7 @@ let rec build_generic_class ctx c p tl =
 		| TInst({ cl_kind = KGenericInstance (csup,_) },_) when c == csup -> t
 		| _ -> typing_error ("Cannot specialize @:generic because the generated type name is already used: " ^ name) p
 	with Error(Module_not_found path,_) when path = (pack,name) ->
-		let m = (try Hashtbl.find ctx.com.module_lut (Hashtbl.find ctx.com.type_to_module c.cl_path) with Not_found -> die "" __LOC__) in
+		let m = (try ctx.com.module_lut#find (ctx.com.type_to_module#find c.cl_path) with Not_found -> die "" __LOC__) in
 		ignore(c.cl_build()); (* make sure the super class is already setup *)
 		let mg = {
 			m_id = alloc_mid();
@@ -259,7 +259,7 @@ let rec build_generic_class ctx c p tl =
 		) c.cl_meta;
 		cg.cl_meta <- (Meta.NoDoc,[],null_pos) :: cg.cl_meta;
 		mg.m_types <- [TClassDecl cg];
-		Hashtbl.add ctx.com.module_lut mg.m_path mg;
+		ctx.com.module_lut#add mg.m_path mg;
 		add_dependency mg m;
 		add_dependency ctx.m.curmod mg;
 		set_type_parameter_dependencies mg tl;

+ 5 - 5
src/typing/macroContext.ml

@@ -318,7 +318,7 @@ let make_macro_api ctx p =
 			let types = imports @ usings @ types in
 			let mpath = Ast.parse_path m in
 			begin try
-				let m = Hashtbl.find ctx.com.module_lut mpath in
+				let m = ctx.com.module_lut#find mpath in
 				ignore(TypeloadModule.type_types_into_module ctx m types pos)
 			with Not_found ->
 				let mnew = TypeloadModule.type_module ctx mpath (Path.UniqueKey.lazy_path ctx.m.curmod.m_extra.m_file) types pos in
@@ -364,7 +364,7 @@ let make_macro_api ctx p =
 		MacroApi.add_module_check_policy = (fun sl il b i ->
 			let add ctx =
 				ctx.g.module_check_policies <- (List.fold_left (fun acc s -> (ExtString.String.nsplit s ".",List.map Obj.magic il,b) :: acc) ctx.g.module_check_policies sl);
-				Hashtbl.iter (fun _ m -> m.m_extra.m_check_policy <- TypeloadModule.get_policy ctx.g m.m_path) ctx.com.module_lut;
+				ctx.com.module_lut#iter (fun _ m -> m.m_extra.m_check_policy <- TypeloadModule.get_policy ctx.g m.m_path);
 			in
 			let add_macro ctx = match ctx.g.macros with
 				| None -> ()
@@ -526,7 +526,7 @@ let get_macro_context ctx p =
 
 let load_macro_module ctx cpath display p =
 	let api, mctx = get_macro_context ctx p in
-	let m = (try Hashtbl.find ctx.com.type_to_module cpath with Not_found -> cpath) in
+	let m = (try ctx.com.type_to_module#find cpath with Not_found -> cpath) in
 	(* Temporarily enter display mode while typing the macro. *)
 	let old = mctx.com.display in
 	if display then mctx.com.display <- ctx.com.display;
@@ -545,7 +545,7 @@ let load_macro_module ctx cpath display p =
 let load_macro' ctx display cpath f p =
 	let api, mctx = get_macro_context ctx p in
 	let mint = Interp.get_ctx() in
-	let (meth,mloaded) = try Hashtbl.find mctx.com.cached_macros (cpath,f) with Not_found ->
+	let (meth,mloaded) = try mctx.com.cached_macros#find (cpath,f) with Not_found ->
 		let t = macro_timer ctx ["typing";s_type_path cpath ^ "." ^ f] in
 		let mpath, sub = (match List.rev (fst cpath) with
 			| name :: pack when name.[0] >= 'A' && name.[0] <= 'Z' -> (List.rev pack,name), Some (snd cpath)
@@ -574,7 +574,7 @@ let load_macro' ctx display cpath f p =
 		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> typing_error "Macro call should be a method" p) in
 		restore();
 		if not ctx.com.is_macro_context then flush_macro_context mint ctx;
-		Hashtbl.add mctx.com.cached_macros (cpath,f) meth;
+		mctx.com.cached_macros#add (cpath,f) meth;
 		mctx.m <- {
 			curmod = null_module;
 			module_imports = [];

+ 3 - 3
src/typing/typeloadCheck.ml

@@ -323,12 +323,12 @@ let check_global_metadata ctx meta f_add mpath tpath so =
 let check_module_types ctx m p t =
 	let t = t_infos t in
 	try
-		let m2 = Hashtbl.find ctx.com.type_to_module t.mt_path in
+		let m2 = ctx.com.type_to_module#find t.mt_path in
 		if m.m_path <> m2 && String.lowercase (s_type_path m2) = String.lowercase (s_type_path m.m_path) then typing_error ("Module " ^ s_type_path m2 ^ " is loaded with a different case than " ^ s_type_path m.m_path) p;
 		typing_error ("Type name " ^ s_type_path t.mt_path ^ " is redefined from module " ^ s_type_path m2) p
 	with
 		Not_found ->
-			Hashtbl.add ctx.com.type_to_module t.mt_path m.m_path
+			ctx.com.type_to_module#add t.mt_path m.m_path
 
 module Inheritance = struct
 	let is_basic_class_path path = match path with
@@ -359,7 +359,7 @@ module Inheritance = struct
 				let cf = {f with cf_overloads = []} in
 				begin try
 					let cf' = PMap.find cf.cf_name c.cl_fields in
-					Hashtbl.remove ctx.com.overload_cache (c.cl_path,f.cf_name);
+					ctx.com.overload_cache#remove (c.cl_path,f.cf_name);
 					cf'.cf_overloads <- cf :: cf'.cf_overloads
 				with Not_found ->
 					TClass.add_field c cf

+ 1 - 1
src/typing/typeloadFields.ml

@@ -681,7 +681,7 @@ let transform_field (ctx,cctx) c f fields p =
 	in
 	if List.mem_assoc AMacro f.cff_access then
 		(match ctx.g.macros with
-		| Some (_,mctx) when Hashtbl.mem mctx.com.type_to_module c.cl_path ->
+		| Some (_,mctx) when mctx.com.type_to_module#mem c.cl_path ->
 			(* assume that if we had already a macro with the same name, it has not been changed during the @:build operation *)
 			if not (List.exists (fun f2 -> f2.cff_name = f.cff_name && List.mem_assoc AMacro f2.cff_access) (!fields)) then
 				typing_error "Class build macro cannot return a macro function when the class has already been compiled into the macro context" p

+ 6 - 6
src/typing/typeloadModule.ml

@@ -57,7 +57,7 @@ module ModuleLevel = struct
 
 	let add_module ctx m p =
 		List.iter (TypeloadCheck.check_module_types ctx m p) m.m_types;
-		Hashtbl.add ctx.com.module_lut m.m_path m
+		ctx.com.module_lut#add m.m_path m
 
 	(*
 		Build module structure : should be atomic - no type loading is possible
@@ -283,7 +283,7 @@ module ModuleLevel = struct
 		in
 		let candidates = loop path_split (fst m.m_path) in
 		let make_import_module path r =
-			Hashtbl.replace com.parser_cache path r;
+			com.parser_cache#add path r;
 			(* We use the file path as module name to make it unique. This may or may not be a good idea... *)
 			let m_import = make_module ctx ([],path) path p in
 			m_import.m_extra.m_kind <- MImport;
@@ -292,8 +292,8 @@ module ModuleLevel = struct
 		in
 		List.fold_left (fun acc path ->
 			let decls = try
-				let r = Hashtbl.find com.parser_cache path in
-				let mimport = Hashtbl.find com.module_lut ([],path) in
+				let r = com.parser_cache#find path in
+				let mimport = com.module_lut#find ([],path) in
 				if mimport.m_extra.m_kind <> MFake then add_dependency m mimport;
 				r
 			with Not_found ->
@@ -769,7 +769,7 @@ let type_types_into_module ?(check=true) ctx m tdecls p =
 *)
 let type_module ctx mpath file ?(dont_check_path=false) ?(is_extern=false) tdecls p =
 	let m = ModuleLevel.make_module ctx mpath file p in
-	Hashtbl.add ctx.com.module_lut m.m_path m;
+	ctx.com.module_lut#add m.m_path m;
 	let tdecls = ModuleLevel.handle_import_hx ctx m tdecls p in
 	let ctx = type_types_into_module ctx m tdecls p in
 	if is_extern then m.m_extra.m_kind <- MExtern else if not dont_check_path then Typecore.check_module_path ctx m.m_path p;
@@ -783,7 +783,7 @@ let type_module_hook = ref (fun _ _ _ -> None)
 
 let load_module' ctx g m p =
 	try
-		Hashtbl.find ctx.com.module_lut m
+		ctx.com.module_lut#find m
 	with
 		Not_found ->
 			match !type_module_hook ctx m p with

+ 2 - 2
src/typing/typeloadParse.ml

@@ -138,10 +138,10 @@ let resolve_module_file com m remap p =
 
 let resolve_module_file com m remap p =
 	try
-		Hashtbl.find com.module_to_file m
+		com.module_to_file#find m
 	with Not_found ->
 		let file = resolve_module_file com m remap p in
-		Hashtbl.add com.module_to_file m file;
+		com.module_to_file#add m file;
 		file
 
 (* let resolve_module_file com m remap p =

+ 1 - 1
src/typing/typer.ml

@@ -516,7 +516,7 @@ and handle_efield ctx e p0 mode with_type =
 							in
 							let pack,name,sub,p = loop [] None path in
 							let mpath = (pack,name) in
-							if Hashtbl.mem ctx.com.module_lut mpath then
+							if ctx.com.module_lut#mem mpath then
 								let tname = Option.default name sub in
 								raise (Error (Type_not_found (mpath,tname,Not_defined),p))
 							else