Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul MacArgs #96546

Merged
merged 6 commits into from
May 4, 2022
Merged

Overhaul MacArgs #96546

merged 6 commits into from
May 4, 2022

Commits on Apr 29, 2022

  1. Tweak print_attr_item.

    This commit rearranges the `match`. The new code avoids testing for
    `MacArgs::Eq` twice, at the cost of repeating the `self.print_path()`
    call. I think this is worthwhile because it puts the `match` in a more
    standard and readable form.
    nnethercote committed Apr 29, 2022
    Configuration menu
    Copy the full SHA
    5a05b61 View commit details
    Browse the repository at this point in the history
  2. Rename visit_interpolated as visit_nonterminal.

    Because `Nonterminal` is the type it visits.
    nnethercote committed Apr 29, 2022
    Configuration menu
    Copy the full SHA
    481a446 View commit details
    Browse the repository at this point in the history
  3. Simplify lower_mac_args.

    The `token` is always an interpolated non-terminal expression, and
    always a literal in valid code. This commit simplifies the processing
    accordingly, by directly extracting and using the literal.
    nnethercote committed Apr 29, 2022
    Configuration menu
    Copy the full SHA
    cde25f8 View commit details
    Browse the repository at this point in the history
  4. Remove the T::VISIT_TOKENS test in visit_mac_args.

    The two paths are equivalent -- they both end up calling `visit_expr()`.
    I have kept the more restrictive path, the one that requires that
    `token` be an expression nonterminal. (The next commit will simplify this
    function further.)
    nnethercote committed Apr 29, 2022
    Configuration menu
    Copy the full SHA
    ae5f67f View commit details
    Browse the repository at this point in the history

Commits on May 4, 2022

  1. Overhaul MacArgs::Eq.

    The value in `MacArgs::Eq` is currently represented as a `Token`.
    Because of `TokenKind::Interpolated`, `Token` can be either a token or
    an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
    literal or macro call AST fragment, and then is later lowered to a
    literal token. But this is very non-obvious. `Token` is a much more
    general type than what is needed.
    
    This commit restricts things, by introducing a new type `MacArgsEqKind`
    that is either an AST expression (pre-lowering) or an AST literal
    (post-lowering). The downside is that the code is a bit more verbose in
    a few places. The benefit is that makes it much clearer what the
    possibilities are (though also shorter in some other places). Also, it
    removes one use of `TokenKind::Interpolated`, taking us a step closer to
    removing that variant, which will let us make `Token` impl `Copy` and
    remove many "handle Interpolated" code paths in the parser.
    
    Things to note:
    - Error messages have improved. Messages like this:
      ```
      unexpected token: `"bug" + "found"`
      ```
      now say "unexpected expression", which makes more sense. Although
      arbitrary expressions can exist within tokens thanks to
      `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
      know compiler internals.
    - In `parse_mac_args_common`, we no longer need to collect tokens for
      the value expression.
    nnethercote committed May 4, 2022
    Configuration menu
    Copy the full SHA
    99f5945 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    baa18c0 View commit details
    Browse the repository at this point in the history