Browse Source

[typer] add apply_typedef convenience function

Simon Krajewski 3 years ago
parent
commit
4f3b0330ea

+ 1 - 1
src/codegen/codegen.ml

@@ -257,7 +257,7 @@ let rec is_volatile t =
 		is_volatile (lazy_type f)
 	| TType (t,tl) ->
 		(match t.t_path with
-		| _ -> is_volatile (apply_params t.t_params tl t.t_type))
+		| _ -> is_volatile (apply_typedef t tl))
 	| _ ->
 		false
 

+ 2 - 2
src/codegen/gencommon/gencommon.ml

@@ -110,7 +110,7 @@ let follow_once t =
 	| TLazy f ->
 		lazy_type f
 	| TType (t,tl) ->
-		apply_params t.t_params tl t.t_type
+		apply_typedef t tl
 	| TAbstract({a_path = [],"Null"},[t]) ->
 		t
 	| _ ->
@@ -665,7 +665,7 @@ let init_ctx gen =
 		| TLazy f ->
 			follow_f (lazy_type f)
 		| TType (t,tl) ->
-			follow_f (apply_params t.t_params tl t.t_type)
+			follow_f (apply_typedef t tl)
 		| TAbstract({a_path = [],"Null"},[t]) ->
 			follow_f t
 		| _ -> Some t

+ 1 - 1
src/codegen/gencommon/hardNullableSynf.ml

@@ -55,7 +55,7 @@ let rec is_null_t gen t = match gen.greal_type t with
 	| TMono r -> (match r.tm_type with | Some t -> is_null_t gen t | None -> None)
 	| TLazy f -> is_null_t gen (lazy_type f)
 	| TType (t, tl) ->
-		is_null_t gen (apply_params t.t_params tl t.t_type)
+		is_null_t gen (apply_typedef t tl)
 	| _ -> None
 
 let follow_addon gen t =

+ 1 - 1
src/codegen/overloads.ml

@@ -106,7 +106,7 @@ struct
 			t
 		| TAbstract(a,tl) -> simplify_t (Abstract.get_underlying_type a tl)
 		| TType(t, tl) ->
-			simplify_t (apply_params t.t_params tl t.t_type)
+			simplify_t (apply_typedef t tl)
 		| TMono r -> (match r.tm_type with
 			| Some t -> simplify_t t
 			| None -> t_dynamic)

+ 1 - 1
src/context/typecore.ml

@@ -652,7 +652,7 @@ let rec is_pos_infos = function
 	| TType ({ t_path = ["haxe"] , "PosInfos" },[]) ->
 		true
 	| TType (t,tl) ->
-		is_pos_infos (apply_params t.t_params tl t.t_type)
+		is_pos_infos (apply_typedef t tl)
 	| TAbstract({a_path=[],"Null"},[t]) ->
 		is_pos_infos t
 	| _ ->

+ 1 - 1
src/core/abstract.ml

@@ -119,7 +119,7 @@ and get_underlying_type ?(return_first=false) a pl =
 			| TAbstract({a_path=([],"Null")} as a,[t1]) ->
 				TAbstract(a,[loop t1])
 			| TType (t,tl) ->
-				loop (apply_params t.t_params tl t.t_type)
+				loop (apply_typedef t tl)
 			| TAbstract(a,tl) when not (Meta.has Meta.CoreType a.a_meta) ->
 				if rec_stack_exists (fast_eq t) underlying_type_stack then begin
 					let pctx = print_context() in

+ 9 - 6
src/core/tFunctions.ml

@@ -436,6 +436,9 @@ let apply_params ?stack cparams params t =
 	in
 	loop t
 
+let apply_typedef td tl =
+	apply_params td.t_params tl td.t_type
+
 let monomorphs eparams t =
 	apply_params eparams (List.map (fun _ -> mk_mono()) eparams) t
 
@@ -463,7 +466,7 @@ let rec follow t =
 	| TLazy f ->
 		follow (lazy_type f)
 	| TType (t,tl) ->
-		follow (apply_params t.t_params tl t.t_type)
+		follow (apply_typedef t tl)
 	| TAbstract({a_path = [],"Null"},[t]) ->
 		follow t
 	| _ -> t
@@ -477,7 +480,7 @@ let follow_once t =
 	| TAbstract _ | TEnum _ | TInst _ | TFun _ | TAnon _ | TDynamic _ ->
 		t
 	| TType (t,tl) ->
-		apply_params t.t_params tl t.t_type
+		apply_typedef t tl
 	| TLazy f ->
 		lazy_type f
 
