소스 검색

[dce] don't process expressions of extern classes (closes #8176) (#9532)

* [dce] don't process expressions of extern classes (closes #8176)

* fix remark
Dan Korostelev 5 년 전
부모
커밋
dfcfd34e1a
3개의 변경된 파일30개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      src/optimization/dce.ml
  2. 19 0
      tests/misc/projects/Issue8176/Main.hx
  3. 5 0
      tests/misc/projects/Issue8176/compile.hxml

+ 6 - 4
src/optimization/dce.ml

@@ -747,10 +747,12 @@ let mark dce =
 			) cfl;
 			(* follow expressions to new types/fields *)
 			List.iter (fun (c,cf,_) ->
-				let pop = push_class dce c in
-				opt (expr dce) cf.cf_expr;
-				List.iter (fun cf -> if cf.cf_expr <> None then opt (expr dce) cf.cf_expr) cf.cf_overloads;
-				pop();
+				if not c.cl_extern then begin
+					let pop = push_class dce c in
+					opt (expr dce) cf.cf_expr;
+					List.iter (fun cf -> if cf.cf_expr <> None then opt (expr dce) cf.cf_expr) cf.cf_overloads;
+					pop()
+				end
 			) cfl;
 			loop ()
 	in

+ 19 - 0
tests/misc/projects/Issue8176/Main.hx

@@ -0,0 +1,19 @@
+function main() {
+	Test.func();
+}
+
+@:keep
+@:native("Test")
+class TestStub {
+	static function func() {}
+}
+
+class Test {
+	public static function func() {
+		trace(Unused);
+	}
+}
+
+class Unused {
+	static function __init__() throw new haxe.Exception("this should be eliminated");
+}

+ 5 - 0
tests/misc/projects/Issue8176/compile.hxml

@@ -0,0 +1,5 @@
+-main Main
+-js bin/main.js
+-dce full
+--macro exclude("Test")
+--cmd node bin/main.js