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

fix: Make edition per-token, not per-file #18861

Merged
merged 1 commit into from
Jan 9, 2025

Conversation

ChayimFriedman2
Copy link
Contributor

More correctly, also per-token. Because as it turns out, while the top-level edition affects parsing (I think), the per-token edition affects escaping of identifiers/keywords.

Fixes #18857.

CC @davidbarsky, I know the SyntaxContextId stuff is problematic for new Salsa and I don't know enough your solution, can you take a look this isn't problematic?

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 7, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really ought to do something about these tests, in new Salsa they change every time someone create a new interned type and that is awful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we talked about that on zulip iirc, for new salsa a bunch of tests need to change the rendering of what they expect. For this kind of stuff we likely need to have the test allocate a map and assign stable IDs that way

@ChayimFriedman2 ChayimFriedman2 force-pushed the await-edition branch 3 times, most recently from 5103b4c to 0ccdf52 Compare January 7, 2025 06:25
@Veykril
Copy link
Member

Veykril commented Jan 7, 2025

More correctly, also per-token. Because as it turns out, while the top-level edition affects parsing (I think), the per-token edition affects escaping of identifiers/keywords.

Yep, edition is part of hygiene (which is a per token, or well, per span thing)

@Veykril Veykril self-requested a review January 7, 2025 08:10
crates/edition/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we talked about that on zulip iirc, for new salsa a bunch of tests need to change the rendering of what they expect. For this kind of stuff we likely need to have the test allocate a map and assign stable IDs that way

@@ -58,8 +58,8 @@ impl BuiltinDeriveExpander {
tt: &tt::TopSubtree,
span: Span,
) -> ExpandResult<tt::TopSubtree> {
let span = span_with_def_site_ctxt(db, span, id);
self.expander()(span, tt)
let span = span_with_def_site_ctxt(db, span, id, Edition::CURRENT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I wonder, what is the edition rustc sets for these? Presumably its the edition of the standard library?

crates/syntax-bridge/src/lib.rs Outdated Show resolved Hide resolved
crates/span/src/hygiene.rs Outdated Show resolved Hide resolved
crates/hir-expand/src/name.rs Show resolved Hide resolved
crates/hir-expand/src/db.rs Show resolved Hide resolved
@@ -369,7 +369,8 @@ pub fn expect_fragment<'t>(
) -> ExpandResult<tt::TokenTreesView<'t, Span>> {
use ::parser;
let buffer = tt_iter.remaining();
let parser_input = to_parser_input(edition, buffer);
// FIXME: Pass the correct edition per token. Due to the split between mbe and hir-expand it's complicated.
let parser_input = to_parser_input(buffer, &mut |_ctx| edition);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is that? syntax context lookup isn't defined on the ExpandDatabase is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah drats, forgot we define the id in span, but not the content (we probably need to do use some extra trait setup to fix that post salsa swap to do dependency injection)

crates/span/src/hygiene.rs Outdated Show resolved Hide resolved

pub fn is_root(self) -> bool {
self == Self::ROOT
self.into_u32() <= Edition::LATEST as u32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in new salsa we still do kind of the same thing see f0ab742

But instead of using 0 we now use the max ID - 1 (which is the actual maximum), now that we have multiple roots we would need to change the check to ignore the page bits but otherwise this change should not be a problem for the salsa upgrade

@Veykril
Copy link
Member

Veykril commented Jan 8, 2025

Neat, I knew we were missing this when I was implementing the hygiene setup but expected this to be a lot more annoying to get to work. Glad to have been proven wrong.

More correctly, *also* per-token. Because as it turns out, while the top-level edition affects parsing (I think), the per-token edition affects escaping of identifiers/keywords.
@Veykril Veykril added this pull request to the merge queue Jan 9, 2025
Merged via the queue into rust-lang:master with commit 3fe50ef Jan 9, 2025
9 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the await-edition branch January 9, 2025 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using await inside a macro defined by an edition 2015 crate fails with E0559
3 participants