Browse Source

[typer] pull some random changes from hxb branch

Simon Krajewski 1 year ago
parent
commit
03db008d5e

+ 2 - 2
src/context/common.ml

@@ -1115,7 +1115,7 @@ let cache_directory ctx class_path dir f_dir =
 	in
 	Option.may (Array.iter prepare_file) dir_listing
 
-let find_file ctx f =
+let find_file ctx ?(class_path=ctx.class_path) f =
 	try
 		match ctx.file_lookup_cache#find f with
 		| None -> raise Exit
@@ -1150,7 +1150,7 @@ let find_file ctx f =
 						loop (had_empty || p = "") l
 				end
 		in
-		let r = try Some (loop false ctx.class_path) with Not_found -> None in
+		let r = try Some (loop false class_path) with Not_found -> None in
 		ctx.file_lookup_cache#add f r;
 		match r with
 		| None -> raise Not_found

+ 8 - 2
src/core/globals.ml

@@ -171,8 +171,14 @@ let die ?p msg ml_loc =
 	in
 	let ver = s_version_full
 	and os_type = if Sys.unix then "unix" else "windows" in
-	Printf.eprintf "%s\nHaxe: %s; OS type: %s;\n%s\n%s" msg ver os_type ml_loc backtrace;
-	assert false
+	let s = Printf.sprintf "%s\nHaxe: %s; OS type: %s;\n%s\n%s" msg ver os_type ml_loc backtrace in
+	failwith s
+
+let dump_callstack () =
+	print_endline (Printexc.raw_backtrace_to_string (Printexc.get_callstack 200))
+
+let dump_backtrace () =
+	print_endline (Printexc.raw_backtrace_to_string (Printexc.get_raw_backtrace ()))
 
 module MessageSeverity = struct
 	type t =

+ 17 - 0
src/core/tFunctions.ml

@@ -198,6 +198,15 @@ let mk_field name ?(public = true) ?(static = false) t p name_pos = {
 	);
 }
 
+let find_field c name kind =
+	match kind with
+	| CfrConstructor ->
+		begin match c.cl_constructor with Some cf -> cf | None -> raise Not_found end
+	| CfrStatic ->
+		PMap.find name c.cl_statics
+	| CfrMember ->
+		PMap.find name c.cl_fields
+
 let null_module = {
 	m_id = alloc_mid();
 	m_path = [] , "";
@@ -598,6 +607,14 @@ let rec follow_without_type t =
 		follow_without_type t
 	| _ -> t
 
+let rec follow_lazy_and_mono t = match t with
+	| TMono {tm_type = Some t} ->
+		follow_lazy_and_mono t
+	| TLazy f ->
+		follow_lazy_and_mono (lazy_type f)
+	| _ ->
+		t
+
 let rec ambiguate_funs t =
 	match follow t with
 	| TFun _ -> TFun ([], t_dynamic)

+ 4 - 3
src/core/tPrinting.ml

@@ -139,7 +139,7 @@ let s_type_param s_type ttp =
 	| Some t ->
 		Printf.sprintf "%s = %s" s (s_type t)
 	end
-		
+
 let s_access is_read = function
 	| AccNormal -> "default"
 	| AccNo -> "null"
@@ -460,7 +460,7 @@ module Printer = struct
 		| TPHEnumConstructor -> "TPHEnumConstructor"
 		| TPHAnonField -> "TPHAnonField"
 		| TPHLocal -> "TPHLocal"
-		
+
 	let s_type_param tabs ttp =
 		s_record_fields tabs [
 			"name",ttp.ttp_name;
@@ -477,7 +477,7 @@ module Printer = struct
 	let s_tclass_field_flags flags =
 		s_flags flags flag_tclass_field_names
 
-	let s_tclass_field tabs cf =
+	let rec s_tclass_field tabs cf =
 		s_record_fields tabs [
 			"cf_name",cf.cf_name;
 			"cf_doc",s_doc cf.cf_doc;
@@ -489,6 +489,7 @@ module Printer = struct
 			"cf_params",s_type_params (tabs ^ "\t") cf.cf_params;
 			"cf_expr",s_opt (s_expr_ast true "\t\t" s_type) cf.cf_expr;
 			"cf_flags",s_tclass_field_flags cf.cf_flags;
+			"cf_overloads",s_list "\n" (s_tclass_field (tabs ^ "\t")) cf.cf_overloads
 		]
 
 	let s_tclass tabs c =

+ 0 - 9
src/optimization/dce.ml

@@ -50,15 +50,6 @@ let push_class dce c =
 		dce.curclass <- old
 	)
 
-let find_field c name kind =
-	match kind with
-	| CfrConstructor ->
-		begin match c.cl_constructor with Some cf -> cf | None -> raise Not_found end
-	| CfrStatic ->
-		PMap.find name c.cl_statics
-	| CfrMember ->
-		PMap.find name c.cl_fields
-
 let resolve_class_field_ref ctx cfr =
 	let ctx = if cfr.cfr_is_macro && not ctx.is_macro_context then Option.get (ctx.get_macros()) else ctx in
 	let m = ctx.module_lut#find_by_type cfr.cfr_path in

+ 1 - 1
src/typing/typeloadModule.ml

@@ -573,7 +573,7 @@ module TypeLevel = struct
 		| TMono r ->
 			(match r.tm_type with
 			| None -> Monomorph.bind r tt;
-			| Some _ -> die "" __LOC__);
+			| Some t' -> die (Printf.sprintf "typedef %s is already initialized to %s, but new init to %s was attempted" (s_type_path t.t_path) (s_type_kind t') (s_type_kind tt)) __LOC__);
 		| _ -> die "" __LOC__);
 		TypeloadFields.build_module_def ctx (TTypeDecl t) t.t_meta (fun _ -> []) (fun _ -> ());
 		if ctx.com.platform = Cs && t.t_meta <> [] then