Introduce -Zmacro-stats.

It collects data about macro expansions and prints them in a table after
expansion finishes. It's very useful for detecting macro bloat,
especially for proc macros.

Details:
- It measures code snippets by pretty-printing them and then measuring
  lines and bytes. This required a bunch of additional pretty-printing
  plumbing, in `rustc_ast_pretty` and `rustc_expand`.
- The measurement is done in `MacroExpander::expand_invoc`.
- The measurements are stored in `ExtCtxt::macro_stats`.
This commit is contained in:
Nicholas Nethercote
2025-06-02 19:39:38 +10:00
parent bdfe1b9fb0
commit 376cbc3787
16 changed files with 610 additions and 52 deletions

View File

@@ -2305,6 +2305,8 @@ options! {
(space separated)"),
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
"show macro backtraces (default: no)"),
macro_stats: bool = (false, parse_bool, [UNTRACKED],
"print some statistics about macro expansions (default: no)"),
maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
"save as much information as possible about the correspondence between MIR and HIR \
as source scopes (default: no)"),