فهرست منبع

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

Alexander Kuzmenko 7 سال پیش
والد
کامیت
ce1fe17db3
4فایلهای تغییر یافته به همراه23 افزوده شده و 2 حذف شده
  1. 1 1
      libs
  2. 1 1
      src/optimization/dce.ml
  3. 6 0
      src/typing/type.ml
  4. 15 0
      tests/unit/src/unit/issues/Issue6807.hx

+ 1 - 1
libs

@@ -1 +1 @@
-Subproject commit 8dbe1ee1ae4b31e7b605f24805d26bda9c701982
+Subproject commit 0e6ea857c0f7df5e69628f949d0d33a3ce5552a8

+ 1 - 1
src/optimization/dce.ml

@@ -129,7 +129,7 @@ and mark_field dce c cf stat =
 		end else
 			add cf;
 		if not stat then
-			match c.cl_constructor with
+			match c.cl_constructor && is_physical_var_field cf with
 				| None -> ()
 				| Some ctor -> mark_field dce c ctor false
 	end

+ 6 - 0
src/typing/type.ml

@@ -770,6 +770,12 @@ 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 } -> false
+	| Var _ -> not (Meta.has Meta.IsVar f.cf_meta)
+	| _ -> false
+
 let is_extern_field f =
 	match f.cf_kind with
 	| Method _ -> false

+ 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;
+}