Browse Source

added tvar_kind (conservative) (#7311)

removed InlineConstructorVariable and ":extractorVariable" (now in tvar_kind)
Nicolas Cannasse 7 years ago
parent
commit
0cfa743cee

+ 2 - 2
src/codegen/codegen.ml

@@ -170,7 +170,7 @@ let fix_override com c f fd =
 					end;
 					cur
 				with Unify_error _ ->
-					let v2 = alloc_var (prefix ^ v.v_name) t2 v.v_pos in
+					let v2 = alloc_var VGenerated (prefix ^ v.v_name) t2 v.v_pos in
 					changed_args := (v,v2) :: !changed_args;
 					v2,ct
 			) fd.tf_args targs in
@@ -435,7 +435,7 @@ let default_cast ?(vtmp="$t") com e texpr t p =
 		| TAbstractDecl a -> TAnon { a_fields = PMap.empty; a_status = ref (AbstractStatics a) }
 		| TTypeDecl _ -> assert false
 	in
-	let vtmp = alloc_var vtmp e.etype e.epos in
+	let vtmp = alloc_var VGenerated vtmp e.etype e.epos in
 	let var = mk (TVar (vtmp,Some e)) api.tvoid p in
 	let vexpr = mk (TLocal vtmp) e.etype p in
 	let texpr = mk (TTypeExpr texpr) (mk_texpr texpr) p in

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

@@ -118,7 +118,7 @@ let follow_once t =
 
 let t_empty = TAnon({ a_fields = PMap.empty; a_status = ref Closed })
 
-let alloc_var n t = Type.alloc_var n t null_pos
+let alloc_var n t = Type.alloc_var VGenerated n t null_pos
 
 let mk_local = Texpr.Builder.make_local
 

+ 5 - 5
src/context/typecore.ml

@@ -206,8 +206,8 @@ let save_locals ctx =
 	let locals = ctx.locals in
 	(fun() -> ctx.locals <- locals)
 
-let add_local ctx n t p =
-	let v = alloc_var n t p in
+let add_local ctx k n t p =
+	let v = alloc_var k n t p in
 	if Define.defined ctx.com.defines Define.WarnVarShadowing then begin
 		try
 			let v' = PMap.find n ctx.locals in
@@ -219,8 +219,8 @@ let add_local ctx n t p =
 	ctx.locals <- PMap.add n v ctx.locals;
 	v
 
-let add_local_with_origin ctx n t p origin =
-	let v = add_local ctx n t p in
+let add_local_with_origin ctx k n t p origin =
+	let v = add_local ctx k n t p in
 	if ctx.com.display.DisplayMode.dms_kind <> DisplayMode.DMNone then v.v_meta <- (TVarOrigin.encode_in_meta origin) :: v.v_meta;
 	v
 
@@ -235,7 +235,7 @@ let gen_local ctx t p =
 		else
 			nv
 	in
-	let v = add_local ctx (loop 0) t p in
+	let v = add_local ctx VGenerated (loop 0) t p in
 	(* v.v_meta <- (Meta.CompilerGenerated,[],null_pos) :: v.v_meta; *)
 	v
 

+ 0 - 2
src/core/meta.ml

@@ -78,7 +78,6 @@ type strict_meta =
 	| Include
 	| InitPackage
 	| InlineConstructorArgument of int * int
-	| InlineConstructorVariable
 	| Internal
 	| IsVar
 	| JavaCanonical
@@ -278,7 +277,6 @@ let get_info = function
 	| Include -> ":include",("",[Platform Cpp])
 	| InitPackage -> ":initPackage",("Some weird thing for Genjs we want to remove someday",[UsedInternally; Platform Js])
 	| InlineConstructorArgument _ -> ":inlineConstructorArgument",("Internally used to mark expressions that were passed as arguments of an inlined constructor",[UsedInternally])
-	| InlineConstructorVariable -> ":inlineConstructorVariable",("Internally used to mark variables that come from inlined constructors",[UsedInternally])
 	| Internal -> ":internal",("Generates the annotated field/class with 'internal' access",[Platforms [Java;Cs]; UsedOnEither[TClass;TEnum;TClassField]])
 	| IsVar -> ":isVar",("Forces a physical field to be generated for properties that otherwise would not require one",[UsedOn TClassField])
 	| JavaCanonical -> ":javaCanonical",("Used by the Java target to annotate the canonical path of the type",[HasParam "Output type package";HasParam "Output type name";UsedOnEither [TClass;TEnum]; Platform Java])

+ 2 - 2
src/core/texpr.ml

@@ -55,7 +55,7 @@ let rec equal e1 e2 = match e1.eexpr,e2.eexpr with
 let duplicate_tvars e =
 	let vars = Hashtbl.create 0 in
 	let copy_var v =
-		let v2 = alloc_var v.v_name v.v_type v.v_pos in
+		let v2 = alloc_var v.v_kind v.v_name v.v_type v.v_pos in
 		v2.v_meta <- v.v_meta;
 		v2.v_extra <- v.v_extra;
 		Hashtbl.add vars v.v_id v2;
