Browse Source

[dce] do not keep constructor if no physical var fields is kept (fixes #6807)

Alexander Kuzmenko 7 years ago
parent
commit
b44fdfa91f
3 changed files with 31 additions and 3 deletions
  1. 7 2
      src/core/type.ml
  2. 9 1
      src/optimization/dce.ml
  3. 15 0
      tests/unit/src/unit/issues/Issue6807.hx

+ 7 - 2
src/core/type.ml

@@ -790,11 +790,16 @@ let extract_field = function
 	| FAnon f | FInstance (_,_,f) | FStatic (_,f) | FClosure (_,f) -> Some f
 	| _ -> None
 
+let is_physical_var_field f =
+	match f.cf_kind with
+	| Var { v_read = AccNormal | AccInline | AccNo } | Var { v_write = AccNormal | AccNo } -> true
+	| Var _ -> Meta.has Meta.IsVar f.cf_meta
+	| _ -> false
+
 let is_physical_field f =
 	match f.cf_kind with
 	| Method _ -> true
-	| Var { v_read = AccNormal | AccInline | AccNo } | Var { v_write = AccNormal | AccNo } -> true
-	| _ -> Meta.has Meta.IsVar f.cf_meta
+	| _ -> is_physical_var_field f
 
 let field_type f =
 	match f.cf_params with

+ 9 - 1
src/optimization/dce.ml

@@ -145,7 +145,7 @@ and mark_field dce c cf stat =
 			| Some (c,_) -> mark_field dce c cf stat
 		end else
 			add cf;
-		if not stat then
+		if not stat && is_physical_var_field cf then
 			match c.cl_constructor with
 				| None -> ()
 				| Some ctor -> mark_field dce c ctor false
@@ -258,6 +258,14 @@ let rec mark_dependent_fields dce csup n stat =
 	in
 	loop_inheritance csup
 
+(*
+	if not stat then begin
+			match csup.cl_constructor with
+				| None -> ()
+				| Some ctor -> mark ctor
+		end
+*)
+
 (* expr and field evaluation *)
 
 let opt f e = match e with None -> () | Some e -> f e

+ 15 - 0
tests/unit/src/unit/issues/Issue6807.hx

@@ -0,0 +1,15 @@
+package unit.issues;
+
+class Issue6807 extends unit.Test {
+	function test() {
+		#if (dce != 'no')
+		t(null == Type.resolveClass('unit.issues._Issue6807.ShouldBeRemovedByDce'));
+		#end
+	}
+}
+
+private class ShouldBeRemovedByDce {
+	public var a = 0;
+	public var b(get,never):Int;
+	function get_b() return 0;
+}