about summary refs log tree commit diff
path: root/compiler/rustc_session/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-06-02 19:39:38 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-06-12 21:17:17 +1000
commit376cbc3787d2312b6b3b5db84dd1734fed1ebda6 (patch)
tree1f93fafea489fc66c36fbacd70b45931952418f2 /compiler/rustc_session/src
parentbdfe1b9fb0c3f98df2a99ab96c6190542c234060 (diff)
downloadrust-376cbc3787d2312b6b3b5db84dd1734fed1ebda6.tar.gz
rust-376cbc3787d2312b6b3b5db84dd1734fed1ebda6.zip
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`.
Diffstat (limited to 'compiler/rustc_session/src')
-rw-r--r--compiler/rustc_session/src/options.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 12fa05118ca..a26d3bc4044 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -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)"),