@@ -335,7 +335,7 @@ let rec type_constant_value basic (e,p) =
 		error "Constant value expected" p
 
 let for_remap basic v e1 e2 p =
-	let v' = alloc_var v.v_name e1.etype e1.epos in
+	let v' = alloc_var v.v_kind v.v_name e1.etype e1.epos in
 	let ev' = mk (TLocal v') e1.etype e1.epos in
 	let t1 = (Abstract.follow_with_abstracts e1.etype) in
 	let ehasnext = mk (TField(ev',try quick_field t1 "hasNext" with Not_found -> error (s_type (print_context()) t1 ^ "has no field hasNext()") p)) (tfun [] basic.tbool) e1.epos in

+ 9 - 1
src/core/type.ml

@@ -85,10 +85,18 @@ and tconstant =
 
 and tvar_extra = (type_params * texpr option) option
 
+and tvar_kind =
+	| VUser
+	| VGenerated
+	| VInlined
+	| VInlinedConstructorVariable
+	| VExtractorVariable
+
 and tvar = {
 	mutable v_id : int;
 	mutable v_name : string;
 	mutable v_type : t;
+	mutable v_kind : tvar_kind;
 	mutable v_capture : bool;
 	mutable v_extra : tvar_extra;
 	mutable v_meta : metadata;
@@ -406,7 +414,7 @@ end
 
 let alloc_var =
 	let uid = ref 0 in
-	(fun n t p -> incr uid; { v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None; v_meta = []; v_pos = p })
+	(fun kind n t p -> incr uid; { v_kind = kind; v_name = n; v_type = t; v_id = !uid; v_capture = false; v_extra = None; v_meta = []; v_pos = p })
 
 let alloc_mid =
 	let mid = ref 0 in

+ 2 - 2
src/filters/capturedVars.ml

@@ -87,7 +87,7 @@ let captured_vars com e =
 	in
 
 	let mk_var v used =
-		let v2 = alloc_var v.v_name (PMap.find v.v_id used) v.v_pos in
+		let v2 = alloc_var v.v_kind v.v_name (PMap.find v.v_id used) v.v_pos in
 		v2.v_meta <- v.v_meta;
 		v2
 	in
@@ -158,7 +158,7 @@ let captured_vars com e =
 			*)
 			if com.config.pf_capture_policy = CPLoopVars then
 				(* We don't want to duplicate any variable declarations, so let's make copies (issue #3902). *)
-				let new_vars = List.map (fun v -> v.v_id,alloc_var v.v_name v.v_type v.v_pos) vars in
+				let new_vars = List.map (fun v -> v.v_id,alloc_var v.v_kind v.v_name v.v_type v.v_pos) vars in
 				let rec loop e = match e.eexpr with
 					| TLocal v ->
 						begin try

+ 1 - 1
src/filters/defaultArguments.ml

@@ -52,7 +52,7 @@ let add_opt com block pos (var,opt) =
 		(var, opt)
 	| Some const ->
 		let basic = com.basic in
-		let nullable_var = alloc_var var.v_name (basic.tnull var.v_type) pos in
+		let nullable_var = alloc_var var.v_kind var.v_name (basic.tnull var.v_type) pos in
 		(* var v = (temp_var == null) ? const : cast temp_var; *)
 		let evar = mk (TVar(var, Some(gen_check basic var.v_type nullable_var const pos))) basic.tvoid pos in
 		block := evar :: !block;

+ 2 - 2
src/filters/filters.ml

@@ -111,7 +111,7 @@ let check_local_vars_init e =
 		| TVar (v,eo) ->
 			begin
 				match eo with
-				| None when Meta.has Meta.InlineConstructorVariable v.v_meta ->
+				| None when v.v_kind = VInlinedConstructorVariable ->
 					()
 				| None ->
 					declared := v.v_id :: !declared;
@@ -518,7 +518,7 @@ let add_field_inits reserved ctx t =
 	let apply c =
 		let ethis = mk (TConst TThis) (TInst (c,List.map snd c.cl_params)) c.cl_pos in
 		(* TODO: we have to find a variable name which is not used in any of the functions *)
-		let v = alloc_var "_g" ethis.etype ethis.epos in
+		let v = alloc_var VGenerated "_g" ethis.etype ethis.epos in
 		let need_this = ref false in
 		let inits,fields = List.fold_left (fun (inits,fields) cf ->
 			match cf.cf_kind,cf.cf_expr with

+ 3 - 3
src/filters/jsExceptions.ml

@@ -114,8 +114,8 @@ let init ctx =
 		| TTry (etry, catches) ->
 			let etry = loop vrethrow etry in
 
-			let catchall_name = match catches with [(v,_)] -> v.v_name | _ -> "e" in
-			let vcatchall = alloc_var catchall_name t_dynamic e.epos in
+			let catchall_name, catchall_kind = match catches with [(v,_)] -> v.v_name, VUser | _ -> "e", VGenerated in
+			let vcatchall = alloc_var catchall_kind catchall_name t_dynamic e.epos in
 			let ecatchall = make_local vcatchall e.epos in
 			let erethrow = mk (TThrow ecatchall) t_dynamic e.epos in
 
@@ -125,7 +125,7 @@ let init ctx =
 			let eVal = field { ecatchall with etype = TInst (cHaxeError,[]) } "val" t_dynamic e.epos in
 			let eunwrap = mk (TIf (eInstanceof, eVal, Some (ecatchall))) t_dynamic e.epos in
 
-			let vunwrapped = alloc_var catchall_name t_dynamic e.epos in
+			let vunwrapped = alloc_var catchall_kind catchall_name t_dynamic e.epos in
 			vunwrapped.v_meta <- (Meta.CompilerGenerated,[],Globals.null_pos) :: vunwrapped.v_meta;
 			let eunwrapped = make_local vunwrapped e.epos in
 

+ 2 - 2
src/filters/tryCatchWrapper.ml

@@ -79,9 +79,9 @@ let init com (should_wrap:t->bool) (wrap_throw:texpr->texpr) (unwrap_expr:texpr-
 			| _, (v, c) :: _ ->
 				let pos = c.epos in
 
-				let temp_var = alloc_var "catchallException" catchall_type pos in
+				let temp_var = alloc_var VGenerated "catchallException" catchall_type pos in
 				let temp_local = make_local temp_var pos in
-				let catchall_var = alloc_var "realException" t_dynamic pos in
+				let catchall_var = alloc_var VGenerated "realException" t_dynamic pos in
 				let catchall_local = make_local catchall_var pos in
 
 				(* if it is of type wrapper_type, unwrap it *)

+ 1 - 1
src/filters/varLazifier.ml

@@ -3,7 +3,7 @@ open Type
 
 let apply com e =
 	let rec loop var_inits e = match e.eexpr with
-		| TVar(v,Some e1) when (Meta.has (Meta.Custom ":extractorVariable") v.v_meta) ->
+		| TVar(v,Some e1) when v.v_kind = VExtractorVariable ->
 			let var_inits,e1 = loop var_inits e1 in
 			let var_inits = PMap.add v.v_id e1 var_inits in
 			var_inits,{e with eexpr = TVar(v,None)}

+ 1 - 1
src/generators/genas3.ml

@@ -842,7 +842,7 @@ and gen_value ctx e =
 	let value block =
 		let old = ctx.in_value in
 		let t = type_str ctx e.etype e.epos in
-		let r = alloc_var (gen_local ctx "$r") e.etype e.epos in
+		let r = alloc_var VGenerated (gen_local ctx "$r") e.etype e.epos in
 		ctx.in_value <- Some r;
 		if ctx.in_static then
 			print ctx "function() : %s " t

+ 2 - 4
src/generators/genhl.ml

@@ -961,9 +961,7 @@ let real_name v =
 	| name -> name
 
 let is_gen_local ctx v =
-	if has_meta Meta.CompilerGenerated v.v_meta || has_meta Meta.ForLoopVariable v.v_meta then true
-	else if String.length v.v_name >= 2 && String.unsafe_get v.v_name 0 = '_' && String.unsafe_get v.v_name 1 = 'g' then true
-	else false
+	v.v_kind <> VUser
 
 let add_assign ctx v =
 	if is_gen_local ctx v then () else
@@ -2117,7 +2115,7 @@ and eval_expr ctx e =
 				let eargs, et = (match follow ef.ef_type with TFun (args,ret) -> args, ret | _ -> assert false) in
 				let ct = ctx.com.basic in
 				let p = ef.ef_pos in
-				let eargs = List.map (fun (n,o,t) -> Type.alloc_var n t en.e_pos, if o then Some TNull else None) eargs in
+				let eargs = List.map (fun (n,o,t) -> Type.alloc_var VGenerated n t en.e_pos, if o then Some TNull else None) eargs in
 				let ecall = mk (TCall (e,List.map (fun (v,_) -> mk (TLocal v) v.v_type p) eargs)) et p in
 				let f = {
 					tf_args = eargs;

+ 1 - 1
src/generators/genjs.ml

@@ -783,7 +783,7 @@ and gen_value ctx e =
 	in
 	let value() =
 		let old = ctx.in_value, ctx.in_loop in
-		let r = alloc_var "$r" t_dynamic e.epos in
+		let r = alloc_var VGenerated "$r" t_dynamic e.epos in
 		ctx.in_value <- Some r;
 		ctx.in_loop <- false;
 		spr ctx "(function($this) ";

+ 4 - 4
src/generators/genlua.ml

@@ -1136,7 +1136,7 @@ and gen_value ctx e =
     let value() =
         let old = ctx.in_value, ctx.in_loop in
         let r_id = temp ctx in
-        let r = alloc_var r_id t_dynamic e.epos in
+        let r = alloc_var VGenerated r_id t_dynamic e.epos in
         ctx.in_value <- Some r;
         ctx.in_loop <- false;
         spr ctx "(function() ";
@@ -1326,10 +1326,10 @@ and gen_tbinop ctx op e1 e2 =
      | Ast.OpAssignOp(op2), TArray(e3,e4), _ ->
          (* TODO: Figure out how to rewrite this expression more cleanly *)
          println ctx "(function() ";
-         let idx = alloc_var "idx" e4.etype e4.epos in
+         let idx = alloc_var VGenerated "idx" e4.etype e4.epos in
          let idx_var =  mk (TVar( idx , Some(e4))) e4.etype e4.epos in
          gen_expr ctx idx_var;
-         let arr = alloc_var "arr" e3.etype e3.epos in
+         let arr = alloc_var VGenerated "arr" e3.etype e3.epos in
          let arr_var = mk (TVar(arr, Some(e3))) e3.etype e3.epos in
          gen_expr ctx arr_var;
          newline ctx;
@@ -1344,7 +1344,7 @@ and gen_tbinop ctx op e1 e2 =
      | Ast.OpAssignOp(op2), TField(e3,e4), _ ->
          (* TODO: Figure out how to rewrite this expression more cleanly *)
          println ctx "(function() ";
-         let obj = alloc_var "obj" e3.etype e3.epos in
+         let obj = alloc_var VGenerated "obj" e3.etype e3.epos in
          spr ctx "local fld = ";
          (match e4 with
           | FInstance(_,_,fld)

+ 4 - 2
src/generators/genpy.ml

@@ -174,6 +174,8 @@ module Transformer = struct
 	let lift_expr1 is_value next_id blocks e =
 		lift_expr ~is_value:is_value ~next_id:(Some next_id) ~blocks:blocks e
 
+	let alloc_var = Type.alloc_var VGenerated
+
 	let to_tvar ?(capture = false) n t p =
 		alloc_var n t p
 		(* { v_name = n; v_type = t; v_id = 0; v_capture = capture; v_extra = None; v_meta = [] } *)
@@ -1865,7 +1867,7 @@ module Generator = struct
 					| e_last :: el ->
 						let new_last = {e_last with eexpr = TReturn (Some e_last)} in
 						let new_block = {expr2 with eexpr = TBlock (List.rev (new_last :: el))} in
-						let v_name = alloc_var name (tfun [] e_last.etype) e_last.epos in
+						let v_name = alloc_var VGenerated name (tfun [] e_last.etype) e_last.epos in
 						let f_name = mk (TLocal v_name) v_name.v_type e_last.epos in
 						let call_f = mk (TCall(f_name,[])) e_last.etype e_last.epos in
 						Some new_block,call_f
@@ -1895,7 +1897,7 @@ module Generator = struct
 		let e = match e.eexpr with
 			| TFunction(f) ->
 				let args = if add_self then
-					let v = alloc_var "self" t_dynamic p in
+					let v = alloc_var VGenerated "self" t_dynamic p in
 					v.v_meta <- (Meta.This,[],p) :: v.v_meta;
 					(v,None) :: f.tf_args
 				else

+ 3 - 3
src/generators/genswf9.ml

@@ -2007,7 +2007,7 @@ let generate_field_kind ctx f c stat =
 			) args;
 			let dparams = (match !dparams with None -> None | Some l -> Some (List.rev l)) in
 			Some (HFMethod {
-				hlm_type = end_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t f.cf_pos, (if opt then Some TNull else None)) args) dparams tret;
+				hlm_type = end_fun ctx (List.map (fun (a,opt,t) -> alloc_var VUser a t f.cf_pos, (if opt then Some TNull else None)) args) dparams tret;
 				hlm_final = false;
 				hlm_override = false;
 				hlm_kind = snd (method_kind());
@@ -2199,7 +2199,7 @@ let generate_class ctx c =
 let generate_enum ctx e meta =
 	let name_id = type_path ctx e.e_path in
 	let api = ctx.com.basic in
-	let f = begin_fun ctx [alloc_var "tag" api.tstring e.e_pos, None;alloc_var "index" api.tint e.e_pos, None;alloc_var "params" (api.tarray (mk_mono())) e.e_pos, None] api.tvoid [ethis] false e.e_pos in
+	let f = begin_fun ctx [alloc_var VGenerated "tag" api.tstring e.e_pos, None;alloc_var VGenerated "index" api.tint e.e_pos, None;alloc_var VGenerated "params" (api.tarray (mk_mono())) e.e_pos, None] api.tvoid [ethis] false e.e_pos in
 	let tag_id = ident "tag" in
 	let index_id = ident "index" in
 	let params_id = ident "params" in
@@ -2230,7 +2230,7 @@ let generate_enum ctx e meta =
 			hlf_slot = !st_count;
 			hlf_kind = (match f.ef_type with
 				| TFun (args,_) ->
-					let fdata = begin_fun ctx (List.map (fun (a,opt,t) -> alloc_var a t e.e_pos, (if opt then Some TNull else None)) args) (TEnum (e,[])) [] true f.ef_pos in
+					let fdata = begin_fun ctx (List.map (fun (a,opt,t) -> alloc_var VGenerated a t e.e_pos, (if opt then Some TNull else None)) args) (TEnum (e,[])) [] true f.ef_pos in
 					write ctx (HFindPropStrict name_id);
 					write ctx (HString f.ef_name);
 					write ctx (HInt f.ef_index);

+ 1 - 1
src/optimization/analyzer.ml

@@ -141,7 +141,7 @@ module Ssa = struct
 	let rec rename_in_block ctx bb =
 		let write_var v is_phi i =
 			update_reaching_def ctx v bb;
-			let v' = alloc_var (v.v_name) v.v_type v.v_pos in
+			let v' = alloc_var v.v_kind v.v_name v.v_type v.v_pos in
 			declare_var ctx.graph v' bb;
 			v'.v_meta <- v.v_meta;
 			v'.v_capture <- v.v_capture;

+ 2 - 2
src/optimization/analyzerTexprTransformer.ml

@@ -239,7 +239,7 @@ let rec func ctx bb tf t p =
 				| s :: _ -> s
 				| [] -> ctx.temp_var_name
 		in
-		let v = match v with Some v -> v | None -> alloc_var (loop e) e.etype e.epos in
+		let v = match v with Some v -> v | None -> alloc_var VGenerated (loop e) e.etype e.epos in
 		begin match ctx.com.platform with
 			| Globals.Cpp when sequential && not (Common.defined ctx.com Define.Cppia) -> ()
 			| _ -> v.v_meta <- [Meta.CompilerGenerated,[],e.epos];
@@ -314,7 +314,7 @@ let rec func ctx bb tf t p =
 				e
 			| _ ->
 				if is_asvar_type t then begin
-					let v = alloc_var "tmp" t e.epos in
+					let v = alloc_var VGenerated "tmp" t e.epos in
 					let bb',e = bind_to_temp ~v:(Some v) !bb false e in
 					bb := bb';
 					e

+ 2 - 2
src/optimization/inline.ml

@@ -258,7 +258,7 @@ class inline_state ctx ethis params cf f p = object(self)
 		try
 			Hashtbl.find locals v.v_id
 		with Not_found ->
-			let v' = alloc_var v.v_name v.v_type v.v_pos in
+			let v' = alloc_var VInlined v.v_name v.v_type v.v_pos in
 			v'.v_extra <- v.v_extra;
 			let i = {
 				i_var = v;
@@ -404,7 +404,7 @@ class inline_state ctx ethis params cf f p = object(self)
 			Build the expr/var subst list
 		*)
 		let ethis = (match ethis.eexpr with TConst TSuper -> { ethis with eexpr = TConst TThis } | _ -> ethis) in
-		let vthis = alloc_var "_this" ethis.etype ethis.epos in
+		let vthis = alloc_var VInlined "_this" ethis.etype ethis.epos in
 		let args1 = (ethis :: params) in
 		let args2 = ((vthis,None) :: f.tf_args) in
 		let vars = loop [] args1 args2 true in

+ 5 - 5
src/optimization/inlineConstructors.ml

@@ -150,7 +150,7 @@ let inline_constructors ctx e =
 		PMap.find s io.io_fields
 	in
 	let alloc_io_field_full (io:inline_object) (fname:string) (constexpr_option:texpr option) (t:t) (p:pos) : inline_var =
-		let v = alloc_var fname t p in
+		let v = alloc_var VInlined fname t p in
 		let iv = add v (IVKField (io,fname,constexpr_option)) in
 		io.io_fields <- PMap.add fname iv io.io_fields;
 		iv
@@ -229,7 +229,7 @@ let inline_constructors ctx e =
 						begin match e.eexpr with
 						| TConst _ -> loop (vs, decls, e::es) el
 						| _ ->
-							let v = alloc_var "arg" e.etype e.epos in
+							let v = alloc_var VInlined "arg" e.etype e.epos in
 							let decle = mk (TVar(v, Some e)) ctx.t.tvoid e.epos in
 							let io_id_start = !current_io_id in
 							ignore(analyze_aliases true decle);
@@ -241,7 +241,7 @@ let inline_constructors ctx e =
 				in
 				let argvs, argvdecls, pl = loop ([],[],[]) pl in
 				let _, cname = c.cl_path in
-				let v = alloc_var ("inl"^cname) e.etype e.epos in
+				let v = alloc_var VInlined ("inl"^cname) e.etype e.epos in
 				match Inline.type_inline_ctor ctx c cf tf (mk (TLocal v) (TInst (c,tl)) e.epos) pl e.epos with
 				| Some inlined_expr ->
 					let has_untyped = (Meta.has Meta.HasUntyped cf.cf_meta) in
@@ -273,7 +273,7 @@ let inline_constructors ctx e =
 		| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some _} as cf)} as c,_,pl),_ when is_extern_ctor c cf ->
 			error "Extern constructor could not be inlined" e.epos;
 		| TObjectDecl fl, _ when captured && fl <> [] && List.for_all (fun((s,_,_),_) -> Lexer.is_valid_identifier s) fl ->
-			let v = alloc_var "inlobj" e.etype e.epos in
+			let v = alloc_var VInlined "inlobj" e.etype e.epos in
 			let ev = mk (TLocal v) v.v_type e.epos in
 			let el = List.map (fun ((s,_,_),e) ->
 				let ef = mk (TField(ev,FDynamic s)) e.etype e.epos in
@@ -290,7 +290,7 @@ let inline_constructors ctx e =
 			Some iv
 		| TArrayDecl el, TInst(_, [elemtype]) when captured ->
 			let len = List.length el in
-			let v = alloc_var "inlarr" e.etype e.epos in
+			let v = alloc_var VInlined "inlarr" e.etype e.epos in
 			let ev = mk (TLocal v) v.v_type e.epos in
 			let el = List.mapi (fun i e ->
 				let ef = mk (TArray(ev,(mk (TConst(TInt (Int32.of_int i))) e.etype e.epos))) elemtype e.epos in

+ 1 - 2
src/optimization/optimizer.ml

@@ -384,8 +384,7 @@ let inline_constructors ctx e =
 	in
 	let add_field_var v s t =
 		let ii = IntMap.find v.v_id !vars in
-		let v' = alloc_var (Printf.sprintf "%s_%s" v.v_name s) t v.v_pos in
-		v'.v_meta <- (Meta.InlineConstructorVariable,[],v.v_pos) :: v'.v_meta;
+		let v' = alloc_var VInlinedConstructorVariable (Printf.sprintf "%s_%s" v.v_name s) t v.v_pos in
 		ii.ii_fields <- PMap.add s v' ii.ii_fields;
 		v'
 	in

+ 5 - 5
src/typing/calls.ml

@@ -426,9 +426,9 @@ let rec acc_get ctx g p =
 			(* arguments might not have names in case of variable fields of function types, so we generate one (issue #2495) *)
 			let args = List.map (fun (n,o,t) ->
 				let t = if o then ctx.t.tnull t else t in
-				o,if n = "" then gen_local ctx t e.epos else alloc_var n t e.epos (* TODO: var pos *)
+				o,if n = "" then gen_local ctx t e.epos else alloc_var VGenerated n t e.epos (* TODO: var pos *)
 			) args in
-			let ve = alloc_var "_e" e.etype e.epos in
+			let ve = alloc_var VGenerated "_e" e.etype e.epos in
 			let ecall = make_call ctx et (List.map (fun v -> mk (TLocal v) v.v_type p) (ve :: List.map snd args)) ret p in
 			let ecallb = mk (TFunction {
 				tf_args = List.map (fun (o,v) -> v,if o then Some TNull else None) args;
@@ -674,12 +674,12 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 			error "Usage of _ is not supported for optional non-nullable arguments" p
 		| (n,o,t) :: args , ([] as params)
 		| (n,o,t) :: args , (EConst(Ident "_"),_) :: params ->
-			let v = alloc_var (alloc_name n) (if o then ctx.t.tnull t else t) p in
+			let v = alloc_var VGenerated (alloc_name n) (if o then ctx.t.tnull t else t) p in
 			loop args params given_args (missing_args @ [v,o]) (ordered_args @ [vexpr v])
 		| (n,o,t) :: args , param :: params ->
 			let e = type_expr ctx param (WithType t) in
 			let e = AbstractCast.cast_or_unify ctx t e p in
-			let v = alloc_var (alloc_name n) t (pos param) in
+			let v = alloc_var VGenerated (alloc_name n) t (pos param) in
 			loop args params (given_args @ [v,o,Some e]) missing_args (ordered_args @ [vexpr v])
 	in
 	let given_args,missing_args,ordered_args = loop args params [] [] [] in
@@ -687,7 +687,7 @@ let type_bind ctx (e : texpr) (args,ret) params p =
 		let name = if n = 0 then "f" else "f" ^ (string_of_int n) in
 		if List.exists (fun (n,_,_) -> name = n) args then gen_loc_name (n + 1) else name
 	in
-	let loc = alloc_var (gen_loc_name 0) e.etype e.epos in
+	let loc = alloc_var VGenerated (gen_loc_name 0) e.etype e.epos in
 	let given_args = (loc,false,Some e) :: given_args in
 	let inner_fun_args l = List.map (fun (v,o) -> v.v_name, o, v.v_type) l in
 	let t_inner = TFun(inner_fun_args missing_args, ret) in

+ 2 - 2
src/typing/forLoop.ml

@@ -18,7 +18,7 @@ let rec optimize_for_loop ctx (i,pi) e1 e2 p =
 		TField (e,try quick_field e.etype n with Not_found -> assert false)
 	in
 	let gen_it_local pt =
-		add_local_with_origin ctx i pt pi (TVarOrigin.TVOForVariable)
+		add_local_with_origin ctx VUser i pt pi (TVarOrigin.TVOForVariable)
 	in
 	let gen_int_iter pt f_get f_length =
 		let i = gen_it_local pt in
@@ -239,7 +239,7 @@ let type_for_loop ctx handle_display it e2 p =
 	let e2 = Expr.ensure_block e2 in
 	let default() =
 		let t, pt = Typeload.t_iterator ctx in
-		let i = add_local_with_origin ctx i pt pi (TVarOrigin.TVOForVariable) in
+		let i = add_local_with_origin ctx VUser i pt pi (TVarOrigin.TVOForVariable) in
 		let e1 = (match follow e1.etype with
 		| TMono _
 		| TDynamic _ ->

+ 1 - 1
src/typing/generic.ml

@@ -85,7 +85,7 @@ let generic_substitute_expr gctx e =
 		try
 			Hashtbl.find vars v.v_id
 		with Not_found ->
-			let v2 = alloc_var v.v_name (generic_substitute_type gctx v.v_type) v.v_pos in
+			let v2 = alloc_var v.v_kind v.v_name (generic_substitute_type gctx v.v_type) v.v_pos in
 			v2.v_meta <- v.v_meta;
 			Hashtbl.add vars v.v_id v2;
 			v2

+ 2 - 3
src/typing/matcher.ml

@@ -184,7 +184,7 @@ module Pattern = struct
 				pctx.current_locals <- PMap.add name (v,p) pctx.current_locals;
 				v
 			| _ ->
-				let v = alloc_var name t p in
+				let v = alloc_var VUser name t p in
 				v.v_meta <- (TVarOrigin.encode_in_meta TVarOrigin.TVOPatternVariable) :: v.v_meta;
 				pctx.current_locals <- PMap.add name (v,p) pctx.current_locals;
 				ctx.locals <- PMap.add name v ctx.locals;
@@ -1098,8 +1098,7 @@ module Compile = struct
 					let patterns = make_offset_list (left2 + 1) (right2 - 1) pat pat_any @ patterns in
 					(left + 1, right - 1,ev :: subjects,((case,bindings,patterns) :: cases),ex_bindings)
 				with Not_found ->
-					let v = alloc_var "_hx_tmp" e1.etype e1.epos in
-					v.v_meta <- (Meta.Custom ":extractorVariable",[],v.v_pos) :: v.v_meta;
+					let v = alloc_var VExtractorVariable "_hx_tmp" e1.etype e1.epos in
 					let ex_bindings = (v,e1.epos,e1,left,right) :: ex_bindings in
 					let patterns = make_offset_list (left + 1) (right - 1) pat pat_any @ patterns in
 					let ev = mk (TLocal v) v.v_type e1.epos in

+ 1 - 1
src/typing/typeloadFields.ml

@@ -163,7 +163,7 @@ let ensure_struct_init_constructor ctx c ast_fields p =
 				let has_default_expr = field_has_default_expr cf.cf_name in
 				let opt = has_default_expr || (Meta.has Meta.Optional cf.cf_meta) in
 				let t = if opt then ctx.t.tnull cf.cf_type else cf.cf_type in
-				let v = alloc_var cf.cf_name t p in
+				let v = alloc_var VUser cf.cf_name t p in
 				let ef = mk (TField(ethis,FInstance(c,params,cf))) t p in
 				let ev = mk (TLocal v) v.v_type p in
 				(* this.field = <constructor_argument> *)

+ 3 - 3
src/typing/typeloadFunction.ml

@@ -88,7 +88,7 @@ let type_function ctx args ret fmode f do_display p =
 	let fargs = List.map2 (fun (n,c,t) ((_,pn),_,m,_,_) ->
 		if starts_with n '$' then error "Function argument names starting with a dollar are not allowed" p;
 		let c = type_function_arg_value ctx t c do_display in
-		let v,c = add_local_with_origin ctx n t pn (TVarOrigin.TVOArgument), c in
+		let v,c = add_local_with_origin ctx VUser n t pn (TVarOrigin.TVOArgument), c in
 		v.v_meta <- v.v_meta @ m;
 		if do_display && DisplayPosition.encloses_display_position pn then
 			DisplayEmitter.display_variable ctx v pn;
@@ -243,12 +243,12 @@ let add_constructor ctx c force_constructor p =
 					| TFun (args,_) ->
 						List.map (fun (n,o,t) ->
 							let def = try type_function_arg_value ctx t (Some (PMap.find n values)) false with Not_found -> if o then Some TNull else None in
-							map_arg (alloc_var n (if o then ctx.t.tnull t else t) p,def) (* TODO: var pos *)
+							map_arg (alloc_var VUser n (if o then ctx.t.tnull t else t) p,def) (* TODO: var pos *)
 						) args
 					| _ -> assert false
 			) in
 			let p = c.cl_pos in
-			let vars = List.map (fun (v,def) -> alloc_var v.v_name (apply_params csup.cl_params cparams v.v_type) v.v_pos, def) args in
+			let vars = List.map (fun (v,def) -> alloc_var VUser v.v_name (apply_params csup.cl_params cparams v.v_type) v.v_pos, def) args in
 			let super_call = mk (TCall (mk (TConst TSuper) (TInst (csup,cparams)) p,List.map (fun (v,_) -> mk (TLocal v) v.v_type p) vars)) ctx.t.tvoid p in
 			let constr = mk (TFunction {
 				tf_args = vars;

+ 7 - 7
src/typing/typer.ml

@@ -1074,12 +1074,12 @@ and type_unop ctx op flag e p =
 		| AKAccess(a,tl,c,ebase,ekey) ->
 			begin try
 				(match op with Increment | Decrement -> () | _ -> raise Not_found);
-				let v_key = alloc_var "tmp" ekey.etype ekey.epos in
+				let v_key = alloc_var VGenerated "tmp" ekey.etype ekey.epos in
 				let evar_key = mk (TVar(v_key,Some ekey)) ctx.com.basic.tvoid ekey.epos in
 				let ekey = mk (TLocal v_key) ekey.etype ekey.epos in
 				(* get *)
 				let e_get = mk_array_get_call ctx (AbstractCast.find_array_access_raise ctx a tl ekey None p) c ebase p in
-				let v_get = alloc_var "tmp" e_get.etype e_get.epos in
+				let v_get = alloc_var VGenerated "tmp" e_get.etype e_get.epos in
 				let ev_get = mk (TLocal v_get) v_get.v_type p in
 				let evar_get = mk (TVar(v_get,Some e_get)) ctx.com.basic.tvoid p in
 				(* op *)
@@ -1398,7 +1398,7 @@ and type_access ctx e p mode =
 				let monos = List.map (fun _ -> mk_mono()) c.cl_params in
 				let ct, cf = get_constructor ctx c monos p in
 				let args = match follow ct with TFun(args,ret) -> args | _ -> assert false in
-				let vl = List.map (fun (n,_,t) -> alloc_var n t c.cl_pos) args in
+				let vl = List.map (fun (n,_,t) -> alloc_var VGenerated n t c.cl_pos) args in
 				let vexpr v = mk (TLocal v) v.v_type p in
 				let el = List.map vexpr vl in
 				let ec,t = match c.cl_kind with
@@ -1481,7 +1481,7 @@ and type_vars ctx vl p =
 					Some e
 			) in
 			if starts_with v '$' then display_error ctx "Variables names starting with a dollar are not allowed" p;
-			let v = add_local_with_origin ctx v t pv TVarOrigin.TVOLocalVariable in
+			let v = add_local_with_origin ctx VUser v t pv TVarOrigin.TVOLocalVariable in
 			v.v_meta <- (Meta.UserVariable,[],pv) :: v.v_meta;
 			if ctx.in_display && DisplayPosition.encloses_display_position pv then
 				DisplayEmitter.display_variable ctx v pv;
@@ -1489,7 +1489,7 @@ and type_vars ctx vl p =
 		with
 			Error (e,p) ->
 				check_error ctx e p;
-				add_local ctx v t_dynamic pv, None (* TODO: What to do with this... *)
+				add_local ctx VUser v t_dynamic pv, None (* TODO: What to do with this... *)
 	) vl in
 	match vl with
 	| [v,eo] ->
@@ -1878,7 +1878,7 @@ and type_try ctx e1 catches with_type p =
 		if starts_with v '$' then display_error ctx "Catch variable names starting with a dollar are not allowed" p;
 		check_unreachable acc1 t2 (pos e_ast);
 		let locals = save_locals ctx in
-		let v = add_local_with_origin ctx v t pv (TVarOrigin.TVOCatchVariable) in
+		let v = add_local_with_origin ctx VUser v t pv (TVarOrigin.TVOCatchVariable) in
 		if ctx.is_display_file && DisplayPosition.encloses_display_position pv then
 			DisplayEmitter.display_variable ctx v pv;
 		let e = type_expr ctx e_ast with_type in
@@ -2020,7 +2020,7 @@ and type_local_function ctx name f with_type p =
 		| None -> None
 		| Some v ->
 			if starts_with v '$' then display_error ctx "Variable names starting with a dollar are not allowed" p;
-			let v = (add_local_with_origin ctx v ft pname (TVarOrigin.TVOLocalFunction)) in
+			let v = (add_local_with_origin ctx VUser v ft pname (TVarOrigin.TVOLocalFunction)) in
 			if params <> [] then v.v_extra <- Some (params,None);
 			Some v
 	) in

+ 1 - 1
src/typing/typerBase.ml

@@ -89,7 +89,7 @@ let get_this ctx p =
 				let v = if ctx.curfun = FunMemberAbstractLocal then
 					PMap.find "this" ctx.locals
 				else
-					add_local ctx "`this" ctx.tthis p
+					add_local ctx VGenerated "`this" ctx.tthis p
 				in
 				ctx.vthis <- Some v;
 				v