Skip to content

Commit 1e21b3c

Browse files
committed
Add some debug logs to macro matching
These were useful while debugging, so I'll leave them here.
1 parent 5f73eac commit 1e21b3c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

+8
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ impl<'matcher> Tracker<'matcher> for NoopTracker {
234234

235235
/// Expands the rules based macro defined by `lhses` and `rhses` for a given
236236
/// input `arg`.
237+
#[instrument(skip(cx, transparency, arg, lhses, rhses))]
237238
fn expand_macro<'cx>(
238239
cx: &'cx mut ExtCtxt<'_>,
239240
sp: Span,
@@ -429,6 +430,7 @@ enum CanRetry {
429430
/// Try expanding the macro. Returns the index of the sucessful arm and its named_matches if it was successful,
430431
/// and nothing if it failed. On failure, it's the callers job to use `track` accordingly to record all errors
431432
/// correctly.
433+
#[instrument(level = "debug", skip(sess, arg, lhses, track), fields(tracking = %T::description()))]
432434
fn try_match_macro<'matcher, T: Tracker<'matcher>>(
433435
sess: &ParseSess,
434436
name: Ident,
@@ -460,6 +462,8 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>(
460462
// Try each arm's matchers.
461463
let mut tt_parser = TtParser::new(name);
462464
for (i, lhs) in lhses.iter().enumerate() {
465+
let _tracing_span = trace_span!("Matching arm", %i);
466+
463467
// Take a snapshot of the state of pre-expansion gating at this point.
464468
// This is used so that if a matcher is not `Success(..)`ful,
465469
// then the spans which became gated when parsing the unsuccessful matcher
@@ -472,20 +476,24 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>(
472476

473477
match result {
474478
Success(named_matches) => {
479+
debug!("Parsed arm successfully");
475480
// The matcher was `Success(..)`ful.
476481
// Merge the gated spans from parsing the matcher with the pre-existing ones.
477482
sess.gated_spans.merge(gated_spans_snapshot);
478483

479484
return Ok((i, named_matches));
480485
}
481486
Failure(_, _) => {
487+
trace!("Failed to match arm, trying the next one");
482488
// Try the next arm
483489
}
484490
Error(_, _) => {
491+
debug!("Fatal error occurred during matching");
485492
// We haven't emitted an error yet
486493
return Err(CanRetry::Yes);
487494
}
488495
ErrorReported(guarantee) => {
496+
debug!("Fatal error occurred and was reported during matching");
489497
return Err(CanRetry::No(guarantee));
490498
}
491499
}

0 commit comments

Comments
 (0)