Browse Source

fixed issue #682 with DCE and empty interface

Nicolas Cannasse 13 years ago
parent
commit
3516dc29b6
4 changed files with 3 additions and 41 deletions
  1. 1 1
      genswf9.ml
  2. 0 1
      main.ml
  3. 0 38
      optimizer.ml
  4. 2 1
      typer.ml

+ 1 - 1
genswf9.ml

@@ -2173,7 +2173,7 @@ let generate_type ctx t =
 	match t with
 	| TClassDecl c ->
 		if c.cl_path = (["flash";"_Boot"],"RealBoot") then c.cl_path <- ctx.boot;
-		if c.cl_extern && c.cl_path <> ([],"Dynamic") then
+		if c.cl_extern && (c.cl_path <> ([],"Dynamic") || has_meta ":real" c.cl_meta) then
 			None
 		else
 			let hlc = generate_class ctx c in

+ 0 - 1
main.ml

@@ -735,7 +735,6 @@ try
 		)," : call the given macro before typing anything else");
 		("--dead-code-elimination", Arg.Unit (fun () ->
 			com.dead_code_elimination <- true;
-			Common.add_filter com (fun() -> Optimizer.filter_dead_code com);
 		)," : remove unused methods");
 		("--wait", Arg.String (fun hp ->
 			let host, port = (try ExtString.String.split hp ":" with _ -> "127.0.0.1", hp) in

+ 0 - 38
optimizer.ml

@@ -711,41 +711,3 @@ let rec reduce_loop ctx e =
 
 let reduce_expression ctx e =
 	if ctx.com.foptimize then reduce_loop ctx e else e
-
-(* ---------------------------------------------------------------------- *)
-(* ELIMINATE DEAD CODE *)
-
-(*
-	if dead code elimination is on, any class without fields is eliminated from the output.
-*)
-
-let filter_dead_code com =
-	let filtered = ref (List.fold_left (fun acc t ->
-		match t with
-		| TClassDecl c when c.cl_extern || has_meta ":keep" c.cl_meta ->
-			acc
-		| TClassDecl ({ cl_ordered_statics = []; cl_ordered_fields = []; cl_constructor = None } as c) ->
-			PMap.add c.cl_path () acc
-		| _ ->
-			acc
-	) PMap.empty com.types) in
-	(* make sure used superclasses and interfaces are kept as well *)
-	let rec use_class c =
-		filtered := PMap.remove c.cl_path !filtered;
-		List.iter (fun (i,_) ->
-			filtered := PMap.remove i.cl_path !filtered;
-		) c.cl_implements;
-		match c.cl_super with
-		| None -> ()
-		| Some (csup,_) -> use_class csup
-	in
-	List.iter (fun t ->
-		match t with
-		| TClassDecl c when not (PMap.mem c.cl_path !filtered) -> use_class c
-		| _ -> ()
-	) com.types;
-	com.types <- List.filter (fun t ->
-		match t with
-		| TClassDecl c when PMap.mem c.cl_path !filtered -> false
-		| _ -> true
-	) com.types

+ 2 - 1
typer.ml

@@ -1936,7 +1936,7 @@ and type_call ctx e el p =
 (* DEAD CODE ELIMINATION *)
 
 let dce_check_class ctx c =
-	let keep_whole_class = c.cl_extern || has_meta ":keep" c.cl_meta || (match c.cl_path with ["php"],"Boot" | ["neko"],"Boot" | ["flash"],"Boot" -> true | _ -> false)  in
+	let keep_whole_class = c.cl_extern || c.cl_interface || has_meta ":keep" c.cl_meta || (match c.cl_path with ["php"],"Boot" | ["neko"],"Boot" | ["flash"],"Boot" -> true | _ -> false)  in
 	let keep stat f =
 		keep_whole_class
 		|| has_meta ":?used" f.cf_meta
@@ -1978,6 +1978,7 @@ let dce_finalize ctx =
 let dce_optimize ctx =
 	let check_class c =
 		let keep = dce_check_class ctx c in
+		let keep stat f = if not (keep stat f) then begin if ctx.com.verbose then print_endline ("Removing " ^ s_type_path c.cl_path ^ "." ^ f.cf_name); false; end else true in
 		c.cl_constructor <- (match c.cl_constructor with Some f when not (keep false f) -> None | x -> x);
 		c.cl_ordered_fields <- List.filter (keep false) c.cl_ordered_fields;
 		c.cl_ordered_statics <- List.filter (keep true) c.cl_ordered_statics;