Browse Source

[dce] run accessor fix even in no-dce mode (closes #3756)

Simon Krajewski 11 years ago
parent
commit
f9fcd72f32
5 changed files with 55 additions and 25 deletions
  1. 2 1
      .gitignore
  2. 25 22
      dce.ml
  3. 11 2
      filters.ml
  4. 13 0
      tests/misc/projects/Issue3756/Main.hx
  5. 4 0
      tests/misc/projects/Issue3756/compile.hxml

+ 2 - 1
.gitignore

@@ -67,4 +67,5 @@ tests/sys/bin/
 tests/optimization/dump/
 tests/optimization/dump/
 tests/misc/projects/*/*.n
 tests/misc/projects/*/*.n
 tests/unit/bin/
 tests/unit/bin/
-tests/*.n
+tests/*.n
+tests/misc/projects/Issue3756/cpp/

+ 25 - 22
dce.ml

@@ -379,6 +379,30 @@ and expr dce e =
 	| _ ->
 	| _ ->
 		Type.iter (expr dce) e
 		Type.iter (expr dce) e
 
 
+let fix_accessors com =
+	List.iter (fun mt -> match mt with
+		| (TClassDecl c) ->
+			let rec has_accessor c n stat =
+				PMap.mem n (if stat then c.cl_statics else c.cl_fields)
+				|| match c.cl_super with Some (csup,_) -> has_accessor csup n stat | None -> false
+			in
+			let check_prop stat cf =
+				(match cf.cf_kind with
+				| Var {v_read = AccCall; v_write = a} ->
+					let s = "get_" ^ cf.cf_name in
+					cf.cf_kind <- Var {v_read = if has_accessor c s stat then AccCall else AccNever; v_write = a}
+				| _ -> ());
+				(match cf.cf_kind with
+				| Var {v_write = AccCall; v_read = a} ->
+					let s = "set_" ^ cf.cf_name in
+					cf.cf_kind <- Var {v_write = if has_accessor c s stat then AccCall else AccNever; v_read = a}
+				| _ -> ())
+			in
+			List.iter (check_prop true) c.cl_ordered_statics;
+			List.iter (check_prop false) c.cl_ordered_fields;
+		| _ -> ()
+	) com.types
+
 let run com main full =
 let run com main full =
 	let dce = {
 	let dce = {
 		com = com;
 		com = com;
@@ -538,28 +562,7 @@ let run com main full =
 	com.types <- loop [] (List.rev com.types);
 	com.types <- loop [] (List.rev com.types);
 
 
 	(* extra step to adjust properties that had accessors removed (required for Php and Cpp) *)
 	(* extra step to adjust properties that had accessors removed (required for Php and Cpp) *)
-	List.iter (fun mt -> match mt with
-		| (TClassDecl c) ->
-			let rec has_accessor c n stat =
-				PMap.mem n (if stat then c.cl_statics else c.cl_fields)
-				|| match c.cl_super with Some (csup,_) -> has_accessor csup n stat | None -> false
-			in
-			let check_prop stat cf =
-				(match cf.cf_kind with
-				| Var {v_read = AccCall; v_write = a} ->
-					let s = "get_" ^ cf.cf_name in
-					cf.cf_kind <- Var {v_read = if has_accessor c s stat then AccCall else AccNever; v_write = a}
-				| _ -> ());
-				(match cf.cf_kind with
-				| Var {v_write = AccCall; v_read = a} ->
-					let s = "set_" ^ cf.cf_name in
-					cf.cf_kind <- Var {v_write = if has_accessor c s stat then AccCall else AccNever; v_read = a}
-				| _ -> ())
-			in
-			List.iter (check_prop true) c.cl_ordered_statics;
-			List.iter (check_prop false) c.cl_ordered_fields;
-		| _ -> ()
-	) com.types;
+	fix_accessors com;
 
 
 	(* remove "override" from fields that do not override anything anymore *)
 	(* remove "override" from fields that do not override anything anymore *)
 	List.iter (fun mt -> match mt with
 	List.iter (fun mt -> match mt with

+ 11 - 2
filters.ml

@@ -1081,8 +1081,17 @@ let run com tctx main =
 	(* check @:remove metadata before DCE so it is ignored there (issue #2923) *)
 	(* check @:remove metadata before DCE so it is ignored there (issue #2923) *)
 	List.iter (check_remove_metadata tctx) com.types;
 	List.iter (check_remove_metadata tctx) com.types;
 	(* DCE *)
 	(* DCE *)
-	let dce_mode = (try Common.defined_value com Define.Dce with _ -> "no") in
-	if not (Common.defined com Define.As3 || dce_mode = "no" || Common.defined com Define.DocGen) then Dce.run com main (dce_mode = "full" && not (Common.defined com Define.Interp));
+	let dce_mode = if Common.defined com Define.As3 || Common.defined com Define.DocGen then
+		"no"
+	else
+		(try Common.defined_value com Define.Dce with _ -> "no")
+	in
+	begin match dce_mode with
+		| "full" -> Dce.run com main (not (Common.defined com Define.Interp))
+		| "std" -> Dce.run com main false
+		| "no" -> Dce.fix_accessors com
+		| _ -> failwith ("Unknown DCE mode " ^ dce_mode)
+	end;
 	(* always filter empty abstract implementation classes (issue #1885) *)
 	(* always filter empty abstract implementation classes (issue #1885) *)
 	List.iter (fun mt -> match mt with
 	List.iter (fun mt -> match mt with
 		| TClassDecl({cl_kind = KAbstractImpl _} as c) when c.cl_ordered_statics = [] && c.cl_ordered_fields = [] && not (Meta.has Meta.Used c.cl_meta) ->
 		| TClassDecl({cl_kind = KAbstractImpl _} as c) when c.cl_ordered_statics = [] && c.cl_ordered_fields = [] && not (Meta.has Meta.Used c.cl_meta) ->

+ 13 - 0
tests/misc/projects/Issue3756/Main.hx

@@ -0,0 +1,13 @@
+class Res {
+    public static var name(get,never) : String;
+    @:extern static inline function get_name() {
+        return "OK";
+    }
+}
+
+class Main {
+
+    static function main() {
+        trace(Res.name);
+    }
+}

+ 4 - 0
tests/misc/projects/Issue3756/compile.hxml

@@ -0,0 +1,4 @@
+-main Main
+-dce no
+-cpp cpp
+# can't use --no-output here