From ffbeab187183167f4e6c7892e32d579f780e1fd1 Mon Sep 17 00:00:00 2001 From: vbot Date: Thu, 10 Oct 2024 16:48:08 +0200 Subject: [PATCH] Explain plugin: make the module usage inlining optional --- compiler/plugins/explain.ml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/compiler/plugins/explain.ml b/compiler/plugins/explain.ml index 1b0fe4fa..e220b2e7 100644 --- a/compiler/plugins/explain.ml +++ b/compiler/plugins/explain.ml @@ -26,6 +26,7 @@ type flags = { output : Global.raw_file option; base_src_url : string; line_format : string; + inline_module_usages : bool; } (* -- Definition of the lazy interpreter -- *) @@ -1487,6 +1488,13 @@ let options = of characters 'NN' will be expanded using the actual positions. \ The default value '#LNN' matches github-like positions") in + let inline_module_usages = + Arg.( + value + & flag + & info ["inline-mod-uses"] + ~doc:"Attempts to inline existing module usages using a heuristic.") + in let f with_conditions no_cleanup @@ -1495,7 +1503,8 @@ let options = show output base_src_url - line_format = + line_format + inline_module_usages = { with_conditions; with_cleanup = not no_cleanup; @@ -1505,6 +1514,7 @@ let options = output; base_src_url; line_format; + inline_module_usages; } in Term.( @@ -1516,7 +1526,8 @@ let options = $ show $ Cli.Flags.output $ base_src_url - $ line_format) + $ line_format + $ inline_module_usages) let inline_used_modules global_options = let prg = @@ -1604,7 +1615,10 @@ let run ex_scope explain_options global_options = - let () = inline_used_modules global_options in + let () = + if explain_options.inline_module_usages then + inline_used_modules global_options + in let prg, _ = Driver.Passes.dcalc global_options ~includes ~optimize ~check_invariants:false ~autotest:false ~typed:Expr.typed