Skip to content

new trace_macros doesn't work if there's an error during expansion #43493

Closed

Description

@durka

The new trace_macros has much better output, but it has regressed in functionality! The old trace_macros could be used to debug macro expansion. Example using rustc 1.6.0:

$ cargo +1.6.0 script -u trace_macros -e 'trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);'
   Compiling expr v0.1.0 (file:///Users/alex/.cargo/.cargo/script-cache/expr-634e13f197b6cae5)
m! { foo }
.cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11:81: 11:84 error: no rules expected the token `foo`
.cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11     match {trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);} {
                                                                                                                                            ^~~
Could not compile `expr`.

OK, you can see m!(foo) was invoked, and then it didn't match so there's an error.

Now with current rustc (all channels):

$ cargo script -u trace_macros -e 'trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);'
   Compiling expr v0.1.0 (file:///Users/alex/.cargo/.cargo/script-cache/expr-634e13f197b6cae5)
error: no rules expected the token `foo`
  --> .cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11:81
   |
11 |     match {trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);} {
   |                                                                                 ^^^

error: Could not compile `expr`.

You no longer get to see the chain of expansions leading up to the error. This typically occurs much deeper in a string of recursive macros, making debugging much harder.

cc #41520 @estebank @nikomatsakis

Activity

  1. added
    A-syntaxextArea: Syntax extensions
    C-bugCategory: This is a bug.
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    P-highHigh priority
    on Jul 26, 2017
  2. Mark-Simulacrum commented on Jul 27, 2017

    @Mark-Simulacrum
    Member

    Nominating for prioritization. Seems good to fix since this is very painful for macro authors.

  3. nikomatsakis commented on Jul 27, 2017

    @nikomatsakis
    Contributor

    triage: P-medium

    Prioritizing as medium. @estebank -- any thoughts on how to include more information? @durka -- any suggestions for what the output should maybe look like?

  4. self-assigned this
    on Jul 27, 2017
  5. durka commented on Jul 27, 2017

    @durka
    ContributorAuthor

    I think the output provided by #41520/#42103 is fine (modulo the verbosity issue #42223). It just needs to show up even when expansion doesn't finish due to an error. Something like this:

    $ cargo script -u trace_macros -e 'trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);'
       Compiling expr v0.1.0 (file:///Users/alex/.cargo/.cargo/script-cache/expr-634e13f197b6cae5)
    error: no rules expected the token `foo`
      --> .cargo/.cargo/script-cache/expr-634e13f197b6cae5/expr.rs:11:81
       |
    11 |     match {trace_macros!(true); macro_rules! m { (x $($t:tt)*) => { m!() } } m!(foo);} {
       |                                                                                 ^^^
       = note: expanding `m! { foo }`
    

    This is probably also the issue in #42170.

  6. jseyfried commented on Jul 27, 2017

    @jseyfried
    Contributor

    This underlying issue here is that macro errors cause aborts way too much. For a quick fix, we could make sure we always call trace_macros_diag in the fatal error handling methods.

  7. estebank commented on Jul 28, 2017

    @estebank
    Contributor

    I think that @jseyfried's solution would be correct one.

  8. added a commit that references this issue on Aug 25, 2017
    1ed962b
  9. added 3 commits that reference this issue on Sep 17, 2017
    cafcdbb
    ef1f04f
    bc638b8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-syntaxextArea: Syntax extensionsC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions