소스 검색

make sure filters are only run once

Nicolas Cannasse 10 년 전
부모
커밋
493e93d085
2개의 변경된 파일34개의 추가작업 그리고 47개의 파일을 삭제
  1. 32 45
      filters.ml
  2. 2 2
      typer.ml

+ 32 - 45
filters.ml

@@ -989,29 +989,29 @@ let run_expression_filters ctx filters t =
 
 let pp_counter = ref 1
 
-let post_process ctx filters t =
-	(* ensure that we don't process twice the same (cached) module *)
+let is_cached t =
 	let m = (t_infos t).mt_module.m_extra in
 	if m.m_processed = 0 then m.m_processed <- !pp_counter;
-	if m.m_processed = !pp_counter then
-	run_expression_filters ctx filters t
+	m.m_processed <> !pp_counter
 
-let post_process_end() =
+let apply_filters_once ctx filters t =
+	if not (is_cached t) then run_expression_filters ctx filters t
+
+let next_compilation() =
 	incr pp_counter
 
-let iter_expressions com fl =
-	List.iter (fun mt -> match mt with
-		| TClassDecl c ->
-			let field cf = match cf.cf_expr with
-				| None -> ()
-				| Some e -> List.iter (fun f -> f e) fl
-			in
-			List.iter field c.cl_ordered_statics;
-			List.iter field c.cl_ordered_fields;
-			(match c.cl_constructor with None -> () | Some cf -> field cf)
-		| _ ->
-			()
-	) com.types
+let iter_expressions fl mt =
+	match mt with
+	| TClassDecl c ->
+		let field cf = match cf.cf_expr with
+			| None -> ()
+			| Some e -> List.iter (fun f -> f e) fl
+		in
+		List.iter field c.cl_ordered_statics;
+		List.iter field c.cl_ordered_fields;
+		(match c.cl_constructor with None -> () | Some cf -> field cf)
+	| _ ->
+		()
 
 let run com tctx main =
 	begin match com.display with
@@ -1024,6 +1024,7 @@ let run com tctx main =
 		Codegen.DeprecationCheck.run com;
 	let use_static_analyzer = Common.defined com Define.Analyzer in
 	(* this part will be a bit messy until we make the analyzer the default *)
+	let new_types = List.filter (fun t -> not (is_cached t)) com.types in
 	if use_static_analyzer then begin
 		(* PASS 1: general expression filters *)
 		let filters = [
@@ -1034,24 +1035,15 @@ let run com tctx main =
 			blockify_ast;
 			captured_vars com;
 		] in
-		List.iter (post_process tctx filters) com.types;
-		Analyzer.apply tctx;
-		post_process_end();
-		iter_expressions com [verify_ast];
-		List.iter (fun f -> f()) (List.rev com.filters);
-		(* save class state *)
-		List.iter (save_class_state tctx) com.types;
-		(* PASS 2: destructive type and expression filters *)
+		List.iter (run_expression_filters tctx filters) new_types;
+		Analyzer.apply tctx; (* TODO *)
+		List.iter (iter_expressions [verify_ast]) new_types;
 		let filters = [
 			Optimizer.sanitize com;
 			if com.config.pf_add_final_return then add_final_return else (fun e -> e);
 			rename_local_vars tctx;
 		] in
-		List.iter (fun t ->
-			remove_generic_base tctx t;
-			remove_extern_fields tctx t;
-			run_expression_filters tctx filters t;
-		) com.types;
+		List.iter (run_expression_filters tctx filters) new_types;
 	end else begin
 		(* PASS 1: general expression filters *)
 		let filters = [
@@ -1070,25 +1062,20 @@ let run com tctx main =
 			if com.foptimize then (fun e -> Optimizer.reduce_expression tctx (Optimizer.inline_constructors tctx e)) else Optimizer.sanitize com;
 			check_local_vars_init;
 			captured_vars com;
-		] in
-		List.iter (post_process tctx filters) com.types;
-		post_process_end();
-		iter_expressions com [verify_ast];
-		List.iter (fun f -> f()) (List.rev com.filters);
-		(* save class state *)
-		List.iter (save_class_state tctx) com.types;
-		(* PASS 2: destructive type and expression filters *)
-		let filters = [
 			promote_complex_rhs com;
 			if com.config.pf_add_final_return then add_final_return else (fun e -> e);
 			rename_local_vars tctx;
 		] in
-		List.iter (fun t ->
-			remove_generic_base tctx t;
-			remove_extern_fields tctx t;
-			run_expression_filters tctx filters t;
-		) com.types;
+		List.iter (run_expression_filters tctx filters) new_types;
+		List.iter (iter_expressions [verify_ast]) new_types;
 	end;
+	next_compilation();
+	List.iter (fun f -> f()) (List.rev com.filters); (* macros onGenerate etc. *)
+	List.iter (save_class_state tctx) new_types;
+	List.iter (fun t ->
+		remove_generic_base tctx t;
+		remove_extern_fields tctx t;
+	) com.types;
 	(* update cache dependencies before DCE is run *)
 	Codegen.update_cache_dependencies com;
 	(* check @:remove metadata before DCE so it is ignored there (issue #2923) *)

+ 2 - 2
typer.ml

@@ -4490,12 +4490,12 @@ and flush_macro_context mint ctx =
 	let expr_filters = [Codegen.AbstractCast.handle_abstract_casts mctx; Filters.captured_vars mctx.com; Filters.rename_local_vars mctx] in
 	let type_filters = [Filters.add_field_inits mctx] in
 	let ready = fun t ->
-		Filters.post_process mctx expr_filters t;
+		Filters.apply_filters_once mctx expr_filters t;
 		List.iter (fun f -> f t) type_filters
 	in
 	(try Interp.add_types mint types ready
 	with Error (e,p) -> raise (Fatal_error(error_msg e,p)));
-	Filters.post_process_end()
+	Filters.next_compilation()
 
 let create_macro_interp ctx mctx =
 	let com2 = mctx.com in