From 1e21b3cfa38c5040ae0faf99178b0112fc90fd93 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 27 Oct 2022 22:03:34 +0200 Subject: [PATCH] Add some debug logs to macro matching These were useful while debugging, so I'll leave them here. --- compiler/rustc_expand/src/mbe/macro_rules.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index b1214543e5d..78b3fa337ae 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -234,6 +234,7 @@ fn description() -> &'static str { /// Expands the rules based macro defined by `lhses` and `rhses` for a given /// input `arg`. +#[instrument(skip(cx, transparency, arg, lhses, rhses))] fn expand_macro<'cx>( cx: &'cx mut ExtCtxt<'_>, sp: Span, @@ -429,6 +430,7 @@ enum CanRetry { /// Try expanding the macro. Returns the index of the sucessful arm and its named_matches if it was successful, /// and nothing if it failed. On failure, it's the callers job to use `track` accordingly to record all errors /// correctly. +#[instrument(level = "debug", skip(sess, arg, lhses, track), fields(tracking = %T::description()))] fn try_match_macro<'matcher, T: Tracker<'matcher>>( sess: &ParseSess, name: Ident, @@ -460,6 +462,8 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>( // Try each arm's matchers. let mut tt_parser = TtParser::new(name); for (i, lhs) in lhses.iter().enumerate() { + let _tracing_span = trace_span!("Matching arm", %i); + // Take a snapshot of the state of pre-expansion gating at this point. // This is used so that if a matcher is not `Success(..)`ful, // then the spans which became gated when parsing the unsuccessful matcher @@ -472,6 +476,7 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>( match result { Success(named_matches) => { + debug!("Parsed arm successfully"); // The matcher was `Success(..)`ful. // Merge the gated spans from parsing the matcher with the pre-existing ones. sess.gated_spans.merge(gated_spans_snapshot); @@ -479,13 +484,16 @@ fn try_match_macro<'matcher, T: Tracker<'matcher>>( return Ok((i, named_matches)); } Failure(_, _) => { + trace!("Failed to match arm, trying the next one"); // Try the next arm } Error(_, _) => { + debug!("Fatal error occurred during matching"); // We haven't emitted an error yet return Err(CanRetry::Yes); } ErrorReported(guarantee) => { + debug!("Fatal error occurred and was reported during matching"); return Err(CanRetry::No(guarantee)); } }