فهرست منبع

fixed DCE removing used superclass/interfaces (fixed issue #424)

Nicolas Cannasse 13 سال پیش
والد
کامیت
e761d2ad9f
2فایلهای تغییر یافته به همراه28 افزوده شده و 13 حذف شده
  1. 2 0
      doc/CHANGES.txt
  2. 26 13
      optimizer.ml

+ 2 - 0
doc/CHANGES.txt

@@ -23,6 +23,8 @@
 	all : added Reflect.getProperty/setProperty 
 		(partial support : neko, js only so far)
 	all : added --cache, --wait and --cwd
+	all : fixed completion in macros calls arguments
+	all : fixed DCE removing empty but still used interfaces/superclasses
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 26 - 13
optimizer.ml

@@ -715,19 +715,32 @@ let reduce_expression ctx e =
 *)
 
 let filter_dead_code com =
-	let s_class c = s_type_path c.cl_path in
-	com.types <- List.filter (fun t ->
+	let filtered = ref (List.fold_left (fun acc t ->
 		match t with
-		| TClassDecl c ->
-			if (c.cl_extern or has_meta ":keep" c.cl_meta) then
-				true
-			else (
-				match (c.cl_ordered_statics, c.cl_ordered_fields, c.cl_constructor) with
-				| ([], [], None) ->
-					if com.verbose then print_endline ("Remove class " ^ s_class c);
-					false
-				| _ ->
-					true)
+		| 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
 		| _ ->
-			true
+			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