Skip to content

fix: Always cache macro expansions' root node in Semantics #18117

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

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

ChayimFriedman2
Copy link
Contributor

Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.

Fixes #18089.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2024
@ChayimFriedman2 ChayimFriedman2 changed the title Always cache macro expansions' root node in Semantics fix: Always cache macro expansions' root node in Semantics Sep 15, 2024
Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.
Comment on lines +124 to +138
pub(super) fn get_or_insert_expansion(
&mut self,
sema: &SemanticsImpl<'_>,
macro_file: MacroFileId,
) -> &ExpansionInfo {
self.expansion_info_cache.entry(macro_file).or_insert_with(|| {
let exp_info = macro_file.expansion_info(sema.db.upcast());

let InMacroFile { file_id, value } = exp_info.expanded();
sema.cache(value, file_id.into());

exp_info
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

this idea behind this is to inline setting both to prevent mismatches, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Without this it's only matter of time until the next panic; this ensures panic of this form will never come again.

@Veykril
Copy link
Member

Veykril commented Sep 18, 2024

Thanks!
@bors r+

@bors
Copy link
Contributor

bors commented Sep 18, 2024

📌 Commit 35e171a has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 18, 2024

⌛ Testing commit 35e171a with merge f4aca78...

@bors
Copy link
Contributor

bors commented Sep 18, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing f4aca78 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Sep 18, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing f4aca78 to master...

@bors bors merged commit f4aca78 into rust-lang:master Sep 18, 2024
13 checks passed
@bors
Copy link
Contributor

bors commented Sep 18, 2024

👀 Test was successful, but fast-forwarding failed: 422 Changes must be made through a pull request.

@bors
Copy link
Contributor

bors commented Sep 18, 2024

☔ The latest upstream changes (presumably #18117) made this pull request unmergeable. Please resolve the merge conflicts.

@ChayimFriedman2
Copy link
Contributor Author

☔ The latest upstream changes (presumably #18117) made this pull request unmergeable. Please resolve the merge conflicts.

What? That's this pull request 😕

@ChayimFriedman2 ChayimFriedman2 deleted the issue-18089 branch October 6, 2024 22:04
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.

Rust analyzer panics when combining the crates "rocket" and "askama"
5 participants