@@ -490,7 +493,7 @@ let rec follow_without_null t =
 	| TLazy f ->
 		follow_without_null (lazy_type f)
 	| TType (t,tl) ->
-		follow_without_null (apply_params t.t_params tl t.t_type)
+		follow_without_null (apply_typedef t tl)
 	| _ -> t
 
 let rec follow_without_type t =
@@ -522,7 +525,7 @@ let rec is_nullable ?(no_lazy=false) = function
 		| _ -> is_nullable (lazy_type f)
 		)
 	| TType (t,tl) ->
-		is_nullable ~no_lazy (apply_params t.t_params tl t.t_type)
+		is_nullable ~no_lazy (apply_typedef t tl)
 	| TFun _ ->
 		false
 (*
@@ -553,7 +556,7 @@ let rec is_null ?(no_lazy=false) = function
 		| _ -> is_null (lazy_type f)
 		)
 	| TType (t,tl) ->
-		is_null ~no_lazy (apply_params t.t_params tl t.t_type)
+		is_null ~no_lazy (apply_typedef t tl)
 	| _ ->
 		false
 
@@ -566,7 +569,7 @@ let rec is_explicit_null = function
 	| TLazy f ->
 		is_explicit_null (lazy_type f)
 	| TType (t,tl) ->
-		is_explicit_null (apply_params t.t_params tl t.t_type)
+		is_explicit_null (apply_typedef t tl)
 	| _ ->
 		false
 

+ 1 - 1
src/core/tOther.ml

@@ -208,7 +208,7 @@ module ExtType = struct
 		let rec loop t = match t with
 			| TInst(c,_) -> check c.cl_meta
 			| TEnum(en,_) -> check en.e_meta
-			| TType(t,tl) -> check t.t_meta || (loop (apply_params t.t_params tl t.t_type))
+			| TType(t,tl) -> check t.t_meta || (loop (apply_typedef t tl))
 			| TAbstract(a,_) -> check a.a_meta
 			| TLazy f -> loop (lazy_type f)
 			| TMono r ->

+ 2 - 2
src/core/tUnification.ml

@@ -1024,7 +1024,7 @@ and unify_with_variance uctx f t1 t2 =
 	let unify_nested t1 t2 = with_variance (get_nested_context uctx) f t1 t2 in
 	let unify_tls tl1 tl2 = List.iter2 unify_nested tl1 tl2 in
 	let get_this_type ab tl = follow_without_type (apply_params ab.a_params tl ab.a_this) in
-	let get_defined_type td tl = follow_without_type (apply_params td.t_params tl td.t_type) in
+	let get_defined_type td tl = follow_without_type (apply_typedef td tl) in
 	let compare_underlying () = type_eq {uctx with equality_underlying = true; equality_kind = EqBothDynamic} t1 t2 in
 	let unifies_abstract uctx a b ab tl ats =
 		try
@@ -1140,7 +1140,7 @@ module UnifyMinT = struct
 					loop t);
 				tl := t :: !tl;
 			| TType (td,pl) ->
-				loop (apply_params td.t_params pl td.t_type);
+				loop (apply_typedef td pl);
 				(* prioritize the most generic definition *)
 				tl := t :: !tl;
 			| TLazy f -> loop (lazy_type f)

+ 2 - 2
src/generators/gencpp.ml

@@ -804,7 +804,7 @@ and type_string_suff suffix haxe_type remap =
          | _ -> die "" __LOC__)
       | ["cpp"] , "Function" ->
          "::cpp::Function< " ^ (cpp_function_signature_params params ) ^ " >"
-      | _ ->  type_string_suff suffix (apply_params type_def.t_params params type_def.t_type) remap
+      | _ ->  type_string_suff suffix (apply_typedef type_def params) remap
       )
    | TFun (args,haxe_type) -> "Dynamic" ^ suffix
    | TAnon a -> "Dynamic"
@@ -1773,7 +1773,7 @@ let rec cpp_type_of stack ctx haxe_type =
 
       | TType (type_def,params) ->
          cpp_type_from_path stack ctx type_def.t_path params (fun () ->
-            cpp_type_of stack ctx (apply_params type_def.t_params params type_def.t_type) )
+            cpp_type_of stack ctx (apply_typedef type_def params) )
 
       | TFun _ -> TCppObject
       | TAnon _ -> TCppObject

+ 1 - 1
src/generators/gencs.ml

