Преглед изворни кода

Use VInlinedConstructorVariable to tag inlined but interesting variable for debug (#11578)

* Let inlineCtor in a not inline func gives VInlinedConstructorVariable

* Let VInlinedConstructorVariable carry original variable info as string

* Let get_pretty_name return a list, remove the illusion of having . in v_name

* Only tag VInlinedC when needed, was overwriting VGenerated

* Replace is_gen_local name, use string list for VInlinedC
Yuxiao Mao пре 1 година
родитељ
комит
707ea41d56

+ 1 - 1
src/compiler/hxb/hxbReader.ml

@@ -963,7 +963,7 @@ class hxb_reader
 			| 5 -> VUser TVOLocalFunction
 			| 6 -> VGenerated
 			| 7 -> VInlined
-			| 8 -> VInlinedConstructorVariable
+			| 8 -> VInlinedConstructorVariable (self#read_list (fun () -> self#read_string))
 			| 9 -> VExtractorVariable
 			| 10 -> VAbstractThis
 			| _ -> assert false

+ 16 - 14
src/compiler/hxb/hxbWriter.ml

@@ -980,20 +980,22 @@ module HxbWriter = struct
 			Chunk.write_uleb128 writer.chunk (Pool.add writer.enum_fields key (en,ef))
 
 	let write_var_kind writer vk =
-		let b = match vk with
-			| VUser TVOLocalVariable -> 0
-			| VUser TVOArgument -> 1
-			| VUser TVOForVariable -> 2
-			| VUser TVOPatternVariable -> 3
-			| VUser TVOCatchVariable -> 4
-			| VUser TVOLocalFunction -> 5
-			| VGenerated -> 6
-			| VInlined -> 7
-			| VInlinedConstructorVariable -> 8
-			| VExtractorVariable -> 9
-			| VAbstractThis -> 10
-		in
-		Chunk.write_u8 writer.chunk b
+		let b,sl = match vk with
+			| VUser TVOLocalVariable -> 0, []
+			| VUser TVOArgument -> 1, []
+			| VUser TVOForVariable -> 2, []
+			| VUser TVOPatternVariable -> 3, []
+			| VUser TVOCatchVariable -> 4, []
+			| VUser TVOLocalFunction -> 5, []
+			| VGenerated -> 6, []
+			| VInlined -> 7, []
+			| VInlinedConstructorVariable sl -> 8, sl
+			| VExtractorVariable -> 9, []
+			| VAbstractThis -> 10, []
+		in begin
+			Chunk.write_u8 writer.chunk b;
+			if (b == 8) then Chunk.write_list writer.chunk sl (Chunk.write_string writer.chunk);
+		end
 
 	let write_var writer fctx v =
 		Chunk.write_uleb128 writer.chunk v.v_id;

+ 1 - 1
src/core/tPrinting.ml

@@ -601,7 +601,7 @@ module Printer = struct
 			| TVOLocalFunction -> "TVOLocalFunction") ^ ")"
 		| VGenerated -> "VGenerated"
 		| VInlined -> "VInlined"
-		| VInlinedConstructorVariable -> "VInlinedConstructorVariable"
+		| VInlinedConstructorVariable sl -> "VInlinedConstructorVariable" ^ "(" ^ (String.concat ", " sl) ^ ")"
 		| VExtractorVariable -> "VExtractorVariable"
 		| VAbstractThis -> "VAbstractThis"
 

+ 1 - 1
src/core/tType.ml

@@ -144,7 +144,7 @@ and tvar_kind =
 	| VUser of tvar_origin
 	| VGenerated
 	| VInlined
-	| VInlinedConstructorVariable
+	| VInlinedConstructorVariable of string list
 	| VExtractorVariable
 	| VAbstractThis
 

+ 1 - 1
src/filters/filters.ml

@@ -103,7 +103,7 @@ let check_local_vars_init ctx e =
 		| TVar (v,eo) ->
 			begin
 				match eo with
-				| None when v.v_kind = VInlinedConstructorVariable ->
+				| None when (match v.v_kind with VInlinedConstructorVariable _ -> true | _ -> false) ->
 					()
 				| None ->
 					declared := v.v_id :: !declared;

+ 6 - 3
src/generators/genhl.ml

@@ -991,14 +991,17 @@ let real_name v =
 	in
 	match loop v.v_meta with
 	| "_gthis" -> "this"
-	| name -> name
+	| name -> match v.v_kind with
+		| VInlinedConstructorVariable sl -> String.concat "." sl
+		| _ -> name
 
-let is_gen_local ctx v = match v.v_kind with
+let not_debug_var ctx v = match v.v_kind with
 	| VUser _ -> false
+	| VInlinedConstructorVariable _ -> false
 	| _ -> true
 
 let add_assign ctx v =
-	if is_gen_local ctx v then () else
+	if not_debug_var ctx v then () else
 	let name = real_name v in
 	ctx.m.massign <- (alloc_string ctx name, current_pos ctx - 1) :: ctx.m.massign
 

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

@@ -655,7 +655,7 @@ and jit_expr jit return e =
 				wrap()
 			| TUnop((Increment | Decrement),_,e1) | TBinop((OpAssign | OpAssignOp _),e1,_) ->
 				begin match (Texpr.skip e1).eexpr with
-				| TLocal {v_kind = VGenerated | VInlined | VInlinedConstructorVariable | VExtractorVariable} ->
+				| TLocal {v_kind = VGenerated | VInlined | VInlinedConstructorVariable _ | VExtractorVariable} ->
 					f
 				| _ ->
 					wrap()

+ 1 - 1
src/optimization/analyzer.ml

@@ -664,7 +664,7 @@ module LocalDce = struct
 			has_var_flag v VAnalyzed
 		in
 		let keep v =
-			is_used v || ((match v.v_kind with VUser _ | VInlined -> true | _ -> false) && not ctx.config.local_dce) || ExtType.has_reference_semantics v.v_type || has_var_flag v VCaptured || Meta.has Meta.This v.v_meta
+			is_used v || ((match v.v_kind with VUser _ | VInlined | VInlinedConstructorVariable _ -> true | _ -> false) && not ctx.config.local_dce) || ExtType.has_reference_semantics v.v_type || has_var_flag v VCaptured || Meta.has Meta.This v.v_meta
 		in
 		let rec use v =
 			if not (is_used v) then begin

+ 1 - 1
src/optimization/analyzerTexpr.ml

@@ -790,7 +790,7 @@ module Fusion = struct
 			let num_uses = state#get_reads v in
 			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 is_compiler_generated = match v.v_kind with VUser _ | VInlined | VInlinedConstructorVariable _ -> false | _ -> true in
 			let has_type_params = match v.v_extra with Some ve when ve.v_params <> [] -> true | _ -> false in
 			let rec is_impure_extern e = match e.eexpr with
 				| TField(ef,(FStatic(cl,cf) | FInstance(cl,_,cf))) when has_class_flag cl CExtern ->

+ 18 - 5
src/optimization/inlineConstructors.ml

@@ -731,22 +731,35 @@ let inline_constructors ctx original_e =
 		let cf = ctx.f.curfield in
 		if !included_untyped && not (Meta.has Meta.HasUntyped cf.cf_meta) then cf.cf_meta <- (Meta.HasUntyped,[],e.epos) :: cf.cf_meta;
 		let e = make_expr_for_rev_list el e.etype e.epos in
-		let rec get_pretty_name iv = match iv.iv_kind with
+		let rec get_pretty_name iv : string list = match iv.iv_kind with
 			| IVKField(io,fname,None) ->
 				begin try
 					let is_user_variable iv = match iv.iv_var.v_kind with VUser _ | VInlined -> true | _ -> false in
 					let iv = List.find is_user_variable io.io_aliases in
-					(get_pretty_name iv) ^ "_" ^ fname;
+					fname :: (get_pretty_name iv);
 				with Not_found ->
-					(get_pretty_name (List.hd io.io_aliases)) ^ "_" ^ fname;
+					fname :: (get_pretty_name (List.hd io.io_aliases));
 				end
-			| _ -> iv.iv_var.v_name
+			| _ -> [iv.iv_var.v_name]
+		in
+		let is_user_kind iv = match iv.iv_var.v_kind with VUser _ -> true | _ -> false in
+		let rec was_user iv = match iv.iv_kind with
+			| IVKField(io,_,_) ->
+				begin try
+					let iv = List.find is_user_kind io.io_aliases in
+					(was_user iv);
+				with Not_found ->
+					(was_user (List.hd io.io_aliases)) ;
+				end
+			| _ -> is_user_kind iv
 		in
 		IntMap.iter (fun _ iv ->
 			let v = iv.iv_var in
 			if v.v_id < 0 then begin
 				v.v_id <- -v.v_id;
-				v.v_name <- get_pretty_name iv
+				let vnames = List.rev (get_pretty_name iv) in
+				v.v_name <- String.concat "_" vnames;
+				if (was_user iv) then v.v_kind <- VInlinedConstructorVariable vnames;
 			end
 		) !vars;
 		e