-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Migrate parser to the new span combining scheme #126763
Copy link
Copy link
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Summary:
I
a,b, ...,zare multiple consecutive span nodes that need to be combined into a single new span node, then its combined span should be"Span node" is either an individual token (every token has a span), or some larger AST node having a
Spanfield.Examples:
The combined span for these pieces of code will be
Status quo:
Currently the resulting span is typically built like
span_first_token.to(span_last_token).So anything in the middle and the internal structure (i.e. nodes, as opposed to tokens) are ignored.
Why we need to change it:
The
tooperation will automatically take macro variables into account, and will try to put the resulting span into the best suitable macro context (this was implemented in #119673).E.g. in
$tt + 5the combined expression span will be put into the context of the macro using$ttas a macro parameter.Note, that the same thing often happens in the current parser as well, but not consistently, e.g.
$a::$bwill produce an incorrect resulting path span because the::in the middle is not considered.This will also give us some single relatively well predictable rule for combining AST spans.
Implementation:
This work should be parallelizable relatively well (but may require a one time initial setup).
I'll review PRs doing this, they can be assigned to me.
It may be convenient to have a rolling value in the
Parserstructure for span of the current (or previous?) span node.The parser has a lot of bespoke diagnostic logic (including snapshotting) that stands in the way of any systematic improvements like this.
How this can be tested:
Make a macro that emits complex nodes using tokens from different contexts, e.g.
and emit some diagnostic using those nodes' spans (maybe can add a special internal diagnostic for this testing).