@@ -110,7 +110,7 @@ let rec is_null t =
 	match t with
 		| TInst( { cl_path = (["haxe"; "lang"], "Null") }, _ )
 		| TAbstract( { a_path = ([], "Null") }, _ ) -> true
-		| TType( t, tl ) -> is_null (apply_params t.t_params tl t.t_type)
+		| TType( t, tl ) -> is_null (apply_typedef t tl)
 		| TMono r ->
 			(match r.tm_type with
 			| Some t -> is_null t

+ 1 - 1
src/generators/genhl.ml

@@ -380,7 +380,7 @@ let rec to_type ?tref ctx t =
 		let t =
 			get_rec_cache ctx t
 				(fun() -> abort "Unsupported recursive type" td.t_pos)
-				(fun tref -> to_type ~tref ctx (apply_params td.t_params tl td.t_type))
+				(fun tref -> to_type ~tref ctx (apply_typedef td tl))
 		in
 		(match td.t_path with
 		| ["haxe";"macro"], name -> Hashtbl.replace ctx.macro_typedefs name t; t

+ 1 - 1
src/generators/genjvm.ml

@@ -181,7 +181,7 @@ let rec jsignature_of_type gctx stack t =
 	| TType(td,tl) ->
 		begin match gctx.typedef_interfaces#get_interface_class td.t_path with
 		| Some c -> TObject(c.cl_path,[])
-		| None -> jsignature_of_type (apply_params td.t_params tl td.t_type)
+		| None -> jsignature_of_type (apply_typedef td tl)
 		end
 	| TLazy f -> jsignature_of_type (lazy_type f)
 

+ 1 - 1
src/generators/genshared.ml

@@ -141,7 +141,7 @@ object(self)
 			begin try
 				Some (Hashtbl.find pfms td.t_path)
 			with Not_found ->
-				self#identify accept_anons (apply_params td.t_params tl td.t_type)
+				self#identify accept_anons (apply_typedef td tl)
 			end
 		| TMono {tm_type = Some t} ->
 			self#identify accept_anons t

+ 1 - 1
src/generators/genswf9.ml

@@ -220,7 +220,7 @@ let rec follow_basic t =
 	| TType ({ t_path = [],"UInt" },[]) ->
 		t
 	| TType (t,tl) ->
-		follow_basic (apply_params t.t_params tl t.t_type)
+		follow_basic (apply_typedef t tl)
 	| TAbstract (a,pl) when not (Meta.has Meta.CoreType a.a_meta) ->
 		follow_basic (apply_params a.a_params pl a.a_this)
 	| _ -> t

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

@@ -555,7 +555,7 @@ let handle_decoding_error f v t =
 				| _ -> error "expected Bool" v
 			end
 		| TType(t,tl) ->
-			loop tabs (apply_params t.t_params tl t.t_type) v
+			loop tabs (apply_typedef t tl) v
 		| TAbstract({a_path=["haxe";"macro"],"Position"},_) ->
 			begin match v with
 				| VInstance {ikind=IPos _} -> f "#pos"

+ 1 - 1
src/macro/macroApi.ml

@@ -1836,7 +1836,7 @@ let macro_api ccom get_api =
 				| TAbstract _ | TEnum _ | TInst _ | TFun _ | TAnon _ | TDynamic _ ->
 					t
 				| TType (t,tl) ->
-					apply_params t.t_params tl t.t_type
+					apply_typedef t tl
 				| TLazy f ->
 					lazy_type f
 			in

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -167,7 +167,7 @@ let type_change_ok com t1 t2 =
 			| TLazy f ->
 				is_nullable_or_whatever (lazy_type f)
 			| TType (t,tl) ->
-				is_nullable_or_whatever (apply_params t.t_params tl t.t_type)
+				is_nullable_or_whatever (apply_typedef t tl)
 			| TFun _ ->
 				false
 			| TInst ({ cl_kind = KTypeParameter _ },_) ->

+ 1 - 1
src/optimization/dce.ml

@@ -299,7 +299,7 @@ let rec to_string dce t = match t with
 	| TType(tt,tl) ->
 		if not (List.exists (fun t2 -> Type.fast_eq t t2) dce.ts_stack) then begin
 			dce.ts_stack <- t :: dce.ts_stack;
-			to_string dce (apply_params tt.t_params tl tt.t_type)
+			to_string dce (apply_typedef tt tl)
 		end
 	| TAbstract({a_impl = Some c} as a,tl) ->
 		if Meta.has Meta.CoreType a.a_meta then

+ 1 - 1
src/typing/fields.ml

@@ -297,7 +297,7 @@ let type_field cfg ctx e i p mode (with_type : WithType.t) =
 		type_field_by_forward f Meta.Forward a
 	in
 	let type_field_by_typedef f e td tl =
-		f e (follow_without_type (apply_params td.t_params tl td.t_type))
+		f e (follow_without_type (apply_typedef td tl))
 	in
 	let type_field_by_interfaces e c =
 		(* For extern lib types we didn't go through check_interfaces and check_abstract_class, which handles some field

+ 5 - 5
src/typing/nullSafety.ml

@@ -80,7 +80,7 @@ let rec is_nullable_type = function
 	| TLazy f ->
 		is_nullable_type (lazy_type f)
 	| TType (t,tl) ->
-		is_nullable_type (apply_params t.t_params tl t.t_type)
+		is_nullable_type (apply_typedef t tl)
 	| _ ->
 		false
 
@@ -235,9 +235,9 @@ class unificator =
 					| _, TMono t ->
 						(match t.tm_type with None -> () | Some t -> self#unify a t)
 					| TType (t,tl), _ ->
-						self#unify_rec a b (fun() -> self#unify (apply_params t.t_params tl t.t_type) b)
+						self#unify_rec a b (fun() -> self#unify (apply_typedef t tl) b)
 					| _, TType (t,tl) ->
-						self#unify_rec a b (fun() -> self#unify a (apply_params t.t_params tl t.t_type))
+						self#unify_rec a b (fun() -> self#unify a (apply_typedef t tl))
 					| TAbstract (abstr,tl), _ when not (Meta.has Meta.CoreType abstr.a_meta) ->
 						self#unify (apply_params abstr.a_params tl abstr.a_this) b
 					| _, TAbstract (abstr,tl) when not (Meta.has Meta.CoreType abstr.a_meta) ->
@@ -341,7 +341,7 @@ let rec unfold_null t =
 		| TAbstract ({ a_path = ([],"Null") }, [t]) -> unfold_null t
 		| TAbstract (abstr,tl) when not (Meta.has Meta.CoreType abstr.a_meta) -> unfold_null (apply_params abstr.a_params tl abstr.a_this)
 		| TLazy f -> unfold_null (lazy_type f)
-		| TType (t,tl) -> unfold_null (apply_params t.t_params tl t.t_type)
+		| TType (t,tl) -> unfold_null (apply_typedef t tl)
 		| _ -> t
 
 (**
@@ -367,7 +367,7 @@ let rec can_pass_type src dst =
 			| TMono r -> (match r.tm_type with None -> true | Some t -> can_pass_type src t)
 			| TEnum (_, params) -> true
 			| TInst _ -> true
-			| TType (t, tl) -> can_pass_type src (apply_params t.t_params tl t.t_type)
+			| TType (t, tl) -> can_pass_type src (apply_typedef t tl)
 			| TFun _ -> true
 			| TAnon _ -> true
 			| TDynamic _ -> true

+ 1 - 1
src/typing/typeload.ml

@@ -726,7 +726,7 @@ let t_iterator ctx =
 		add_dependency ctx.m.curmod t.t_module;
 		if List.length t.t_params <> 1 then die "" __LOC__;
 		let pt = mk_mono() in
-		apply_params t.t_params [pt] t.t_type, pt
+		apply_typedef t [pt], pt
 	| _ ->
 		die "" __LOC__
 

+ 1 - 1
src/typing/typeloadModule.ml

@@ -829,7 +829,7 @@ let init_module_type ctx context_init (decl,p) =
 						check_rec (lazy_type f);
 					| TType (td,tl) ->
 						if td == t then typing_error "Recursive typedef is not allowed" p;
-						check_rec (apply_params td.t_params tl td.t_type)
+						check_rec (apply_typedef td tl)
 					| _ ->
 						()
 				in

+ 1 - 1
src/typing/typerBase.ml

@@ -89,7 +89,7 @@ let rec type_module_type ctx t tparams p =
 		let types = (match tparams with None -> Monomorph.spawn_constrained_monos (fun t -> t) e.e_params | Some l -> l) in
 		mk (TTypeExpr (TEnumDecl e)) (TType (e.e_type,types)) p
 	| TTypeDecl s ->
-		let t = apply_params s.t_params (List.map (fun _ -> spawn_monomorph ctx p) s.t_params) s.t_type in
+		let t = apply_typedef s (List.map (fun _ -> spawn_monomorph ctx p) s.t_params) in
 		DeprecationCheck.check_typedef ctx.com s p;
 		(match follow t with
 		| TEnum (e,params) ->