Selaa lähdekoodia

[typer] turn v_extra into a record

Simon Krajewski 5 vuotta sitten
vanhempi
commit
4d2454f876

+ 10 - 10
src/codegen/gencommon/closuresToClass.ml

@@ -191,29 +191,29 @@ let traverse gen ?tparam_anon_decl ?tparam_anon_acc (handle_anon_func:texpr->tfu
 				| None -> Type.map_expr run e
 				| Some tparam_anon_decl ->
 					(match (vv, ve) with
-						| ({ v_extra = Some( _ :: _, _) } as v), Some ({ eexpr = TFunction tf } as f)
-						| ({ v_extra = Some( _ :: _, _) } as v), Some { eexpr = TArrayDecl([{ eexpr = TFunction tf } as f]) | TCall({ eexpr = TIdent "__array__" }, [{ eexpr = TFunction tf } as f]) } -> (* captured transformation *)
+						| ({ v_extra = Some({v_params = _ :: _}) } as v), Some ({ eexpr = TFunction tf } as f)
+						| ({ v_extra = Some({v_params = _ :: _}) } as v), Some { eexpr = TArrayDecl([{ eexpr = TFunction tf } as f]) | TCall({ eexpr = TIdent "__array__" }, [{ eexpr = TFunction tf } as f]) } -> (* captured transformation *)
 							tparam_anon_decl v f { tf with tf_expr = run tf.tf_expr };
 							{ e with eexpr = TBlock([]) }
 						| _ ->
 							Type.map_expr run { e with eexpr = TVar(vv, ve) })
 					)
-			| TBinop(OpAssign, { eexpr = TLocal({ v_extra = Some(_ :: _, _) } as v)}, ({ eexpr= TFunction tf } as f)) when is_some tparam_anon_decl ->
+			| TBinop(OpAssign, { eexpr = TLocal({ v_extra = Some({v_params = _ :: _}) } as v)}, ({ eexpr= TFunction tf } as f)) when is_some tparam_anon_decl ->
 				(match tparam_anon_decl with
 					| None -> die "" __LOC__
 					| Some tparam_anon_decl ->
 						tparam_anon_decl v f { tf with tf_expr = run tf.tf_expr };
 						{ e with eexpr = TBlock([]) }
 				)
-			| TLocal ({ v_extra = Some( _ :: _, _) } as v) ->
+			| TLocal ({ v_extra = Some({v_params =  _ :: _}) } as v) ->
 				(match tparam_anon_acc with
 				| None -> Type.map_expr run e
 				| Some tparam_anon_acc -> tparam_anon_acc v e false)
-			| TArray ( ({ eexpr = TLocal ({ v_extra = Some( _ :: _, _) } as v) } as expr), _) -> (* captured transformation *)
+			| TArray ( ({ eexpr = TLocal ({ v_extra = Some({v_params =  _ :: _}) } as v) } as expr), _) -> (* captured transformation *)
 				(match tparam_anon_acc with
 				| None -> Type.map_expr run e
 				| Some tparam_anon_acc -> tparam_anon_acc v { expr with etype = e.etype } false)
-			| TMeta((Meta.Custom ":tparamcall",_,_),({ eexpr=TLocal ({ v_extra = Some( _ :: _, _) } as v) } as expr)) ->
+			| TMeta((Meta.Custom ":tparamcall",_,_),({ eexpr=TLocal ({ v_extra = Some({v_params = _ :: _}) } as v) } as expr)) ->
 				(match tparam_anon_acc with
 				| None -> Type.map_expr run e
 				| Some tparam_anon_acc -> tparam_anon_acc v expr true)
@@ -334,12 +334,12 @@ let get_captured expr =
 				Type.iter traverse expr
 			| TVar (v, opt) ->
 				(match v.v_extra with
-					| Some(_ :: _, _) -> ()
+					| Some({v_params = _ :: _}) -> ()
 					| _ ->
 						check_params v.v_type);
 				Hashtbl.add ignored v.v_id v;
 				ignore(Option.map traverse opt)
