瀏覽代碼

always perform std library DCE for all platforms. Only perform full DCE when explicit --dead-code-elimination is set (fixed issue #899)

Nicolas Cannasse 13 年之前
父節點
當前提交
be18467a37
共有 5 個文件被更改,包括 15 次插入7 次删除
  1. 1 1
      common.ml
  2. 10 1
      dce.ml
  3. 3 3
      main.ml
  4. 1 1
      typeload.ml
  5. 0 1
      typer.ml

+ 1 - 1
common.ml

@@ -411,7 +411,7 @@ let rec has_feature com f =
 			let r = (try
 				let path = List.rev pack, cl in
 				(match List.find (fun t -> t_path t = path && not (has_meta ":realPath" (t_infos t).mt_meta)) com.types with
-				| t when meth = "*" -> not (defined com "dce") || has_meta ":used" (t_infos t).mt_meta
+				| t when meth = "*" -> has_meta ":used" (t_infos t).mt_meta
 				| TClassDecl c -> PMap.exists meth c.cl_statics || PMap.exists meth c.cl_fields
 				| _ -> false)
 			with Not_found ->

+ 10 - 1
dce.ml

@@ -36,6 +36,8 @@ open Type
 
 type dce = {
 	com : context;
+	full : bool;
+	std_dirs : string list;
 	debug : bool;
 	follow_expr : dce -> texpr -> unit;
 	mutable added_fields : (tclass * tclass_field * bool) list;
@@ -51,9 +53,14 @@ let rec super_forces_keep c =
 	| Some (csup,_) -> super_forces_keep csup
 	| _ -> false
 
+let is_std_class dce c =
+	let file = c.cl_module.m_extra.m_file in
+	List.exists (ExtString.String.starts_with file) dce.std_dirs
+
 (* check if a class is kept entirely *)
 let keep_whole_class dce c =
 	has_meta ":keep" c.cl_meta
+	|| not (dce.full || is_std_class dce c)
 	|| super_forces_keep c
 	|| (match c with
 		| { cl_extern = true; cl_path = ([],"Math")} when dce.com.platform = Js -> false
@@ -235,9 +242,11 @@ and expr dce e =
 		expr dce e;
 	| _ -> Type.iter (expr dce) e
 
-let run com main =
+let run com main full =
 	let dce = {
 		com = com;
+		full = full;
+		std_dirs = if full then [] else List.map Common.unique_full_path com.std_path;
 		debug = Common.defined com "dce_debug";
 		added_fields = [];
 		follow_expr = expr;

+ 3 - 3
main.ml

@@ -690,6 +690,7 @@ try
 	let force_typing = ref false in
 	let pre_compilation = ref [] in
 	let interp = ref false in
+	let full_dce = ref false in
 	if version >= 300 then Common.define com "haxe3";
 	for i = 0 to (if version < 300 then 4 else version - 300) do
 		let v = version - i in
@@ -909,7 +910,7 @@ try
 			config_macros := e :: !config_macros
 		)," : call the given macro before typing anything else");
 		("--dead-code-elimination", Arg.Unit (fun () ->
-			Common.define com "dce"
+			full_dce := true
 		)," : remove unused methods");
 		("--wait", Arg.String (fun hp ->
 			let host, port = (try ExtString.String.split hp ":" with _ -> "127.0.0.1", hp) in
@@ -982,7 +983,6 @@ try
 				com.platform <- Flash8;
 				add_std "flash8";
 			end;
-			if !gen_as3 && defined com "dce" then com.defines <- PMap.remove "dce" com.defines;
 			"swf"
 		| Neko ->
 			add_std "neko";
@@ -1044,7 +1044,7 @@ try
 		Codegen.post_process_end();
 		List.iter (fun f -> f()) (List.rev com.filters);
 		List.iter (Codegen.save_class_state tctx) com.types;
-		if Common.defined ctx.com "dce" && not !interp then Dce.run com main;
+		Dce.run com main (!full_dce && not !interp);
 		let type_filters = [
 			Codegen.check_private_path;
 			Codegen.remove_generic_base;

+ 1 - 1
typeload.ml

@@ -1008,7 +1008,7 @@ let init_class ctx c p context_init herits fields =
 		c.cl_extern <- true;
 		List.filter (fun f -> List.mem AStatic f.cff_access) fields, []
 	end else fields, herits in
-	if core_api && not (ctx.com.display || Common.defined ctx.com "dce") then delay ctx PForce (fun() -> init_core_api ctx c);
+	if core_api && not ctx.com.display then delay ctx PForce (fun() -> init_core_api ctx c);
 	let rec extends_public c =
 		List.exists (fun (c,_) -> c.cl_path = (["haxe"],"Public") || extends_public c) c.cl_implements ||
 		match c.cl_super with

+ 0 - 1
typer.ml

@@ -2982,7 +2982,6 @@ let get_macro_context ctx p =
 		com2.class_path <- List.map (fun p -> p ^ "neko" ^ "/_std/") com2.std_path @ com2.class_path;
 		com2.defines <- PMap.foldi (fun k _ acc ->
 			match k with
-			| "dce"
 			| "no_traces" -> acc
 			| _ when List.exists (fun (_,d) -> "flash" ^ d = k) Common.flash_versions -> acc
 			| _ -> PMap.add k () acc