Browse Source

store reverse features in m_extra so it can be cached (closes #2159)

Simon Krajewski 12 years ago
parent
commit
cd900ae2e7
4 changed files with 21 additions and 19 deletions
  1. 1 3
      common.ml
  2. 16 12
      dce.ml
  3. 3 1
      type.ml
  4. 1 3
      typeload.ml

+ 1 - 3
common.ml

@@ -127,7 +127,6 @@ type context = {
 	mutable file : string;
 	mutable flash_version : float;
 	mutable features : (string,bool) Hashtbl.t;
-	mutable reverse_features : (string,(tclass * tclass_field * bool) list) Hashtbl.t;
 	mutable modules : Type.module_def list;
 	mutable main : Type.texpr option;
 	mutable types : Type.module_type list;
@@ -610,7 +609,6 @@ let create v args =
 		verbose = false;
 		foptimize = true;
 		features = Hashtbl.create 0;
-		reverse_features = Hashtbl.create 0;
 		platform = Cross;
 		config = default_config;
 		print = (fun s -> print_string s; flush stdout);
@@ -655,7 +653,7 @@ let log com str =
 
 let clone com =
 	let t = com.basic in
-	{ com with basic = { t with tvoid = t.tvoid }; main_class = None; features = Hashtbl.create 0; reverse_features = Hashtbl.create 0; }
+	{ com with basic = { t with tvoid = t.tvoid }; main_class = None; features = Hashtbl.create 0; }
 
 let file_time file =
 	try (Unix.stat file).Unix.st_mtime with _ -> 0.

+ 16 - 12
dce.ml

@@ -35,7 +35,7 @@ type dce = {
 	mutable marked_maybe_fields : tclass_field list;
 	mutable t_stack : t list;
 	mutable ts_stack : t list;
-	mutable checked_features : (string,bool) Hashtbl.t;
+	mutable features : (string,(tclass * tclass_field * bool) list) Hashtbl.t;
 }
 
 (* checking *)
@@ -71,16 +71,14 @@ let keep_field dce cf =
 (* marking *)
 
 let rec check_feature dce s =
-	if not (Hashtbl.mem dce.checked_features s) then begin
-		add_feature dce.com s;
-		Hashtbl.add dce.checked_features s true;
-		try
-			List.iter (fun (c,cf,stat) ->
-				mark_field dce c cf stat
-			) (Hashtbl.find dce.com.reverse_features s)
-		with Not_found ->
-			()
-	end
+	try
+		let l = Hashtbl.find dce.features s in
+		List.iter (fun (c,cf,stat) ->
+			mark_field dce c cf stat
+		) l;
+		Hashtbl.remove dce.features s;
+	with Not_found ->
+		()
 
 (* mark a field as kept *)
 and mark_field dce c cf stat =
@@ -368,7 +366,7 @@ let run com main full =
 		marked_maybe_fields = [];
 		t_stack = [];
 		ts_stack = [];
-		checked_features = Hashtbl.create 0;
+		features = Hashtbl.create 0;
 	} in
 	begin match main with
 		| Some {eexpr = TCall({eexpr = TField(e,(FStatic(c,cf)))},_)} ->
@@ -376,6 +374,12 @@ let run com main full =
 		| _ ->
 			()
 	end;
+	List.iter (fun m ->
+		List.iter (fun (s,v) ->
+			if Hashtbl.mem dce.features s then Hashtbl.replace dce.features s (v :: Hashtbl.find dce.features s)
+			else Hashtbl.add dce.features s [v]
+		) m.m_extra.m_features;
+	) com.modules;
 	(* first step: get all entry points, which is the main method and all class methods which are marked with @:keep *)
 	List.iter (fun t -> match t with
 		| TClassDecl c ->

+ 3 - 1
type.ml

@@ -285,6 +285,7 @@ and module_def_extra = {
 	mutable m_kind : module_kind;
 	mutable m_binded_res : (string, string) PMap.t;
 	mutable m_macro_calls : string list;
+	mutable m_features : (string *(tclass * tclass_field * bool)) list;
 }
 
 and module_kind =
@@ -382,6 +383,7 @@ let module_extra file sign time kind =
 		m_kind = kind;
 		m_binded_res = PMap.empty;
 		m_macro_calls = [];
+		m_features = [];
 	}
 
 
@@ -1159,7 +1161,7 @@ let rec unify a b =
 	| TEnum(en,_), TAbstract ({ a_path = ["haxe"],"FlatEnum" },[]) when Meta.has Meta.FlatEnum en.e_meta ->
 		()
 	| TFun _, TAbstract ({ a_path = ["haxe"],"Function" },[]) ->
-		()		
+		()
 	| TDynamic t , _ ->
 		if t == a then
 			()

+ 1 - 3
typeload.ml

@@ -1884,9 +1884,7 @@ let init_class ctx c p context_init herits fields =
 				let _,args,_ = Meta.get Meta.IfFeature f.cf_meta in
 				List.iter (fun e -> match fst e with
 					| EConst(String s) ->
-						let fl,v = ctx.com.reverse_features,(c,f,is_static) in
-						if Hashtbl.mem fl s then Hashtbl.replace fl s (v :: Hashtbl.find fl s)
-						else Hashtbl.add fl s [v]
+						ctx.m.curmod.m_extra.m_features <- (s,(c,f,is_static)) :: ctx.m.curmod.m_extra.m_features;
 					| _ ->
 						error "String expected" (pos e)
 				) args