Simon Krajewski пре 5 месеци
родитељ
комит
f805e072a5

+ 3 - 2
src/filters/addFieldInits.ml

@@ -47,9 +47,10 @@ let add_field_inits cl_path locals com t =
 				| _ ->
 					die "" __LOC__
 			in
-			let config = AnalyzerConfig.get_field_config com c cf in
+			let scom = Common.to_safe_com com in
+			let config = AnalyzerConfig.get_field_config scom c cf in
 			remove_class_field_flag cf CfPostProcessed;
-			Analyzer.Run.run_on_field com config c cf;
+			Analyzer.Run.run_on_field scom config c cf;
 			add_class_field_flag cf CfPostProcessed;
 			(match cf.cf_expr with
 			| Some e ->

+ 11 - 14
src/optimization/analyzer.ml

@@ -20,6 +20,7 @@
 open StringHelper
 open Ast
 open Type
+open SafeCom
 open AnalyzerTexpr
 open AnalyzerTypes
 open OptimizerTexpr
@@ -974,16 +975,10 @@ module Run = struct
 		let id = Timer.determine_id level ["analyzer"] s identifier in
 		Timer.time timer_ctx id f ()
 
-	let create_analyzer_context (com : Common.context) config identifier e =
+	let create_analyzer_context (com : SafeCom.t) config identifier e =
 		let g = Graph.create e.etype e.epos in
 		let ctx = {
-			com = {
-				basic = com.basic;
-				platform = com.platform;
-				platform_config = com.config;
-				defines = com.defines;
-				debug = com.debug;
-			};
+			com = com;
 			config = config;
 			graph = g;
 			(* For CPP we want to use variable names which are "probably" not used by users in order to
@@ -1113,7 +1108,7 @@ module Run = struct
 		Optimizer.reduce_control_flow com e
 
 	let run_on_field' com exc_out config c cf = match cf.cf_expr with
-		| Some e when not (is_ignored cf.cf_meta) && not (FilterContext.is_removable_field com.Common.is_macro_context cf) && not (has_class_field_flag cf CfPostProcessed) ->
+		| Some e when not (is_ignored cf.cf_meta) && not (FilterContext.is_removable_field com.is_macro_context cf) && not (has_class_field_flag cf CfPostProcessed) ->
 			let config = update_config_from_meta com config cf.cf_meta in
 			let actx = create_analyzer_context com config (Printf.sprintf "%s.%s" (s_type_path c.cl_path) cf.cf_name) e in
 			let debug() =
@@ -1133,7 +1128,7 @@ module Run = struct
 			in
 			begin try
 				let e = run_on_expr actx e in
-				let e = reduce_control_flow com e in
+				let e = reduce_control_flow com.platform e in
 				maybe_debug();
 				cf.cf_expr <- Some e;
 			with
@@ -1196,21 +1191,23 @@ module Run = struct
 		| TAbstractDecl _ -> ()
 
 	let run_on_types com pool types =
-		let config = get_base_config com in
+		let scom = Common.to_safe_com com in
+		let config = get_base_config scom in
 		with_timer com.timer_ctx config.detail_times None ["other"] (fun () ->
 			if config.optimize && config.purity_inference then
 				with_timer com.timer_ctx config.detail_times None ["optimize";"purity-inference"] (fun () -> Purity.infer com);
 			let exc_out = Atomic.make None in
-			Parallel.ParallelArray.iter pool (run_on_type com exc_out pool config) (Array.of_list types);
+			Parallel.ParallelArray.iter pool (run_on_type scom exc_out pool config) (Array.of_list types);
 			check_exc_out exc_out
 		)
 end
 ;;
 Typecore.analyzer_run_on_expr_ref := (fun com identifier e ->
-	let config = AnalyzerConfig.get_base_config com in
+	let scom = Common.to_safe_com com in
+	let config = AnalyzerConfig.get_base_config scom in
 	(* We always want to optimize because const propagation might be required to obtain
 	   a constant expression for inline field initializations (see issue #4977). *)
 	let config = {config with AnalyzerConfig.optimize = true} in
-	let actx = Run.create_analyzer_context com config identifier e in
+	let actx = Run.create_analyzer_context scom config identifier e in
 	Run.run_on_expr actx e
 )

+ 10 - 12
src/optimization/analyzerConfig.ml

@@ -19,7 +19,7 @@
 
 open Ast
 open Type
-open Common
+open SafeCom
 open Globals
 
 type debug_kind =
@@ -64,15 +64,15 @@ let is_ignored meta =
 
 let get_base_config com =
 	{
-		optimize = Common.defined com Define.AnalyzerOptimize;
-		const_propagation = not (Common.raw_defined com "analyzer_no_const_propagation");
-		copy_propagation = not (Common.raw_defined com "analyzer_no_copy_propagation");
-		local_dce = not (Common.raw_defined com "analyzer_no_local_dce");
-		fusion = not (Common.raw_defined com "analyzer_no_fusion");
-		purity_inference = not (Common.raw_defined com "analyzer_no_purity_inference");
+		optimize = Define.defined com.defines Define.AnalyzerOptimize;
+		const_propagation = not (Define.raw_defined com.defines "analyzer_no_const_propagation");
+		copy_propagation = not (Define.raw_defined com.defines "analyzer_no_copy_propagation");
+		local_dce = not (Define.raw_defined com.defines "analyzer_no_local_dce");
+		fusion = not (Define.raw_defined com.defines "analyzer_no_fusion");
+		purity_inference = not (Define.raw_defined com.defines "analyzer_no_purity_inference");
 		debug_kind = DebugNone;
 		detail_times = Timer.level_from_define com.defines Define.AnalyzerTimes;
-		user_var_fusion = (match com.platform with Flash | Jvm -> false | _ -> true) && (Common.raw_defined com "analyzer_user_var_fusion" || (not com.debug && not (Common.raw_defined com "analyzer_no_user_var_fusion")));
+		user_var_fusion = (match com.platform with Flash | Jvm -> false | _ -> true) && (Define.raw_defined com.defines "analyzer_user_var_fusion" || (not com.debug && not (Define.raw_defined com.defines "analyzer_no_user_var_fusion")));
 		fusion_debug = false;
 	}
 
@@ -99,14 +99,12 @@ let update_config_from_meta com config ml =
 						| "fusion_debug" -> { config with fusion_debug = true }
 						| "as_var" -> config
 						| _ ->
-							let options = Warning.from_meta ml in
-							com.warning WOptimizer options (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);
+							SafeCom.add_warning com WOptimizer (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);
 							config
 					end
 				| _ ->
 					let s = Ast.Printer.s_expr e in
-					let options = Warning.from_meta ml in
-					com.warning WOptimizer options (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);
+					SafeCom.add_warning com WOptimizer (StringError.string_error s all_flags ("Unrecognized analyzer option: " ^ s)) (pos e);
 					config
 			) config el
 		| (Meta.HasUntyped,_,_) ->

+ 2 - 2
src/optimization/analyzerTexpr.ml

@@ -19,7 +19,7 @@
 
 open Ast
 open Type
-open Common
+open SafeCom
 open AnalyzerTypes
 open OptimizerTexpr
 open Globals
@@ -1252,7 +1252,7 @@ module Purity = struct
 					] impure.pn_field.cf_pos)
 				end
 			| _ -> ()
-		) com.types;
+		) com.Common.types;
 		Hashtbl.iter (fun _ node ->
 			match node.pn_purity with
 			| Pure | MaybePure when not (List.exists (fun (m,_,_) -> m = Meta.Pure) node.pn_field.cf_meta) ->

+ 1 - 9
src/optimization/analyzerTypes.ml

@@ -597,16 +597,8 @@ module Graph = struct
 		Hashtbl.iter (fun _ (bb,_,_,_) -> loop [0] bb) g.g_functions
 end
 
-type light_com = {
-	basic : basic_types;
-	platform : platform;
-	defines : Define.define;
-	platform_config : PlatformConfig.platform_config;
-	debug : bool;
-}
-
 type analyzer_context = {
-	com : light_com;
+	com : SafeCom.t;
 	config : AnalyzerConfig.t;
 	graph : Graph.t;
 	temp_var_name : string;

+ 3 - 3
src/optimization/optimizer.ml

@@ -96,7 +96,7 @@ in
 			else
 				None
 
-let reduce_control_flow com e = match e.eexpr with
+let reduce_control_flow platform e = match e.eexpr with
 	| TIf ({ eexpr = TConst (TBool t) },e1,e2) ->
 		(if t then e1 else match e2 with None -> { e with eexpr = TBlock [] } | Some e -> e)
 	| TWhile ({ eexpr = TConst (TBool false) },sub,flag) ->
@@ -121,7 +121,7 @@ let reduce_control_flow com e = match e.eexpr with
 		(try List.nth el i with Failure _ -> e)
 	| TCast(e1,None) ->
 		(* TODO: figure out what's wrong with these targets *)
-		let require_cast = match com.platform with
+		let require_cast = match platform with
 			| Cpp | Flash -> true
 			| Jvm -> true
 			| _ -> false
@@ -168,7 +168,7 @@ let rec reduce_loop ctx stack e =
 				reduce_expr ctx e
 		end
 	| _ ->
-		reduce_expr ctx (reduce_control_flow ctx.com e))
+		reduce_expr ctx (reduce_control_flow ctx.com.platform e))
 
 let reduce_expression ctx e =
 	if ctx.com.foptimize then begin