-			| TLocal { v_extra = Some( (_ :: _ ),_) } ->
+			| TLocal { v_extra = Some({v_params = (_ :: _ )}) } ->
 				()
 			| TLocal v when has_var_flag v VCaptured ->
 				(if not (Hashtbl.mem ignored v.v_id || Hashtbl.mem ret v.v_id) then begin check_params v.v_type; Hashtbl.replace ret v.v_id expr end);
@@ -528,7 +528,7 @@ let configure gen ft =
 
 		(match tvar with
 		| None -> ()
-		| Some ({ v_extra = Some(_ :: _, _) } as v) ->
+		| Some ({ v_extra = Some({v_params = _ :: _}) } as v) ->
 			Hashtbl.add tvar_to_cdecl v.v_id (cls,captured)
 		| _ -> ());
 
@@ -596,7 +596,7 @@ let configure gen ft =
 				| _ -> die "" __LOC__) captured
 			in
 			let types = match v.v_extra with
-				| Some(t,_) -> t
+				| Some ve -> ve.v_params
 				| _ -> die "" __LOC__
 			in
 			let monos = List.map (fun _ -> mk_mono()) types in

+ 1 - 1
src/context/abstractCast.ml

@@ -255,7 +255,7 @@ let handle_abstract_casts ctx e =
 				let rec find_abstract e t = match follow t,e.eexpr with
 					| TAbstract(a,pl),_ when Meta.has Meta.MultiType a.a_meta -> a,pl,e
 					| _,TCast(e1,None) -> find_abstract e1 e1.etype
