Преглед изворни кода

add IntHashtbl and StringHashtbl (#12106)

Simon Krajewski пре 5 месеци
родитељ
комит
06149e99d5

+ 0 - 11
src/compiler/hxb/hxbWriter.ml

@@ -45,17 +45,6 @@ let unop_index op flag = match op,flag with
 	| NegBits,Postfix -> 10
 	| Spread,Postfix -> 11
 
-module StringHashtbl = Hashtbl.Make(struct
-	type t = string
-
-	let equal =
-		String.equal
-
-	let hash s =
-		(* What's the best here? *)
-		Hashtbl.hash s
-end)
-
 module Pool = struct
 	type ('key,'value) t = {
 		lut : ('key,int) Hashtbl.t;

+ 1 - 10
src/core/ds/stringPool.ml

@@ -1,13 +1,4 @@
-module StringHashtbl = Hashtbl.Make(struct
-	type t = string
-
-	let equal =
-		String.equal
-
-	let hash s =
-		(* What's the best here? *)
-		Hashtbl.hash s
-end)
+open Globals
 
 type t = {
 	lut : int StringHashtbl.t;

+ 19 - 0
src/core/globals.ml

@@ -10,6 +10,25 @@ module IntMap = Map.Make(struct type t = int let compare i1 i2 = i2 - i1 end)
 module StringMap = Map.Make(struct type t = string let compare = String.compare end)
 module Int32Map = Map.Make(struct type t = Int32.t let compare = Int32.compare end)
 
+module IntHashtbl = Hashtbl.Make(struct
+	type t = int
+
+	let equal =
+		Int.equal
+
+	let hash = Int.hash
+end)
+
+module StringHashtbl = Hashtbl.Make(struct
+	type t = string
+
+	let equal =
+		String.equal
+
+	let hash s =
+		Hashtbl.hash s
+end)
+
 type platform =
 	| Cross
 	| Js

+ 5 - 4
src/filters/localStatic.ml

@@ -1,10 +1,11 @@
+open Globals
 open Type
 open Typecore
 open Error
 
 type lscontext = {
 	ctx : typer;
-	lut : (int,tclass_field) Hashtbl.t;
+	lut : tclass_field IntHashtbl.t;
 	mutable added_fields : tclass_field list;
 }
 
@@ -75,16 +76,16 @@ let promote_local_static lsctx run v eo =
 		lsctx.added_fields <- cf :: lsctx.added_fields;
 		(* Add to lookup early so that the duplication check works. *)
 		c.cl_statics <- PMap.add cf.cf_name cf c.cl_statics;
-		Hashtbl.add lsctx.lut v.v_id cf
+		IntHashtbl.add lsctx.lut v.v_id cf
 	end
 
 let find_local_static lut v =
-	Hashtbl.find lut v.v_id
+	IntHashtbl.find lut v.v_id
 
 let run ctx e =
 	let lsctx = {
 		ctx = ctx;
-		lut = Hashtbl.create 0;
+		lut = IntHashtbl.create 0;
 		added_fields = [];
 	} in
 	let c = ctx.c.curclass in

+ 10 - 10
src/filters/renameVars.ml

@@ -82,25 +82,25 @@ let init com =
 module Overlaps = struct
 	type t = {
 		mutable ov_vars : tvar list;
-		mutable ov_lut : (int,bool) Hashtbl.t;
+		mutable ov_lut : bool IntHashtbl.t;
 		mutable ov_name_cache : bool StringMap.t option;
 	}
 
 	let create () = {
 		ov_vars = [];
-		ov_lut = Hashtbl.create 0;
+		ov_lut = IntHashtbl.create 0;
 		ov_name_cache = None;
 	}
 
 	let copy ov = {
 		ov_vars = ov.ov_vars;
-		ov_lut = Hashtbl.copy ov.ov_lut;
+		ov_lut = IntHashtbl.copy ov.ov_lut;
 		ov_name_cache = ov.ov_name_cache;
 	}
 
 	let add v ov =
 		ov.ov_vars <- v :: ov.ov_vars;
-		Hashtbl.add ov.ov_lut v.v_id true;
+		IntHashtbl.add ov.ov_lut v.v_id true;
 		ov.ov_name_cache <- None
 
 	let get_cache ov = match ov.ov_name_cache with
@@ -118,11 +118,11 @@ module Overlaps = struct
 		List.iter f ov.ov_vars
 
 	let mem id ov =
-		Hashtbl.mem ov.ov_lut id
+		IntHashtbl.mem ov.ov_lut id
 
 	let reset ov =
 		ov.ov_vars <- [];
-		Hashtbl.clear ov.ov_lut;
+		IntHashtbl.clear ov.ov_lut;
 		ov.ov_name_cache <- None
 
 	let is_empty ov = match ov.ov_vars with
@@ -167,7 +167,7 @@ type rename_context = {
 	rc_scope : var_scope;
 	mutable rc_reserved : bool StringMap.t;
 	(** Scope a variable is declared in *)
-	rc_var_origins : (int,scope) Hashtbl.t;
+	rc_var_origins : scope IntHashtbl.t;
 }
 
 (**
@@ -216,7 +216,7 @@ let declare_var rc scope v =
 			end
 	in
 	scope.own_vars <- (v, overlaps) :: scope.own_vars;
-	Hashtbl.add rc.rc_var_origins v.v_id scope;
+	IntHashtbl.add rc.rc_var_origins v.v_id scope;
 	if scope.loop_count > 0 then
 		Overlaps.add v scope.loop_vars
 
@@ -255,7 +255,7 @@ let use_var rc scope v =
 	if not (will_be_reserved rc v) then
 		determine_overlaps rc scope v
 	else begin
-		let origin = Hashtbl.find rc.rc_var_origins v.v_id in
+		let origin = IntHashtbl.find rc.rc_var_origins v.v_id in
 		let rec loop scope =
 			if scope != origin then begin
 				if (rc.rc_no_shadowing || rc.rc_hoisting) then
@@ -391,7 +391,7 @@ let run cl_path ri e =
 		rc_no_catch_var_shadowing = ri.ri_no_catch_var_shadowing;
 		rc_switch_cases_no_blocks = ri.ri_switch_cases_no_blocks;
 		rc_reserved = ri.ri_reserved;
-		rc_var_origins = Hashtbl.create 0;
+		rc_var_origins = IntHashtbl.create 0;
 	} in
 	if ri.ri_reserve_current_top_level_symbol then begin
 		match cl_path with

+ 9 - 9
src/macro/eval/evalContext.ml

@@ -34,9 +34,9 @@ type scope = {
 	(* The local start offset of the current scope. *)
 	local_offset : int;
 	(* The locals declared in the current scope. Maps variable IDs to local slots. *)
-	locals : (int,int) Hashtbl.t;
+	locals : int IntHashtbl.t;
 	(* The name of local variables. Maps local slots to variable names. Only filled in debug mode. *)
-	local_infos : (int,var_info) Hashtbl.t;
+	local_infos : var_info IntHashtbl.t;
 	(* The IDs of local variables. Maps variable names to variable IDs. *)
 	local_ids : (string,int) Hashtbl.t;
 }
@@ -59,7 +59,7 @@ type env_info = {
 	(* The environment kind. *)
 	kind : env_kind;
 	(* The name of capture variables. Maps local slots to variable names. Only filled in debug mode. *)
-	capture_infos : (int,var_info) Hashtbl.t;
+	capture_infos : var_info IntHashtbl.t;
 	(* The number of local variables. *)
 	num_locals : int;
 	(* The number of capture variables. *)
@@ -114,7 +114,7 @@ and eval = {
 	(* The currently active breakpoint. Set to a dummy value initially. *)
 	mutable breakpoint : breakpoint;
 	(* Map of all types that are currently being caught. Updated by `emit_try`. *)
-	caught_types : (int,bool) Hashtbl.t;
+	caught_types : bool IntHashtbl.t;
 	(* The most recently caught exception. Used by `debug_loop` to avoid getting stuck. *)
 	mutable caught_exception : value;
 	(* The value which was last returned. *)
@@ -156,8 +156,8 @@ type function_breakpoint = {
 type builtins = {
 	mutable instance_builtins : (int * value) list IntMap.t;
 	mutable static_builtins : (int * value) list IntMap.t;
-	constructor_builtins : (int,value list -> value) Hashtbl.t;
-	empty_constructor_builtins : (int,unit -> value) Hashtbl.t;
+	constructor_builtins : (value list -> value) IntHashtbl.t;
+	empty_constructor_builtins : (unit -> value) IntHashtbl.t;
 }
 
 type debug_scope_info = {
@@ -168,7 +168,7 @@ type debug_scope_info = {
 type context_reference =
 	| StackFrame of env
 	| Scope of scope * env
-	| CaptureScope of (int,var_info) Hashtbl.t * env
+	| CaptureScope of var_info IntHashtbl.t * env
 	| DebugScope of debug_scope_info * env
 	| Value of value * env
 	| Toplevel
@@ -249,7 +249,7 @@ and debug_socket = {
 (* Per-context debug information *)
 and debug = {
 	(* The registered breakpoints *)
-	breakpoints : (int,(int,breakpoint) Hashtbl.t) Hashtbl.t;
+	breakpoints : breakpoint IntHashtbl.t IntHashtbl.t;
 	(* The registered function breakpoints *)
 	function_breakpoints : ((int * int),function_breakpoint) Hashtbl.t;
 	(* Whether or not debugging is supported. Has various effects on the amount of
@@ -520,7 +520,7 @@ let get_instance_constructor ctx path p =
 	with Not_found -> Error.raise_typing_error (Printf.sprintf "[%i] Instance constructor not found: %s" ctx.ctx_id (rev_hash path)) p
 
 let get_special_instance_constructor_raise ctx path =
-	Hashtbl.find (get_ctx()).builtins.constructor_builtins path
+	IntHashtbl.find (get_ctx()).builtins.constructor_builtins path
 
 let get_proto_field_index_raise proto name =
 	IntMap.find name proto.pnames

+ 4 - 3
src/macro/eval/evalDebug.ml

@@ -1,3 +1,4 @@
+open Globals
 open Type
 open EvalJitContext
 open EvalContext
@@ -7,7 +8,7 @@ open EvalDebugMisc
 
 let is_caught eval v =
 	try
-		Hashtbl.iter (fun path _ -> if is v path then raise Exit) eval.caught_types;
+		IntHashtbl.iter (fun path _ -> if is v path then raise Exit) eval.caught_types;
 		false
 	with Exit ->
 		true
@@ -72,8 +73,8 @@ let debug_loop jit conn e f =
 	let rec run_check_breakpoint env =
 		let eval = env.env_eval in
 		try
-			let h = Hashtbl.find ctx.debug.breakpoints env.env_info.pfile_unique in
-			let breakpoint = Hashtbl.find h env.env_debug.line in
+			let h = IntHashtbl.find ctx.debug.breakpoints env.env_info.pfile_unique in
+			let breakpoint = IntHashtbl.find h env.env_debug.line in
 			begin match breakpoint.bpstate with
 				| BPEnabled when column_matches breakpoint && condition_holds env breakpoint ->
 					breakpoint.bpstate <- BPHit;

+ 11 - 11
src/macro/eval/evalDebugMisc.ml

@@ -38,27 +38,27 @@ let make_function_breakpoint state =
 	}
 
 let iter_breakpoints ctx f =
-	Hashtbl.iter (fun _ breakpoints ->
-		Hashtbl.iter (fun _ breakpoint -> f breakpoint) breakpoints
+	IntHashtbl.iter (fun _ breakpoints ->
+		IntHashtbl.iter (fun _ breakpoint -> f breakpoint) breakpoints
 	) ctx.debug.breakpoints
 
 let add_breakpoint ctx file line column condition =
 	let hash = hash (Path.UniqueKey.to_string (ctx.file_keys#get (Common.find_file (ctx.curapi.get_com()) file))) in
 	let h = try
-		Hashtbl.find ctx.debug.breakpoints hash
+		IntHashtbl.find ctx.debug.breakpoints hash
 	with Not_found ->
-		let h = Hashtbl.create 0 in
-		Hashtbl.add ctx.debug.breakpoints hash h;
+		let h = IntHashtbl.create 0 in
+		IntHashtbl.add ctx.debug.breakpoints hash h;
 		h
 	in
 	let breakpoint = make_breakpoint hash line BPEnabled column condition in
-	Hashtbl.replace h line breakpoint;
+	IntHashtbl.replace h line breakpoint;
 	breakpoint
 
 let delete_breakpoint ctx file line =
 	let hash = hash (Path.UniqueKey.to_string (ctx.file_keys#get (Common.find_file (ctx.curapi.get_com()) file))) in
-	let h = Hashtbl.find ctx.debug.breakpoints hash in
-	Hashtbl.remove h line
+	let h = IntHashtbl.find ctx.debug.breakpoints hash in
+	IntHashtbl.remove h line
 
 let find_breakpoint ctx sid =
 	let found = ref None in
@@ -91,8 +91,8 @@ let get_var_slot_by_name env is_read scopes name =
 		| scope :: scopes ->
 			begin try
 				let id = Hashtbl.find scope.local_ids name in
-				let slot = Hashtbl.find scope.locals id in
-				let vi = Hashtbl.find scope.local_infos slot in
+				let slot = IntHashtbl.find scope.locals id in
+				let vi = IntHashtbl.find scope.local_infos slot in
 				if is_read && not (declared_before vi env.env_debug.debug_pos) then raise Not_found;
 				slot + scope.local_offset
 			with Not_found ->
@@ -106,7 +106,7 @@ let get_var_slot_by_name env is_read scopes name =
 let get_capture_slot_by_name capture_infos name =
 	let ret = ref None in
 	try
-		Hashtbl.iter (fun slot vi ->
+		IntHashtbl.iter (fun slot vi ->
 			if name = vi.vi_name then begin
 				ret := (Some slot);
 				raise Exit

+ 15 - 15
src/macro/eval/evalDebugSocket.ml

@@ -225,7 +225,7 @@ let output_scopes ctx env =
 		JObject fl
 	in
 	let scopes = List.fold_left (fun acc scope ->
-		if Hashtbl.length scope.local_infos <> 0 then
+		if IntHashtbl.length scope.local_infos <> 0 then
 			(mk_scope (ctx.debug.debug_context#add_scope scope env) "Locals" scope.pos) :: acc
 		else
 			acc
@@ -240,11 +240,11 @@ let output_scopes ctx env =
 		(mk_scope (ctx.debug.debug_context#add_debug_scope dbg env) "Eval" null_pos) :: scopes
 	end in
 	let scopes = List.rev scopes in
-	let scopes = if Hashtbl.length capture_infos = 0 then scopes else (mk_scope (ctx.debug.debug_context#add_capture_scope capture_infos env) "Captures" null_pos) :: scopes in
+	let scopes = if IntHashtbl.length capture_infos = 0 then scopes else (mk_scope (ctx.debug.debug_context#add_capture_scope capture_infos env) "Captures" null_pos) :: scopes in
 	JArray scopes
 
 let output_capture_vars infos env =
-	let vars = Hashtbl.fold (fun slot vi acc ->
+	let vars = IntHashtbl.fold (fun slot vi acc ->
 		let value = (env.env_captures.(slot)) in
 		(var_to_json vi.vi_name value (Some vi) env) :: acc
 	) infos [] in
@@ -259,7 +259,7 @@ let output_debug_scope dbg env =
 
 let output_scope_vars env scope =
 	let p = env.env_debug.debug_pos in
-	let vars = Hashtbl.fold (fun local_slot vi acc ->
+	let vars = IntHashtbl.fold (fun local_slot vi acc ->
 		if declared_before vi p then begin
 			let slot = local_slot + scope.local_offset in
 			let value = env.env_locals.(slot) in
@@ -312,7 +312,7 @@ let output_inner_vars v env =
 				n, v
 			) l
 		| VInstance {ikind = IStringMap h} ->
-			StringHashtbl.fold (fun s (_,v) acc ->
+			RuntimeStringHashtbl.fold (fun s (_,v) acc ->
 				(s,v) :: acc
 			) h []
 		| VInstance {ikind = IMutex mutex} ->
@@ -384,7 +384,7 @@ module ValueCompletion = struct
 		in
 		loop env.env_debug.scopes;
 		(* 2. Captures *)
-		Hashtbl.iter (fun slot vi ->
+		IntHashtbl.iter (fun slot vi ->
 			add (hash vi.vi_name) "variable"
 		) env.env_info.capture_infos;
 		(* 3. Instance *)
@@ -644,17 +644,17 @@ let handler =
 			let hash = hash (Path.UniqueKey.to_string (hctx.ctx.file_keys#get (Common.find_file (hctx.ctx.curapi.get_com()) file))) in
 			let h =
 				try
-					let h = Hashtbl.find hctx.ctx.debug.breakpoints hash in
-					Hashtbl.clear h;
+					let h = IntHashtbl.find hctx.ctx.debug.breakpoints hash in
+					IntHashtbl.clear h;
 					h
 				with Not_found ->
-					let h = Hashtbl.create (List.length bps) in
-					Hashtbl.add hctx.ctx.debug.breakpoints hash h;
+					let h = IntHashtbl.create (List.length bps) in
+					IntHashtbl.add hctx.ctx.debug.breakpoints hash h;
 					h
 			in
 			let bps = List.map (fun (line,column,condition) ->
 				let bp = make_breakpoint hash line BPEnabled column condition in
-				Hashtbl.add h line bp;
+				IntHashtbl.add h line bp;
 				JObject ["id",JInt bp.bpid]
 			) bps in
 			JArray bps
@@ -685,10 +685,10 @@ let handler =
 		"removeBreakpoint",(fun hctx ->
 			let id = hctx.jsonrpc#get_int_param "id" in
 			begin try
-				Hashtbl.iter (fun _ h ->
+				IntHashtbl.iter (fun _ h ->
 					let to_delete = ref [] in
-					Hashtbl.iter (fun k breakpoint -> if breakpoint.bpid = id then to_delete := k :: !to_delete) h;
-					List.iter (fun k -> Hashtbl.remove h k) !to_delete;
+					IntHashtbl.iter (fun k breakpoint -> if breakpoint.bpid = id then to_delete := k :: !to_delete) h;
+					List.iter (fun k -> IntHashtbl.remove h k) !to_delete;
 				) hctx.ctx.debug.breakpoints;
 			with Not_found ->
 				hctx.send_error (Printf.sprintf "Unknown breakpoint: %d" id)
@@ -726,7 +726,7 @@ let handler =
 			| Scope(scope,env) ->
 				let value = get_value env in
 				let id = Hashtbl.find scope.local_ids name in
-				let slot = Hashtbl.find scope.locals id in
+				let slot = IntHashtbl.find scope.locals id in
 				env.env_locals.(slot + scope.local_offset) <- value;
 				var_to_json "" value None env
 			| CaptureScope(infos,env) ->

+ 2 - 2
src/macro/eval/evalEmitter.ml

@@ -219,10 +219,10 @@ let emit_try exec catches env =
 	let ctx = get_ctx() in
 	let eval = env.env_eval in
 	if ctx.debug.support_debugger then begin
-		List.iter (fun (_,path,_) -> Hashtbl.add eval.caught_types path true) catches
+		List.iter (fun (_,path,_) -> IntHashtbl.add eval.caught_types path true) catches
 	end;
 	let restore () =
-		List.iter (fun (_,path,_) -> Hashtbl.remove eval.caught_types path) catches
+		List.iter (fun (_,path,_) -> IntHashtbl.remove eval.caught_types path) catches
 	in
 	let v = try
 		let v = handle_stack_overflow eval (fun() -> exec env) in

+ 2 - 2
src/macro/eval/evalEncode.ml

@@ -249,8 +249,8 @@ let encode_object_map_direct =
 	create_cached_instance key_haxe_ds_ObjectMap (fun (s : value ValueHashtbl.t) -> IObjectMap (Obj.magic s))
 
 let encode_string_map convert m =
-	let h = StringHashtbl.create () in
-	PMap.iter (fun key value -> StringHashtbl.add h (create_ascii key) (convert value)) m;
+	let h = RuntimeStringHashtbl.create () in
+	PMap.iter (fun key value -> RuntimeStringHashtbl.add h (create_ascii key) (convert value)) m;
 	encode_string_map_direct h
 
 let fake_proto path =

+ 3 - 3
src/macro/eval/evalJit.ml

@@ -229,13 +229,13 @@ and jit_expr jit return e =
 		let fl,exec = jit_tfunction jit_closure true e.epos tf in
 		let hasret = jit_closure.has_nonfinal_return in
 		let eci = get_env_creation jit_closure false tf.tf_expr.epos.pfile (EKLocalFunction jit.num_closures) in
-		let captures = Hashtbl.fold (fun vid (i,declared) acc -> (i,vid,declared) :: acc) jit_closure.captures [] in
+		let captures = IntHashtbl.fold (fun vid (i,declared) acc -> (i,vid,declared) :: acc) jit_closure.captures [] in
 		let captures = List.sort (fun (i1,_,_) (i2,_,_) -> Stdlib.compare i1 i2) captures in
 		(* Check if the out-of-scope var is in the outer scope because otherwise we have to promote outwards. *)
 		List.iter (fun var -> ignore(get_capture_slot jit var)) jit_closure.captures_outside_scope;
 		let captures = ExtList.List.filter_map (fun (i,vid,declared) ->
 			if declared then None
-			else Some (i,fst (try Hashtbl.find jit.captures vid with Not_found -> Error.raise_typing_error (Printf.sprintf "Could not find capture variable %i" vid) e.epos))
+			else Some (i,fst (try IntHashtbl.find jit.captures vid with Not_found -> Error.raise_typing_error (Printf.sprintf "Could not find capture variable %i" vid) e.epos))
 		) captures in
 		let mapping = Array.of_list captures in
 		emit_closure ctx mapping eci hasret exec fl
@@ -696,7 +696,7 @@ and jit_tfunction jit static pos tf =
 	fl,exec
 
 and get_env_creation jit static file info =
-	create_env_info static file (jit.ctx.file_keys#get file) info jit.capture_infos jit.max_num_locals (Hashtbl.length jit.captures)
+	create_env_info static file (jit.ctx.file_keys#get file) info jit.capture_infos jit.max_num_locals (IntHashtbl.length jit.captures)
 
 let jit_timer ctx f =
 	Timer.time ctx.timer_ctx [(if ctx.is_macro then "macro" else "interp");"jit"] f ()

+ 19 - 18
src/macro/eval/evalJitContext.ml

@@ -1,3 +1,4 @@
+open Globals
 open Type
 open EvalContext
 
@@ -17,7 +18,7 @@ type t = {
 	(* The scope stack. *)
 	mutable scopes : scope list;
 	(* The captured variables declared in this context. Maps variable IDs to capture slots. *)
-	mutable captures : (int,int * bool) Hashtbl.t;
+	mutable captures : (int * bool) IntHashtbl.t;
 	(* The current number of locals. *)
 	mutable num_locals : int;
 	(* The maximum number of locals. *)
@@ -27,7 +28,7 @@ type t = {
 	(* Whether or not this function has a return that's not at the end of control flow. *)
 	mutable has_nonfinal_return : bool;
 	(* The name of capture variables. Maps local slots to variable names. Only filled in debug mode. *)
-	mutable capture_infos : (int,var_info) Hashtbl.t;
+	mutable capture_infos : var_info IntHashtbl.t;
 	(* Variables which are accessed but not declared in this scope. *)
 	mutable captures_outside_scope : tvar list;
 }
@@ -43,25 +44,25 @@ let var_info_of_var var =
 let create ctx = {
 	ctx = ctx;
 	scopes = [];
-	captures = Hashtbl.create 0;
+	captures = IntHashtbl.create 0;
 	num_locals = 0;
 	max_num_locals = 0;
 	num_closures = 0;
 	has_nonfinal_return = false;
-	capture_infos = Hashtbl.create 0;
+	capture_infos = IntHashtbl.create 0;
 	captures_outside_scope = []
 }
 
 (* Returns the number of locals in [scope]. *)
 let num_locals scope =
-	Hashtbl.length scope.locals
+	IntHashtbl.length scope.locals
 
 (* Pushes a new scope onto context [jit]. *)
 let push_scope jit pos =
 	let scope = {
 		local_offset = jit.num_locals;
-		locals = Hashtbl.create 0;
-		local_infos = Hashtbl.create 0;
+		locals = IntHashtbl.create 0;
+		local_infos = IntHashtbl.create 0;
 		local_ids = Hashtbl.create 0;
 		pos = pos;
 	} in
@@ -82,10 +83,10 @@ let increase_num_locals jit =
 
 (* Adds capture variable [var] to context [jit]. *)
 let add_capture jit var declared =
-	let i = Hashtbl.length jit.captures in
-	Hashtbl.add jit.captures var.v_id (i,declared);
+	let i = IntHashtbl.length jit.captures in
+	IntHashtbl.add jit.captures var.v_id (i,declared);
 	if jit.ctx.debug.support_debugger then begin
-		Hashtbl.replace jit.capture_infos i (var_info_of_var var)
+		IntHashtbl.replace jit.capture_infos i (var_info_of_var var)
 	end;
 	i
 
@@ -93,13 +94,13 @@ let add_capture jit var declared =
 let add_local jit var = match jit.scopes with
 	| [] -> Globals.die "" __LOC__
 	| scope :: _ ->
-		let i = Hashtbl.length scope.locals in
-		Hashtbl.add scope.locals var.v_id i;
+		let i = IntHashtbl.length scope.locals in
+		IntHashtbl.add scope.locals var.v_id i;
 		increase_num_locals jit;
 		let slot = scope.local_offset + i in
 		if jit.ctx.debug.support_debugger then begin
 			Hashtbl.replace scope.local_ids var.v_name var.v_id;
-			Hashtbl.replace scope.local_infos i (var_info_of_var var)
+			IntHashtbl.replace scope.local_infos i (var_info_of_var var)
 		end;
 		slot
 
@@ -127,12 +128,12 @@ let declare_arg jit var =
 let declare_local_this jit = match jit.scopes with
 	| [] -> Globals.die "" __LOC__
 	| scope :: _ ->
-		let i = Hashtbl.length scope.locals in
-		Hashtbl.add scope.locals 0 i;
+		let i = IntHashtbl.length scope.locals in
+		IntHashtbl.add scope.locals 0 i;
 		increase_num_locals jit;
 		if jit.ctx.debug.support_debugger then begin
 			Hashtbl.replace scope.local_ids "this" 0;
-			Hashtbl.replace scope.local_infos 0 { vi_name = "this"; vi_pos = Globals.null_pos; vi_generated = false }
+			IntHashtbl.replace scope.local_infos 0 { vi_name = "this"; vi_pos = Globals.null_pos; vi_generated = false }
 		end;
 		Local i
 
@@ -142,7 +143,7 @@ let get_slot_raise jit vid =
 		| [] -> raise Not_found
 		| scope :: scopes ->
 			try
-				scope.local_offset + Hashtbl.find scope.locals vid
+				scope.local_offset + IntHashtbl.find scope.locals vid
 			with Not_found ->
 				loop scopes
 	in
@@ -154,7 +155,7 @@ let get_slot jit vid p =
 
 (* Gets the slot of captured variable id [vid] in context [jit]. *)
 let get_capture_slot jit var =
-	try fst (Hashtbl.find jit.captures var.v_id)
+	try fst (IntHashtbl.find jit.captures var.v_id)
 	with Not_found ->
 		jit.captures_outside_scope <- var :: jit.captures_outside_scope;
 		add_capture jit var false

+ 3 - 3
src/macro/eval/evalLuv.ml

@@ -1317,7 +1317,7 @@ let process_fields = [
 					get key_environment (fun v ->
 						match decode_instance v with
 						| { ikind = IStringMap m } ->
-							StringHashtbl.fold (fun k (_,v) acc -> (k, decode_native_string v) :: acc) m []
+							RuntimeStringHashtbl.fold (fun k (_,v) acc -> (k, decode_native_string v) :: acc) m []
 						| _ ->
 							unexpected_value v "haxe.ds.Map<String,String>"
 					)
@@ -2166,9 +2166,9 @@ let env_fields = [
 		let encode env =
 			let map =
 				List.fold_left (fun map (name,value) ->
-					StringHashtbl.add map (EvalString.create_unknown_vstring name) (vnative_string value);
+					RuntimeStringHashtbl.add map (EvalString.create_unknown_vstring name) (vnative_string value);
 					map
-				) (StringHashtbl.create()) env
+				) (RuntimeStringHashtbl.create()) env
 			in
 			encode_string_map_direct map
 		in

+ 8 - 8
src/macro/eval/evalMain.ml

@@ -42,8 +42,8 @@ let create com api is_macro =
 			let builtins = {
 				static_builtins = IntMap.empty;
 				instance_builtins = IntMap.empty;
-				constructor_builtins = Hashtbl.create 0;
-				empty_constructor_builtins = Hashtbl.create 0;
+				constructor_builtins = IntHashtbl.create 0;
+				empty_constructor_builtins = IntHashtbl.create 0;
 			} in
 			EvalStdLib.init_standard_library builtins;
 			GlobalState.stdlib := Some builtins;
@@ -77,7 +77,7 @@ let create com api is_macro =
 					None
 			in
 			let debug' = {
-				breakpoints = Hashtbl.create 0;
+				breakpoints = IntHashtbl.create 0;
 				function_breakpoints = Hashtbl.create 0;
 				support_debugger = support_debugger;
 				debug_socket = socket;
@@ -181,7 +181,7 @@ let call_path ctx path f vl api =
 			let vtype = get_static_prototype_as_value ctx (path_hash path) api.pos in
 			let vfield = field vtype (hash f) in
 			let p = api.pos in
-			let info = create_env_info true p.pfile (ctx.file_keys#get p.pfile) (EKMacro (path_hash path, hash f)) (Hashtbl.create 0) 0 0 in
+			let info = create_env_info true p.pfile (ctx.file_keys#get p.pfile) (EKMacro (path_hash path, hash f)) (IntHashtbl.create 0) 0 0 in
 			let env = push_environment ctx info in
 			env.env_leave_pmin <- p.pmin;
 			env.env_leave_pmax <- p.pmax;
@@ -278,7 +278,7 @@ let value_signature v =
 		| VInstance {ikind = IStringMap map} ->
 			cache v (fun() ->
 				addc 'b';
-				StringHashtbl.iter (fun s (_,value) ->
+				RuntimeStringHashtbl.iter (fun s (_,value) ->
 					adds s;
 					loop value
 				) map;
@@ -287,7 +287,7 @@ let value_signature v =
 		| VInstance {ikind = IIntMap map} ->
 			cache v (fun () ->
 				addc 'q';
-				IntHashtbl.iter (fun i value ->
+				RuntimeIntHashtbl.iter (fun i value ->
 					addc ':';
 					add (string_of_int i);
 					loop value
@@ -491,13 +491,13 @@ let rec value_to_expr v p =
 				(ECall (epath, args), p)
 		end
 	| VInstance {ikind = IIntMap m} ->
-		let el = IntHashtbl.fold (fun k v acc ->
+		let el = RuntimeIntHashtbl.fold (fun k v acc ->
 			let e_key = (EConst (Int (string_of_int k, None)),p) in
 			(make_map_entry e_key v) :: acc
 		) m [] in
 		(EArrayDecl el,p)
 	| VInstance {ikind = IStringMap m} ->
-		let el = StringHashtbl.fold (fun k (_,v) acc ->
+		let el = RuntimeStringHashtbl.fold (fun k (_,v) acc ->
 			let e_key = (EConst (String(k,SDoubleQuotes)),p) in
 			(make_map_entry e_key v) :: acc
 		) m [] in

+ 3 - 3
src/macro/eval/evalPrototype.ml

@@ -32,7 +32,7 @@ open EvalMisc
 let eval_expr ctx kind e =
 	catch_exceptions ctx (fun () ->
 		let jit,f = jit_expr ctx e in
-		let num_captures = Hashtbl.length jit.captures in
+		let num_captures = IntHashtbl.length jit.captures in
 		let info = create_env_info true e.epos.pfile (ctx.file_keys#get e.epos.pfile) kind jit.capture_infos jit.max_num_locals num_captures in
 		let env = push_environment ctx info in
 		Std.finally (fun _ -> pop_environment ctx env) f env
@@ -319,8 +319,8 @@ let add_types ctx types ready =
 			ctx.type_cache <- IntMap.add key mt ctx.type_cache;
 			if ctx.debug.support_debugger then begin
 				let file_key = hash (Path.UniqueKey.lazy_path inf.mt_module.m_extra.m_file) in
-				if not (Hashtbl.mem ctx.debug.breakpoints file_key) then begin
-					Hashtbl.add ctx.debug.breakpoints file_key (Hashtbl.create 0)
+				if not (IntHashtbl.mem ctx.debug.breakpoints file_key) then begin
+					IntHashtbl.add ctx.debug.breakpoints file_key (IntHashtbl.create 0)
 				end
 			end;
 			true

+ 35 - 35
src/macro/eval/evalStdLib.ml

@@ -1503,26 +1503,26 @@ module StdIntMap = struct
 		| v -> unexpected_value v "int map"
 
 	let copy = vifun0 (fun vthis ->
-		let copied = IntHashtbl.copy (this vthis) in
+		let copied = RuntimeIntHashtbl.copy (this vthis) in
 		encode_int_map_direct copied
 	)
 
 	let exists = vifun1 (fun vthis vkey ->
-		vbool (IntHashtbl.mem (this vthis) (decode_int vkey))
+		vbool (RuntimeIntHashtbl.mem (this vthis) (decode_int vkey))
 	)
 
 	let get = vifun1 (fun vthis vkey ->
-		try IntHashtbl.find (this vthis) (decode_int vkey)
+		try RuntimeIntHashtbl.find (this vthis) (decode_int vkey)
 		with Not_found -> vnull
 	)
 
 	let iterator = vifun0 (fun vthis ->
-		let keys = IntHashtbl.fold (fun _ v acc -> v :: acc) (this vthis) [] in
+		let keys = RuntimeIntHashtbl.fold (fun _ v acc -> v :: acc) (this vthis) [] in
 		encode_list_iterator keys
 	)
 
 	let keys = vifun0 (fun vthis ->
-		let keys = IntHashtbl.fold (fun k _ acc -> vint k :: acc) (this vthis) [] in
+		let keys = RuntimeIntHashtbl.fold (fun k _ acc -> vint k :: acc) (this vthis) [] in
 		encode_list_iterator keys
 	)
 
@@ -1531,19 +1531,19 @@ module StdIntMap = struct
 	let remove = vifun1 (fun vthis vkey ->
 		let this = this vthis in
 		let key = decode_int vkey in
-		let b = IntHashtbl.mem this key in
-		IntHashtbl.remove this key;
+		let b = RuntimeIntHashtbl.mem this key in
+		RuntimeIntHashtbl.remove this key;
 		vbool b
 	)
 
 	let set = vifun2 (fun vthis vkey vvalue ->
-		IntHashtbl.add (this vthis) (decode_int vkey) vvalue;
+		RuntimeIntHashtbl.add (this vthis) (decode_int vkey) vvalue;
 		vnull
 	)
 
 	let toString = vifun0 (fun vthis ->
 		let this = this vthis in
-		let l = IntHashtbl.fold (fun key vvalue acc ->
+		let l = RuntimeIntHashtbl.fold (fun key vvalue acc ->
 			(join empty_string [create_ascii (string_of_int key); create_ascii " => "; s_value 0 vvalue]) :: acc) this [] in
 		let s = join rcomma l in
 		let s = join empty_string [rbkopen;s;rbkclose] in
@@ -1551,7 +1551,7 @@ module StdIntMap = struct
 	)
 
 	let clear = vifun0 (fun vthis ->
-		IntHashtbl.clear (this vthis);
+		RuntimeIntHashtbl.clear (this vthis);
 		vnull
 	)
 end
@@ -1562,26 +1562,26 @@ module StdStringMap = struct
 		| v -> unexpected_value v "string map"
 
 	let copy = vifun0 (fun vthis ->
-		let copied = StringHashtbl.copy (this vthis) in
+		let copied = RuntimeStringHashtbl.copy (this vthis) in
 		encode_string_map_direct copied
 	)
 
 	let exists = vifun1 (fun vthis vkey ->
-		vbool (StringHashtbl.mem (this vthis) (decode_vstring vkey))
+		vbool (RuntimeStringHashtbl.mem (this vthis) (decode_vstring vkey))
 	)
 
 	let get = vifun1 (fun vthis vkey ->
-		try snd (StringHashtbl.find (this vthis) (decode_vstring vkey))
+		try snd (RuntimeStringHashtbl.find (this vthis) (decode_vstring vkey))
 		with Not_found -> vnull
 	)
 
 	let iterator = vifun0 (fun vthis ->
-		let keys = StringHashtbl.fold (fun _ (_,v) acc -> v :: acc) (this vthis) [] in
+		let keys = RuntimeStringHashtbl.fold (fun _ (_,v) acc -> v :: acc) (this vthis) [] in
 		encode_list_iterator keys
 	)
 
 	let keys = vifun0 (fun vthis ->
-		let keys = StringHashtbl.fold (fun _ (k,_) acc -> vstring k :: acc) (this vthis) [] in
+		let keys = RuntimeStringHashtbl.fold (fun _ (k,_) acc -> vstring k :: acc) (this vthis) [] in
 		encode_list_iterator keys
 	)
 
@@ -1590,19 +1590,19 @@ module StdStringMap = struct
 	let remove = vifun1 (fun vthis vkey ->
 		let this = this vthis in
 		let key = decode_vstring vkey in
-		let b = StringHashtbl.mem this key in
-		StringHashtbl.remove this key;
+		let b = RuntimeStringHashtbl.mem this key in
+		RuntimeStringHashtbl.remove this key;
 		vbool b
 	)
 
 	let set = vifun2 (fun vthis vkey vvalue ->
-		StringHashtbl.add (this vthis) (decode_vstring vkey) vvalue;
+		RuntimeStringHashtbl.add (this vthis) (decode_vstring vkey) vvalue;
 		vnull
 	)
 
 	let toString = vifun0 (fun vthis ->
 		let this = this vthis in
-		let l = StringHashtbl.fold (fun _ (key,vvalue) acc ->
+		let l = RuntimeStringHashtbl.fold (fun _ (key,vvalue) acc ->
 			(join empty_string [key; create_ascii " => "; s_value 0 vvalue]) :: acc) this [] in
 		let s = join rcomma l in
 		let s = join empty_string [rbkopen;s;rbkclose] in
@@ -1610,7 +1610,7 @@ module StdStringMap = struct
 	)
 
 	let clear = vifun0 (fun vthis ->
-		StringHashtbl.clear (this vthis);
+		RuntimeStringHashtbl.clear (this vthis);
 		vnull
 	)
 end
@@ -2585,10 +2585,10 @@ module StdSys = struct
 
 	let environment = vfun0 (fun () ->
 		let env = catch_unix_error Unix.environment() in
-		let h = StringHashtbl.create () in
+		let h = RuntimeStringHashtbl.create () in
 		Array.iter(fun s ->
 			let k, v = ExtString.String.split s "=" in
-			StringHashtbl.add h (create_ascii k) (create_unknown v)
+			RuntimeStringHashtbl.add h (create_ascii k) (create_unknown v)
 		) env;
 		encode_string_map_direct h
 	)
@@ -2826,7 +2826,7 @@ module StdType = struct
 		match v with
 		| VPrototype {pkind = PClass _; ppath = path} ->
 			begin try
-				(Hashtbl.find (get_ctx()).builtins.empty_constructor_builtins path) ()
+				(IntHashtbl.find (get_ctx()).builtins.empty_constructor_builtins path) ()
 			with Not_found ->
 				encode_instance path
 			end
@@ -3226,7 +3226,7 @@ let init_maps builtins =
 	]
 
 let init_constructors builtins =
-	let add = Hashtbl.add builtins.constructor_builtins in
+	let add = IntHashtbl.add builtins.constructor_builtins in
 	add key_Array (fun _ -> encode_array_instance (EvalArray.create [||]));
 	add key_eval_Vector
 		(fun vl ->
@@ -3263,8 +3263,8 @@ let init_constructors builtins =
 			| [size] -> encode_instance key_haxe_Utf8 ~kind:(IUtf8 (UTF8.Buf.create (default_int size 0)))
 			| _ -> die "" __LOC__
 		);
-	add key_haxe_ds_StringMap (fun _ -> encode_string_map_direct (StringHashtbl.create ()));
-	add key_haxe_ds_IntMap (fun _ -> encode_int_map_direct (IntHashtbl.create ()));
+	add key_haxe_ds_StringMap (fun _ -> encode_string_map_direct (RuntimeStringHashtbl.create ()));
+	add key_haxe_ds_IntMap (fun _ -> encode_int_map_direct (RuntimeIntHashtbl.create ()));
 	add key_haxe_ds_ObjectMap (fun _ -> encode_object_map_direct (Obj.magic (ValueHashtbl.create 0)));
 	add key_haxe_io_BytesBuffer (fun _ -> encode_instance key_haxe_io_BytesBuffer ~kind:(IOutput (Buffer.create 0)));
 	add key_haxe_io_Bytes
@@ -3349,15 +3349,15 @@ let init_constructors builtins =
 
 let init_empty_constructors builtins =
 	let h = builtins.empty_constructor_builtins in
-	Hashtbl.add h key_Array (fun () -> encode_array_instance (EvalArray.create [||]));
-	Hashtbl.add h key_eval_Vector (fun () -> encode_vector_instance (Array.make 0 vnull));
-	Hashtbl.add h key_Date (fun () -> encode_instance key_Date ~kind:(IDate 0.));
-	Hashtbl.add h key_EReg (fun () -> encode_instance key_EReg ~kind:(IRegex {r = Pcre2.regexp ""; r_rex_string = create_ascii "~//"; r_global = false; r_string = ""; r_groups = [||]}));
-	Hashtbl.add h key_String (fun () -> v_empty_string);
-	Hashtbl.add h key_haxe_ds_StringMap (fun () -> encode_instance key_haxe_ds_StringMap ~kind:(IStringMap (StringHashtbl.create ())));
-	Hashtbl.add h key_haxe_ds_IntMap (fun () -> encode_instance key_haxe_ds_IntMap ~kind:(IIntMap (IntHashtbl.create ())));
-	Hashtbl.add h key_haxe_ds_ObjectMap (fun () -> encode_instance key_haxe_ds_ObjectMap ~kind:(IObjectMap (Obj.magic (ValueHashtbl.create 0))));
-	Hashtbl.add h key_haxe_io_BytesBuffer (fun () -> encode_instance key_haxe_io_BytesBuffer ~kind:(IOutput (Buffer.create 0)))
+	IntHashtbl.add h key_Array (fun () -> encode_array_instance (EvalArray.create [||]));
+	IntHashtbl.add h key_eval_Vector (fun () -> encode_vector_instance (Array.make 0 vnull));
+	IntHashtbl.add h key_Date (fun () -> encode_instance key_Date ~kind:(IDate 0.));
+	IntHashtbl.add h key_EReg (fun () -> encode_instance key_EReg ~kind:(IRegex {r = Pcre2.regexp ""; r_rex_string = create_ascii "~//"; r_global = false; r_string = ""; r_groups = [||]}));
+	IntHashtbl.add h key_String (fun () -> v_empty_string);
+	IntHashtbl.add h key_haxe_ds_StringMap (fun () -> encode_instance key_haxe_ds_StringMap ~kind:(IStringMap (RuntimeStringHashtbl.create ())));
+	IntHashtbl.add h key_haxe_ds_IntMap (fun () -> encode_instance key_haxe_ds_IntMap ~kind:(IIntMap (RuntimeIntHashtbl.create ())));
+	IntHashtbl.add h key_haxe_ds_ObjectMap (fun () -> encode_instance key_haxe_ds_ObjectMap ~kind:(IObjectMap (Obj.magic (ValueHashtbl.create 0))));
+	IntHashtbl.add h key_haxe_io_BytesBuffer (fun () -> encode_instance key_haxe_io_BytesBuffer ~kind:(IOutput (Buffer.create 0)))
 
 let init_standard_library builtins =
 	init_constructors builtins;

+ 1 - 1
src/macro/eval/evalThread.ml

@@ -72,7 +72,7 @@ let create_eval thread = {
 	debug_channel = Event.new_channel ();
 	debug_state = DbgRunning;
 	breakpoint = make_breakpoint 0 0 BPDisabled BPAny None;
-	caught_types = Hashtbl.create 0;
+	caught_types = IntHashtbl.create 0;
 	last_return = None;
 	caught_exception = vnull;
 }

+ 16 - 16
src/macro/eval/evalValue.ml

@@ -43,7 +43,7 @@ type vstring_buffer = {
 let vstring_equal s1 s2 =
 	s1 == s2 || s1.sstring = s2.sstring
 
-module StringHashtbl = struct
+module RuntimeStringHashtbl = struct
 	type 'value t = (vstring * 'value) StringMap.t ref
 
 	let add this key v = this := StringMap.add key.sstring (key,v) !this
@@ -58,19 +58,19 @@ module StringHashtbl = struct
 	let clear this = this := StringMap.empty
 end
 
-module IntHashtbl = struct
-	type 'value t = (int, 'value) Hashtbl.t
-
-	let add this key v = Hashtbl.replace this key v
-	let copy this = Hashtbl.copy this
-	let create () = Hashtbl.create 0
-	let find this key = Hashtbl.find this key
-	let fold f this acc = Hashtbl.fold f this acc
-	let is_empty this = Hashtbl.length this = 0
-	let iter f this = Hashtbl.iter f this
-	let mem this key = Hashtbl.mem this key
-	let remove this key = Hashtbl.remove this key
-	let clear this = Hashtbl.clear this
+module RuntimeIntHashtbl = struct
+	type 'value t = 'value IntHashtbl.t
+
+	let add this key v = IntHashtbl.replace this key v
+	let copy this = IntHashtbl.copy this
+	let create () = IntHashtbl.create 0
+	let find this key = IntHashtbl.find this key
+	let fold f this acc = IntHashtbl.fold f this acc
+	let is_empty this = IntHashtbl.length this = 0
+	let iter f this = IntHashtbl.iter f this
+	let mem this key = IntHashtbl.mem this key
+	let remove this key = IntHashtbl.remove this key
+	let clear this = IntHashtbl.clear this
 end
 
 type vregex = {
@@ -186,8 +186,8 @@ and vinstance_kind =
 	| IBytes of bytes
 	| IRegex of vregex
 	| IDate of float
-	| IStringMap of value StringHashtbl.t
-	| IIntMap of value IntHashtbl.t
+	| IStringMap of value RuntimeStringHashtbl.t
+	| IIntMap of value RuntimeIntHashtbl.t
 	| IObjectMap of (value,value) Hashtbl.t
 	| IOutput of Buffer.t (* BytesBuffer *)
 	| IBuffer of vstring_buffer(* StringBuf *)

+ 9 - 9
src/optimization/analyzer.ml

@@ -376,7 +376,7 @@ module ConstPropagationImpl = struct
 		| EnumValue of int * t list
 		| ModuleType of module_type * Type.t
 
-	type opt_ctx = (int,t) Hashtbl.t
+	type opt_ctx = t IntHashtbl.t
 
 	let rec to_string =
 		let st = s_type (print_context()) in
@@ -391,8 +391,8 @@ module ConstPropagationImpl = struct
 	let conditional = true
 	let flag = FlagExecutable
 
-	let get_cell ctx i = try Hashtbl.find ctx i with Not_found -> Top
-	let set_cell ctx i ct = Hashtbl.replace ctx i ct
+	let get_cell ctx i = try IntHashtbl.find ctx i with Not_found -> Top
+	let set_cell ctx i ct = IntHashtbl.replace ctx i ct
 
 	let top = Top
 	let bottom = Bottom
@@ -504,7 +504,7 @@ module ConstPropagationImpl = struct
 			Bottom
 
 	let init ctx =
-		Hashtbl.create 0
+		IntHashtbl.create 0
 
 	let commit actx ctx =
 		let inline e i = match get_cell ctx i with
@@ -565,7 +565,7 @@ module CopyPropagationImpl = struct
 		| Local of tvar
 		| This of Type.t
 
-	type opt_ctx = (int,t) Hashtbl.t
+	type opt_ctx = t IntHashtbl.t
 
 	let to_string = function
 		| Top -> "Top"
@@ -576,8 +576,8 @@ module CopyPropagationImpl = struct
 	let conditional = false
 	let flag = FlagCopyPropagation
 
-	let get_cell ctx i = try Hashtbl.find ctx i with Not_found -> Top
-	let set_cell ctx i ct = Hashtbl.replace ctx i ct
+	let get_cell ctx i = try IntHashtbl.find ctx i with Not_found -> Top
+	let set_cell ctx i ct = IntHashtbl.replace ctx i ct
 
 	let top = Top
 	let bottom = Bottom
@@ -603,7 +603,7 @@ module CopyPropagationImpl = struct
 		loop e
 
 	let init actx =
-		Hashtbl.create 0
+		IntHashtbl.create 0
 
 	let commit actx ctx =
 		let rec commit bb e = match e.eexpr with
@@ -611,7 +611,7 @@ module CopyPropagationImpl = struct
 				begin try
 					let lat = get_cell ctx v.v_id in
 					let leave () =
-						Hashtbl.remove ctx v.v_id;
+						IntHashtbl.remove ctx v.v_id;
 						raise Not_found
 					in
 					begin match lat with