diff --git a/src-json/define.json b/src-json/define.json index 48d0df31cce..170464eefdc 100644 --- a/src-json/define.json +++ b/src-json/define.json @@ -188,6 +188,12 @@ "doc": "Output filename extension for cpp source code.", "platforms": ["cpp"] }, + { + "name": "FilterDebug", + "define": "filter-debug", + "doc": "Prints post-processing debug information.", + "links": ["https://haxe.org/manual/cr-dce.html"] + }, { "name": "FlashStrict", "define": "flash-strict", diff --git a/src/filters/filterContext.ml b/src/filters/filterContext.ml index 3c7624b347b..3c1cb4aad79 100644 --- a/src/filters/filterContext.ml +++ b/src/filters/filterContext.ml @@ -1,9 +1,10 @@ -let with_timer detail_times label identifier f = +let with_timer detail_times debug label identifier f = let label = match detail_times,identifier with | 0,_ -> ["filters"] | 1,_ -> "filters" :: label :: [] | _,Some identifier -> "filters" :: label :: identifier :: [] | _ -> ["filters"] in + if debug then print_endline (Printf.sprintf "Running filter: %s" (String.concat "." label)); let timer = Timer.timer label in Std.finally timer f () \ No newline at end of file diff --git a/src/filters/filters.ml b/src/filters/filters.ml index b8efae167a4..6805b3d0ab6 100644 --- a/src/filters/filters.ml +++ b/src/filters/filters.ml @@ -457,9 +457,9 @@ end open FilterContext -let destruction tctx detail_times main locals = +let destruction tctx detail_times debug main locals = let com = tctx.com in - with_timer detail_times "type 2" None (fun () -> + with_timer detail_times debug "type 2" None (fun () -> (* PASS 2: type filters pre-DCE *) List.iter (fun t -> FiltersCommon.remove_generic_base t; @@ -470,7 +470,7 @@ let destruction tctx detail_times main locals = ) com.types; ); enter_stage com CDceStart; - with_timer detail_times "dce" None (fun () -> + with_timer detail_times debug "dce" None (fun () -> (* DCE *) let dce_mode = try Common.defined_value com Define.Dce with _ -> "no" in let dce_mode = match dce_mode with @@ -488,6 +488,7 @@ let destruction tctx detail_times main locals = ~ignore_processed_status:true tctx detail_times + debug (* This has to run after DCE, or otherwise its condition always holds. *) ["insert_save_stacks",Exceptions.insert_save_stacks tctx] ) @@ -504,7 +505,7 @@ let destruction tctx detail_times main locals = commit_features com; (if com.config.pf_reserved_type_paths <> [] then check_reserved_type_paths com else (fun _ -> ())); ] in - with_timer detail_times "type 3" None (fun () -> + with_timer detail_times debug "type 3" None (fun () -> List.iter (fun t -> begin match t with | TClassDecl c -> @@ -666,6 +667,7 @@ let might_need_cf_unoptimized c cf = let run tctx main before_destruction = let com = tctx.com in + let debug = Define.defined com.defines Define.FilterDebug in let detail_times = (try int_of_string (Common.defined_value_safe com ~default:"0" Define.FilterTimes) with _ -> 0) in let new_types = List.filter (fun t -> let cached = is_cached com t in @@ -708,7 +710,7 @@ let run tctx main before_destruction = "ForRemap",ForRemap.apply tctx; "handle_abstract_casts",AbstractCast.handle_abstract_casts tctx; ] in - List.iter (run_expression_filters tctx detail_times filters) new_types; + List.iter (run_expression_filters tctx detail_times debug filters) new_types; let filters = [ "local_statics",LocalStatic.run tctx; "fix_return_dynamic_from_void_function",fix_return_dynamic_from_void_function true; @@ -720,7 +722,7 @@ let run tctx main before_destruction = "Exceptions_filter",Exceptions.filter tctx; "captured_vars",CapturedVars.captured_vars com; ] in - List.iter (run_expression_filters tctx detail_times filters) new_types; + List.iter (run_expression_filters tctx detail_times debug filters) new_types; (* PASS 1.5: pre-analyzer type filters *) let filters = match com.platform with @@ -731,7 +733,7 @@ let run tctx main before_destruction = | _ -> [] in - with_timer detail_times "type 1" None (fun () -> + with_timer detail_times debug "type 1" None (fun () -> List.iter (fun f -> List.iter f new_types) filters; ); enter_stage com CAnalyzerStart; @@ -747,20 +749,20 @@ let run tctx main before_destruction = | _ -> (fun e -> RenameVars.run tctx.c.curclass.cl_path locals e)); "mark_switch_break_loops",mark_switch_break_loops; ] in - List.iter (run_expression_filters tctx detail_times filters) new_types; - with_timer detail_times "callbacks" None (fun () -> + List.iter (run_expression_filters tctx detail_times debug filters) new_types; + with_timer detail_times debug "callbacks" None (fun () -> com.callbacks#run com.error_ext com.callbacks#get_before_save; ); enter_stage com CSaveStart; - with_timer detail_times "save state" None (fun () -> + with_timer detail_times debug "save state" None (fun () -> List.iter (fun mt -> update_cache_dependencies ~close_monomorphs:true com mt; save_class_state com mt ) new_types; ); enter_stage com CSaveDone; - with_timer detail_times "callbacks" None (fun () -> + with_timer detail_times debug "callbacks" None (fun () -> com.callbacks#run com.error_ext com.callbacks#get_after_save; ); before_destruction(); - destruction tctx detail_times main locals + destruction tctx detail_times debug main locals diff --git a/src/filters/filtersCommon.ml b/src/filters/filtersCommon.ml index 7468f4425fc..a0a75576b69 100644 --- a/src/filters/filtersCommon.ml +++ b/src/filters/filtersCommon.ml @@ -53,11 +53,11 @@ let is_overridden cls field = in List.exists (fun d -> loop_inheritance d) cls.cl_descendants -let run_expression_filters ?(ignore_processed_status=false) ctx detail_times filters t = +let run_expression_filters ?(ignore_processed_status=false) ctx detail_times debug filters t = let com = ctx.com in let run identifier e = List.fold_left (fun e (filter_name,f) -> - FilterContext.with_timer detail_times filter_name identifier (fun () -> f e) + FilterContext.with_timer detail_times debug (* TODO spammy *) filter_name identifier (fun () -> f e) ) e filters in match t with @@ -96,4 +96,5 @@ let is_cached com t = let apply_filters_once ctx filters t = let detail_times = (try int_of_string (Common.defined_value_safe ctx.com ~default:"0" Define.FilterTimes) with _ -> 0) in - if not (is_cached ctx.com t) then run_expression_filters ctx detail_times filters t \ No newline at end of file + let debug = Define.defined ctx.com.defines Define.FilterDebug in + if not (is_cached ctx.com t) then run_expression_filters ctx detail_times debug filters t \ No newline at end of file