-					| _,TLocal {v_extra = Some(_,Some e')} ->
+					| _,TLocal {v_extra = Some({v_expr = Some e'})} ->
 						begin match follow e'.etype with
 						| TAbstract(a,pl) when Meta.has Meta.MultiType a.a_meta -> a,pl,mk (TCast(e,None)) e'.etype e.epos
 						| _ -> raise Not_found

+ 4 - 2
src/core/json/genjson.ml

@@ -283,7 +283,9 @@ and generate_type_parameter ctx (s,t) =
 (* texpr *)
 
 and generate_tvar ctx v =
-	let generate_extra (params,eo) = jobject (
+	let generate_extra ve =
+		let (params,eo) = (ve.v_params,ve.v_expr) in
+		jobject (
 		("params",jlist (generate_type_parameter ctx) params) ::
 		(match eo with
 		| None -> []
@@ -300,7 +302,7 @@ and generate_tvar ctx v =
 		"meta",generate_metadata ctx v.v_meta;
 		"pos",generate_pos ctx v.v_pos;
 		"isFinal",jbool (has_var_flag v VFinal);
-		"isInline",jbool (match v.v_extra with Some (_,Some _) -> true | _ -> false);
+		"isInline",jbool (match v.v_extra with Some {v_expr = Some _} -> true | _ -> false);
 	] in
 	let origin_to_int = function
 		| TVOLocalVariable -> 0

+ 6 - 0
src/core/tFunctions.ml

@@ -772,3 +772,9 @@ let type_has_meta t m =
 		| TType ({ t_meta = metadata }, _)
 		| TAbstract ({ a_meta = metadata }, _) -> has_meta m metadata
 
+(* tvar *)
+
+let var_extra params e = {
+	v_params = params;
+	v_expr = e;
+}

+ 2 - 2
src/core/tPrinting.ml

@@ -582,8 +582,8 @@ module Printer = struct
 			"a_write",s_opt (fun cf -> cf.cf_name) a.a_write;
 		]
 
-	let s_tvar_extra (tl,eo) =
-		Printf.sprintf "Some(%s, %s)" (s_type_params tl) (s_opt (s_expr_ast true "" s_type) eo)
+	let s_tvar_extra ve =
+		Printf.sprintf "Some(%s, %s)" (s_type_params ve.v_params) (s_opt (s_expr_ast true "" s_type) ve.v_expr)
 
 	let s_tvar v =
 		s_record_fields "" [

+ 5 - 2
src/core/tType.ml

@@ -67,7 +67,10 @@ and tconstant =
 	| TThis
 	| TSuper
 
-and tvar_extra = (type_params * texpr option) option
+and tvar_extra = {
+	v_params : type_params;
+	v_expr : texpr option;
+}
 
 and tvar_origin =
 	| TVOLocalVariable
@@ -89,7 +92,7 @@ and tvar = {
 	mutable v_name : string;
 	mutable v_type : t;
 	mutable v_kind : tvar_kind;
-	mutable v_extra : tvar_extra;
+	mutable v_extra : tvar_extra option;
 	mutable v_meta : metadata;
 	mutable v_flags : int;
 	v_pos : pos;

+ 6 - 6
src/filters/capturedVars.ml

@@ -128,8 +128,8 @@ let captured_vars com e =
 			let tmp_used = ref used in
 			let rec browse = function
 				| Block f | Loop f | Function f -> f browse
-				| Use ({ v_extra = Some( _ :: _, _) })
-				| Assign ({ v_extra = Some( _ :: _, _) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
+				| Use ({ v_extra = Some({v_params = _ :: _}) })
+				| Assign ({ v_extra = Some({v_params = _ :: _}) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
 					(* Java and C# deal with functions with type parameters in a different way *)
 					(* so they do should not be wrapped *)
 					()
@@ -219,8 +219,8 @@ let captured_vars com e =
 					incr depth;
 					f (collect_vars false);
 					decr depth;
-				| Use ({ v_extra = Some( _ :: _, _) })
-				| Assign ({ v_extra = Some( _ :: _, _) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
+				| Use ({ v_extra = Some({v_params = _ :: _}) })
+				| Assign ({ v_extra = Some({v_params = _ :: _}) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
 					(* Java/C# use a special handling for functions with type parmaters *)
 					()
 				| Declare v ->
@@ -256,8 +256,8 @@ let captured_vars com e =
 			decr depth;
 		| Declare v ->
 			vars := PMap.add v.v_id !depth !vars;
-		| Use ({ v_extra = Some( _ :: _, _) })
-		| Assign ({ v_extra = Some( _ :: _, _) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
+		| Use ({ v_extra = Some({v_params = _ :: _}) })
+		| Assign ({ v_extra = Some({v_params = _ :: _}) }) when com.platform = Cs || (com.platform = Java && not (Common.defined com Define.Jvm)) ->
 			()
 		| Use v ->
 			(try

+ 1 - 1
src/generators/genjava.ml

@@ -2438,7 +2438,7 @@ let generate con =
 	TArrayTransform.configure gen (
 	fun e _ ->
 		match e.eexpr with
-			| TArray ({ eexpr = TLocal { v_extra = Some( _ :: _, _) } }, _) -> (* captured transformation *)
+			| TArray ({ eexpr = TLocal { v_extra = Some({v_params = _ :: _}) } }, _) -> (* captured transformation *)
 				false
 			| TArray(e1, e2) ->
 				( match run_follow gen (follow e1.etype) with

+ 3 - 3
src/macro/macroApi.ml

@@ -1142,10 +1142,10 @@ and encode_tconst c =
 	encode_enum ITConstant tag pl
 
 and encode_tvar v =
-	let f_extra (pl,e) =
+	let f_extra ve =
 		encode_obj [
-			"params",encode_type_params pl;
-			"expr",vopt encode_texpr e
+			"params",encode_type_params ve.v_params;
+			"expr",vopt encode_texpr ve.v_expr;
 		]
 	in
 	encode_obj [

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -589,7 +589,7 @@ module Fusion = struct
 			let num_writes = state#get_writes v in
 			let can_be_used_as_value = can_be_used_as_value com e in
 			let is_compiler_generated = match v.v_kind with VUser _ | VInlined -> false | _ -> true in
-			let has_type_params = match v.v_extra with Some (tl,_) when tl <> [] -> true | _ -> false in
+			let has_type_params = match v.v_extra with Some ve when ve.v_params <> [] -> true | _ -> false in
 			let b = num_uses <= 1 &&
 			        num_writes = 0 &&
 			        can_be_used_as_value &&

+ 3 - 3
src/optimization/analyzerTypes.ml

@@ -176,7 +176,7 @@ module Graph = struct
 
 	type var_info = {
 		vi_var : tvar;                            (* The variable itself *)
-		vi_extra : tvar_extra;                    (* The original v_extra *)
+		vi_extra : tvar_extra option;             (* The original v_extra *)
 		vi_bb_declare : BasicBlock.t;             (* The block where this variable was declared *)
 		mutable vi_origin : tvar;                 (* The origin variable of this variable *)
 		mutable vi_writes : var_write;            (* A list of blocks that assign to this variable *)
@@ -210,11 +210,11 @@ module Graph = struct
 		} in
 		DynArray.add g.g_var_infos vi;
 		let i = DynArray.length g.g_var_infos - 1 in
-		v.v_extra <- Some([],Some (mk (TConst (TInt (Int32.of_int i))) t_dynamic null_pos));
+		v.v_extra <- Some(var_extra [] (Some (mk (TConst (TInt (Int32.of_int i))) t_dynamic null_pos)));
 		vi
 
 	let get_var_info g v = match v.v_extra with
-		| Some(_,Some {eexpr = TConst (TInt i32)}) -> DynArray.get g.g_var_infos (Int32.to_int i32)
+		| Some({v_expr = Some {eexpr = TConst (TInt i32)}}) -> DynArray.get g.g_var_infos (Int32.to_int i32)
 		| _ ->
 			print_endline "Unbound variable, please report this";
 			print_endline (Printer.s_tvar v);

+ 3 - 3
src/optimization/inline.ml

@@ -449,7 +449,7 @@ class inline_state ctx ethis params cf f p = object(self)
 					l.i_force_temp <- true;
 				end;
 				(* We use a null expression because we only care about the type (for abstract casts). *)
-				if l.i_abstract_this then l.i_subst.v_extra <- Some ([],Some {e with eexpr = TConst TNull});
+				if l.i_abstract_this then l.i_subst.v_extra <- Some (var_extra [] (Some {e with eexpr = TConst TNull}));
 				loop ((l,e) :: acc) pl al false
 			| [], (v,opt) :: al ->
 				let l = self#declare v in
@@ -598,8 +598,8 @@ class inline_state ctx ethis params cf f p = object(self)
 				if not (self#read v).i_outside then begin
 					v.v_type <- map_type v.v_type;
 					match v.v_extra with
-					| Some(tl,Some e) ->
-						v.v_extra <- Some(tl,Some (map_expr_type map_type e));
+					| Some ({v_expr = Some e} as ve) ->
+						v.v_extra <- Some(var_extra ve.v_params (Some (map_expr_type map_type e)));
 					| _ ->
 						()
 				end

+ 4 - 3
src/typing/typer.ml

@@ -334,7 +334,8 @@ let rec type_ident_raise ctx i p mode =
 	try
 		let v = PMap.find i ctx.locals in
 		(match v.v_extra with
-		| Some (params,e) ->
+		| Some ve ->
+			let (params,e) = (ve.v_params,ve.v_expr) in
 			let t = monomorphs params v.v_type in
 			(match e with
 			| Some ({ eexpr = TFunction f } as e) when ctx.com.display.dms_inline ->
@@ -2061,7 +2062,7 @@ and type_local_function ctx kind f with_type p =
 		| None -> None
 		| Some v ->
 			let v = (add_local_with_origin ctx TVOLocalFunction v ft pname) in
-			if params <> [] then v.v_extra <- Some (params,None);
+			if params <> [] then v.v_extra <- Some (var_extra params None);
 			Some v
 	) in
 	let curfun = match ctx.curfun with
@@ -2084,7 +2085,7 @@ and type_local_function ctx kind f with_type p =
 	| Some v ->
 		Typeload.generate_args_meta ctx.com None (fun m -> v.v_meta <- m :: v.v_meta) f.f_args;
 		let open LocalUsage in
-		if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None);
+		if params <> [] || inline then v.v_extra <- Some (var_extra params (if inline then Some e else None));
 		if ctx.in_display && DisplayPosition.display_position#enclosed_in v.v_pos then
 			DisplayEmitter.display_variable ctx v v.v_pos;
 		let rec loop = function