-
Notifications
You must be signed in to change notification settings - Fork 158
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
Idea: salsa::supertype and upcasting on Id
#578
Labels
Milestone
Comments
nikomatsakis
added
good first issue
Good for newcomers
bikeshed 🚴♀️
Debating API details and the like
labels
Sep 26, 2024
Mentoring instructions: Methods on id
Proc macro |
I've assigned this issue to myself; I'll need this functionality in Salsa in order to migrate rust-analyzer. |
ChayimFriedman2
added a commit
to ChayimFriedman2/salsa
that referenced
this issue
Jan 12, 2025
Or "supertypes" as they are called in salsa-rs#578. They are of the form: ``` enum Enum { Input(Input), Interned(Interned), ... } ```
davidbarsky
pushed a commit
to davidbarsky/salsa
that referenced
this issue
Jan 14, 2025
Or "supertypes" as they are called in salsa-rs#578. They are of the form: ``` enum Enum { Input(Input), Interned(Interned), ... } ```
davidbarsky
pushed a commit
to davidbarsky/salsa
that referenced
this issue
Jan 15, 2025
Or "supertypes" as they are called in salsa-rs#578. They are of the form: ``` enum Enum { Input(Input), Interned(Interned), ... } ```
davidbarsky
pushed a commit
to davidbarsky/salsa
that referenced
this issue
Jan 24, 2025
Or "supertypes" as they are called in salsa-rs#578. They are of the form: ``` enum Enum { Input(Input), Interned(Interned), ... } ```
davidbarsky
pushed a commit
to davidbarsky/salsa
that referenced
this issue
Jan 24, 2025
Or "supertypes" as they are called in salsa-rs#578. They are of the form: ``` enum Enum { Input(Input), Interned(Interned), ... } ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
I've noticed that I often have an enum whose variants are all different salsa structs:
I was thinking about how this enum will use 2 words and not 1 and I realized that, given that each variant is just storing an
Id
, and that we can go from anId
to anIngredientIndex
(it's stored on the page), we could have a proc-macro that takes such an enum and returns a special struct that just stores a singleId
. It could then be converted into an enum readily enough. You also downcast it.I'm imagining the following:
First, add two methods to
salsa::Id
,fn is<S>(self, db: &dyn Database) -> bool
andfn downcast<S>(self, db: &dyn Database) -> Option<S>
, whereS: SalsaStructInDb<'_>
. These methods can lookup the id indb.table
, identify the ingredient index on the from thePage
, compare that to the ingredient index forS
, and then do the appropriate thing. (We might also want to tweak theFromId
or other traits in a similar-ish way.)Next, create a proc macro named
supertype
(bikeshed) which expects an enum with one lifetime argument and where each variant has a single argument:we generate the following:
The text was updated successfully, but these errors were encountered: