Skip to content

Commit

Permalink
add -D filter-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Oct 10, 2024
1 parent 39aceb1 commit dc40224
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src-json/define.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/filters/filterContext.ml
Original file line number Diff line number Diff line change
@@ -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 ()
26 changes: 14 additions & 12 deletions src/filters/filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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]
)
Expand All @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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
7 changes: 4 additions & 3 deletions src/filters/filtersCommon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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

0 comments on commit dc40224

Please sign in to comment.