internal: Refactor SyntaxContext to not reimplement Salsa macros - #23308
Open
ChayimFriedman2 wants to merge 1 commit into
Open
internal: Refactor SyntaxContext to not reimplement Salsa macros#23308ChayimFriedman2 wants to merge 1 commit into
SyntaxContext to not reimplement Salsa macros#23308ChayimFriedman2 wants to merge 1 commit into
Conversation
ChayimFriedman2
force-pushed
the
syntaxcontext-refactor
branch
from
September 7, 2026 15:31
02db2f6 to
1886f9a
Compare
Veykril
reviewed
Sep 7, 2026
| opaque: SyntaxContext, | ||
| opaque_and_semiopaque: SyntaxContext, | ||
| opaque_if_not_self: Option<SyntaxContext>, | ||
| opaque_and_semiopaque_if_not_self: Option<SyntaxContext>, |
Member
There was a problem hiding this comment.
We still don't need to partial_eq and hash these two fields, the way apply_mark_internal works the first 4 fields will never be interned equally with differing fields for these two
Contributor
Author
There was a problem hiding this comment.
We don't, but I feel safer this way, and the perf impact shouldn't be large.
Comment on lines
+60
to
+66
| #[salsa::interned(unsafe(no_lifetime), revisions = usize::MAX)] | ||
| struct SyntaxContextImpl { | ||
| data: SyntaxContextData, | ||
| } | ||
|
|
||
| zalsa_::register_jar! { | ||
| zalsa_::ErasedJar::erase::<SyntaxContext>() | ||
| } | ||
|
|
||
| /// Key to use during hash lookups. Each field is some type that implements `Lookup<T>` | ||
| /// for the owned type. This permits interning with an `&str` when a `String` is required and so forth. | ||
| #[derive(Hash)] | ||
| struct StructKey<'db, T0, T1, T2, T3>(T0, T1, T2, T3, std::marker::PhantomData<&'db ()>); | ||
|
|
||
| impl<'db, T0, T1, T2, T3> zalsa_::HashEqLike<StructKey<'db, T0, T1, T2, T3>> for SyntaxContextData | ||
| where | ||
| Option<MacroCallId>: zalsa_::HashEqLike<T0>, | ||
| Transparency: zalsa_::HashEqLike<T1>, | ||
| Edition: zalsa_::HashEqLike<T2>, | ||
| SyntaxContext: zalsa_::HashEqLike<T3>, | ||
| { | ||
| fn hash<H: std::hash::Hasher>(&self, h: &mut H) { | ||
| zalsa_::HashEqLike::<T0>::hash(&self.outer_expn, &mut *h); | ||
| zalsa_::HashEqLike::<T1>::hash(&self.outer_transparency, &mut *h); | ||
| zalsa_::HashEqLike::<T2>::hash(&self.edition, &mut *h); | ||
| zalsa_::HashEqLike::<T3>::hash(&self.parent, &mut *h); | ||
| } | ||
| fn eq(&self, data: &StructKey<'db, T0, T1, T2, T3>) -> bool { | ||
| zalsa_::HashEqLike::<T0>::eq(&self.outer_expn, &data.0) | ||
| && zalsa_::HashEqLike::<T1>::eq(&self.outer_transparency, &data.1) | ||
| && zalsa_::HashEqLike::<T2>::eq(&self.edition, &data.2) | ||
| && zalsa_::HashEqLike::<T3>::eq(&self.parent, &data.3) | ||
| } | ||
| } | ||
|
|
||
| // SAFETY: `Self::Fields`, i.e. `SyntaxContextData`, doesn't contain any lifetimes. | ||
| unsafe impl zalsa_struct_::Configuration for SyntaxContext { | ||
| const LOCATION: salsa::plumbing::Location = | ||
| salsa::plumbing::Location { file: file!(), line: line!() }; | ||
| const DEBUG_NAME: &'static str = "SyntaxContextData"; | ||
| const REVISIONS: std::num::NonZeroUsize = std::num::NonZeroUsize::MAX; | ||
| const PERSIST: bool = false; | ||
|
|
||
| type Fields<'a> = SyntaxContextData; | ||
| type Struct<'a> = SyntaxContext; | ||
|
|
||
| fn serialize<S>(_: &Self::Fields<'_>, _: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: zalsa_::serde::Serializer, | ||
| { | ||
| unimplemented!("attempted to serialize value that set `PERSIST` to false") | ||
| } | ||
|
|
||
| fn deserialize<'de, D>(_: D) -> Result<Self::Fields<'static>, D::Error> | ||
| where | ||
| D: zalsa_::serde::Deserializer<'de>, | ||
| { | ||
| unimplemented!("attempted to deserialize value that cannot set `PERSIST` to false"); | ||
| } | ||
| } | ||
| #[derive(Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct SyntaxContext(NonZeroU32); |
Member
There was a problem hiding this comment.
why the split here? And if there is a reason for it, why aren't we just embedding newtyping like SyntaxContext(SyntaxContextImpl)
Contributor
Author
There was a problem hiding this comment.
It's easier because there are many methods. But it doesn't really matter.
ChayimFriedman2
force-pushed
the
syntaxcontext-refactor
branch
from
September 8, 2026 02:09
1886f9a to
63fce89
Compare
Instead store `Option`s for the self-referential parts.
ChayimFriedman2
force-pushed
the
syntaxcontext-refactor
branch
from
September 8, 2026 03:43
63fce89 to
ef4abcd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead store
Options for the self-referential parts.