소스 검색

move scom stuff to scom

Simon Krajewski 5 달 전
부모
커밋
4be9adf4f0
5개의 변경된 파일47개의 추가작업 그리고 49개의 파일을 삭제
  1. 0 17
      src/context/common.ml
  2. 38 0
      src/context/safeCom.ml
  3. 4 22
      src/filters/filters.ml
  4. 2 2
      src/optimization/analyzer.ml
  5. 3 8
      src/typing/macroContext.ml

+ 0 - 17
src/context/common.ml

@@ -334,23 +334,6 @@ let to_gctx com = {
 	std = com.std;
 	timer_ctx = com.timer_ctx;
 }
-
-let to_safe_com com = {
-	SafeCom.basic = com.basic;
-	platform = com.platform;
-	defines = com.defines;
-	platform_config = com.config;
-	debug = com.debug;
-	is_macro_context = com.is_macro_context;
-	exceptions = ref [];
-	exceptions_mutex = Mutex.create ();
-	warnings = ref [];
-	warnings_mutex = Mutex.create ();
-	timer_ctx = com.timer_ctx;
-	curclass = null_class;
-	curfield = null_field;
-}
-
 let enter_stage com stage =
 	(* print_endline (Printf.sprintf "Entering stage %s" (s_compiler_stage stage)); *)
 	com.stage <- stage

+ 38 - 0
src/context/safeCom.ml

@@ -26,6 +26,44 @@ type t = {
 	curfield : tclass_field;
 }
 
+let of_com (com : Common.context) = {
+	basic = com.basic;
+	platform = com.platform;
+	defines = com.defines;
+	platform_config = com.config;
+	debug = com.debug;
+	is_macro_context = com.is_macro_context;
+	exceptions = ref [];
+	exceptions_mutex = Mutex.create ();
+	warnings = ref [];
+	warnings_mutex = Mutex.create ();
+	timer_ctx = com.timer_ctx;
+	curclass = null_class;
+	curfield = null_field;
+}
+
+let of_typer (ctx : Typecore.typer) = {
+	(of_com ctx.com) with
+	curclass = ctx.c.curclass;
+	curfield = ctx.f.curfield;
+}
+
+let finalize scom com =
+	List.iter (fun warning ->
+		Common.module_warning com warning.w_module warning.w_warning warning.w_options warning.w_msg warning.w_pos
+	) !(scom.warnings);
+	scom.warnings := [];
+	let exns = !(scom.exceptions) in
+	scom.exceptions := [];
+	match exns with
+	| x :: _ ->
+		raise x
+	| [] ->
+		()
+
+let run_with_scom com scom pool f =
+	Std.finally (fun() -> finalize scom com) f ()
+
 let add_exn scom exn =
 	Mutex.protect scom.exceptions_mutex (fun () -> scom.exceptions := exn :: !(scom.exceptions))
 

+ 4 - 22
src/filters/filters.ml

@@ -387,24 +387,6 @@ let might_need_cf_unoptimized c cf =
 	| _ ->
 		has_class_field_flag cf CfGeneric
 
-let check_scom com scom =
-	let open SafeCom in
-	List.iter (fun warning ->
-		module_warning com warning.w_module warning.w_warning warning.w_options warning.w_msg warning.w_pos
-	) !(scom.warnings);
-	scom.warnings := [];
-	let exns = !(scom.exceptions) in
-	scom.exceptions := [];
-	match exns with
-	| x :: _ ->
-		raise x
-	| [] ->
-		()
-
-let run_parallel_safe com scom pool f =
-	f ();
-	check_scom com scom
-
 let run tctx ectx main before_destruction =
 	let com = tctx.com in
 	let detail_times = Timer.level_from_define com.defines Define.FilterTimes in
@@ -435,7 +417,7 @@ let run tctx ectx main before_destruction =
 		not cached
 	) com.types in
 	let new_types_array = Array.of_list new_types in
-	let scom = to_safe_com com in
+	let scom = SafeCom.of_com com in
 	(* IMPORTANT:
 	    There may be types in new_types which have already been post-processed, but then had their m_processed flag unset
 		because they received an additional dependency. This could happen in cases such as @:generic methods in #10635.
@@ -460,7 +442,7 @@ let run tctx ectx main before_destruction =
 		"Tre",if defined com Define.AnalyzerOptimize then Tre.run else (fun _ e -> e);
 	] in
 	Parallel.run_in_new_pool com.timer_ctx (fun pool ->
-		run_parallel_safe com scom pool (fun () ->
+		SafeCom.run_with_scom com scom pool (fun () ->
 			Parallel.ParallelArray.iter pool (SafeCom.run_expression_filters_safe scom detail_times filters) new_types_array
 		);
 	);
@@ -478,7 +460,7 @@ let run tctx ectx main before_destruction =
 	] in
 
 	let locals = Parallel.run_in_new_pool com.timer_ctx (fun pool ->
-		run_parallel_safe com scom pool (fun () ->
+		SafeCom.run_with_scom com scom pool (fun () ->
 			Parallel.ParallelArray.iter pool (SafeCom.run_expression_filters_safe scom detail_times filters) new_types_array
 		);
 		enter_stage com CAnalyzerStart;
@@ -495,7 +477,7 @@ let run tctx ectx main before_destruction =
 			);
 			"mark_switch_break_loops",SafeFilters.mark_switch_break_loops;
 		] in
-		run_parallel_safe com scom pool (fun () ->
+		SafeCom.run_with_scom com scom pool (fun () ->
 			Parallel.ParallelArray.iter pool (SafeCom.run_expression_filters_safe scom detail_times filters) new_types_array
 		);
 		locals

+ 2 - 2
src/optimization/analyzer.ml

@@ -1191,7 +1191,7 @@ module Run = struct
 		| TAbstractDecl _ -> ()
 
 	let run_on_types com pool types =
-		let scom = Common.to_safe_com com in
+		let scom = SafeCom.of_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
@@ -1203,7 +1203,7 @@ module Run = struct
 end
 ;;
 Typecore.analyzer_run_on_expr_ref := (fun com identifier e ->
-	let scom = Common.to_safe_com com in
+	let scom = SafeCom.of_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). *)

+ 3 - 8
src/typing/macroContext.ml

@@ -645,22 +645,17 @@ and flush_macro_context mint mctx =
 			in
 			if apply_native then Native.apply_native_paths t
 		in
-		let scom_from_tctx tctx =
-			let scom = to_safe_com mctx.com in
-			let scom = {scom with curclass = tctx.c.curclass; curfield = tctx.f.curfield} in (* This isn't great *)
-			scom
-		in
-		let scom = scom_from_tctx mctx in
+		let scom = SafeCom.of_com mctx.com in
 		let cv_wrapper_impl = CapturedVars.get_wrapper_implementation mctx.com in
 		let expr_filters = [
 			"handle_abstract_casts",AbstractCast.handle_abstract_casts;
 			"local_statics",(fun tctx ->
-				let scom = scom_from_tctx tctx in
+				let scom = SafeCom.of_typer tctx in
 				LocalStatic.run scom
 			);
 			"Exceptions",(fun _ -> Exceptions.filter ectx);
 			"captured_vars",(fun tctx ->
-				let scom = scom_from_tctx tctx in
+				let scom = SafeCom.of_typer tctx in
 				CapturedVars.captured_vars scom cv_wrapper_impl
 			);
 		] in