瀏覽代碼

[hxb] some fixes for hl / anon mix up

Rudy Ges 1 年之前
父節點
當前提交
abf768f26c

+ 14 - 3
src/compiler/hxb/hxbReader.ml

@@ -651,7 +651,9 @@ class hxb_reader
 			TEnum(self#read_enum_ref,[])
 		| 12 ->
 			begin match self#read_u8 with
-				(* TODO wrap those two in TType? *)
+				(* TODO does it make more sense to wrap in tdef like in source? *)
+				(* | 0 -> TType({null_typedef with t_type = (mk_anon (ref Closed))},[]) *)
+				(* | 1 -> TType({null_typedef with t_type = (TAnon self#read_anon_ref)},[]) *)
 				| 0 -> mk_anon (ref Closed)
 				| 1 -> TAnon self#read_anon_ref
 				| _ -> TType(self#read_typedef_ref,[])
@@ -678,10 +680,19 @@ class hxb_reader
 					let tl = self#read_types in
 					let td = { null_typedef with t_type = an } in
 					TType(td,tl)
+				(* TODO: does this help with anything? *)
+				(* | 2 -> *)
+				(* 	let t = self#read_type_instance in *)
+				(* 	let tl = self#read_types in *)
+				(* 	let tmono = !monomorph_create_ref () in (1* TODO identity *1) *)
+				(* 	tmono.tm_type <- Some t; *)
+				(* 	let td = { null_typedef with t_type = TMono tmono } in *)
+				(* 	TType(td,tl) *)
 				| _ ->
-					let t = self#read_typedef_ref in
+					let t = self#read_type_instance in
 					let tl = self#read_types in
-					TType(t,tl)
+					let td = { null_typedef with t_type = t } in
+					TType(td,tl)
 			end
 		| 17 ->
 			let a = self#read_abstract_ref in

+ 3 - 1
src/compiler/hxb/hxbRestore.ml

@@ -69,7 +69,9 @@ class hxb_restore
 				m_added = com.compilation_step;
 				m_checked = 0;
 				m_processed = 1;
-				m_time = (Common.file_time file)
+				m_features = Hashtbl.create 0; (* ? *)
+				m_if_feature = [];
+				m_time = (Common.file_time file) (* TODO check that... *)
 			}
 		}
 

+ 9 - 3
src/compiler/hxb/hxbWriter.ml

@@ -397,7 +397,7 @@ class ['a] hxb_writer
 			(* DynArray.iter (fun ttp -> debug_msg (Printf.sprintf "FTP %s %s" ttp.ttp_name (s_type_kind ttp.ttp_type)) field_type_parameters#items); *)
 			(* DynArray.iter (fun ttp -> debug_msg (Printf.sprintf "TTP %s %s" ttp.ttp_name (s_type_kind ttp.ttp_type)) type_type_parameters#items); *)
 			(* print_stacktrace (); *)
-			chunk#write_byte 40
+			chunk#write_byte 0 (* TMono None *)
 		end
 
 	method write_type_instance ?(debug:bool = false) t =
@@ -439,6 +439,7 @@ class ['a] hxb_writer
 				| TAnon an ->
 					chunk#write_byte 1;
 					self#write_anon_ref an td.t_params
+				(* TODO: do something about TMono? *)
 				| _ ->
 					chunk#write_byte 2;
 					self#write_typedef_ref td;
@@ -464,9 +465,14 @@ class ['a] hxb_writer
 					chunk#write_byte 1;
 					self#write_anon_ref an td.t_params;
 					self#write_types tl
-				| _ ->
+				(* TODO: does this help with anything? *)
+				| TMono _ ->
 					chunk#write_byte 2;
-					self#write_typedef_ref td;
+					self#write_type_instance ~debug (apply_typedef td tl);
+					self#write_types tl
+				| _ ->
+					chunk#write_byte 3;
+					self#write_type_instance ~debug (apply_typedef td tl);
 					self#write_types tl
 			end;
 		| TAbstract(a,tl) ->

+ 0 - 6
src/context/commonCache.ml

@@ -91,12 +91,6 @@ let rec clear_cache cs com =
 	let cc = get_cache com in
 	cc#clear_cache;
 
-	com.module_lut#clear;
-	com.stored_typed_exprs#clear;
-	com.module_nonexistent_lut#clear;
-	(* Hashtbl.clear com.features; *)
-	(* com.type_to_module#clear; *)
-
 	match com.get_macros() with
 	| None -> ()
 	| Some com -> clear_cache cs com

+ 2 - 1
src/core/tUnification.ml

@@ -568,7 +568,8 @@ let rec type_eq uctx a b =
 			PMap.iter (fun n f1 ->
 				try
 					let f2 = PMap.find n a2.a_fields in
-					if f1.cf_kind <> f2.cf_kind && (param = EqStrict || param = EqCoreType || not (unify_kind f1.cf_kind f2.cf_kind)) then error [invalid_kind n f1.cf_kind f2.cf_kind];
+					(* if f1.cf_kind <> f2.cf_kind && (param = EqStrict || param = EqCoreType || not (unify_kind f1.cf_kind f2.cf_kind)) then error [invalid_kind n f1.cf_kind f2.cf_kind]; *)
+					if f1.cf_kind <> f2.cf_kind && (param = EqStrict || param = EqCoreType || param = EqDoNotFollowNull || not (unify_kind f1.cf_kind f2.cf_kind)) then error [invalid_kind n f1.cf_kind f2.cf_kind];
 					let a = f1.cf_type and b = f2.cf_type in
 					(try type_eq uctx a b with Unify_error l -> error (invalid_field n :: l));
 					if (has_class_field_flag f1 CfPublic) != (has_class_field_flag f2 CfPublic) then error [invalid_visibility n];

+ 18 - 4
src/typing/tanon_identification.ml

@@ -59,7 +59,7 @@ object(self)
 		DynArray.add (DynArray.get pfm_by_arity pfm.pfm_arity) pfm;
 		Hashtbl.replace pfms path pfm
 
-	method unify (tc : Type.t) (pfm : 'a path_field_mapping) =
+	method unify ?(unify_kind = TUnification.unify_kind) ?(strict:bool = false) (tc : Type.t) (pfm : 'a path_field_mapping) =
 		let check () =
 			let pair_up fields =
 				PMap.fold (fun cf acc ->
@@ -85,7 +85,16 @@ object(self)
 					List.iter (fun (cf,cf') ->
 						if not (unify_kind cf'.cf_kind cf.cf_kind) then raise (Unify_error [Unify_custom "kind mismatch"]);
 						fields := PMap.remove cf.cf_name !fields;
-						Type.type_eq EqDoNotFollowNull cf'.cf_type (map (monomorphs cf.cf_params cf.cf_type))
+						(* if strict && cf'.cf_type <> cf.cf_type then raise (Unify_error [Unify_custom "type strict equality failed"]); *)
+						let eq_kind = if strict then {
+							allow_transitive_cast = false;
+							allow_abstract_cast = false;
+							allow_dynamic_to_cast = false;
+							(* equality_kind = EqStrict; *)
+							equality_kind = EqDoNotFollowNull;
+							equality_underlying = true; (* ?? *)
+						} else {default_unification_context with equality_kind = EqDoNotFollowNull} in
+						type_eq_custom eq_kind cf'.cf_type (map (monomorphs cf.cf_params cf.cf_type))
 					) pairs;
 					if not (PMap.is_empty !fields) then raise (Unify_error [Unify_custom "not enough fields"]);
 					monos
@@ -110,12 +119,17 @@ object(self)
 			raise Not_found;
 		let d = DynArray.get pfm_by_arity arity in
 		let l = DynArray.length d in
+		let unify_kind cfk1 cfk2 = cfk1 = cfk2 || match cfk1, cfk2 with
+			| Var _, Var _ | Method _, Method _ -> unify_kind cfk1 cfk2
+			| _ -> false
+		in
+
 		let rec loop i =
 			if i >= l then
 				raise Not_found;
 			let pfm = DynArray.unsafe_get d i in
 			try
-				self#unify tc pfm;
+				self#unify ~unify_kind ~strict:true tc pfm;
 				pfm
 			with Unify_error _ ->
 				loop (i + 1)
@@ -174,4 +188,4 @@ object(self)
 			end;
 		| _ ->
 			None
-end
+end

+ 3 - 1
std/hl/_std/Reflect.hx

@@ -133,7 +133,9 @@ class Reflect {
 	@:overload(function(f:Array<Dynamic>->Void):Dynamic {})
 	extern public static function makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic;
 
-	@:ifFeature("Reflect.makeVarArgs") static function _makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
+	@:keep
+	// @:ifFeature("Reflect.makeVarArgs")
+	static function _makeVarArgs(f:Array<Dynamic>->Dynamic):Dynamic {
 		return hl.Api.makeVarArgs(function(args:hl.NativeArray<Dynamic>) {
 			var arr = hl.types.ArrayDyn.alloc(hl.types.ArrayObj.alloc(args), true);
 			return f(cast arr);