-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] intern types using Salsa #12061
Conversation
As reference, this is how rustc interns types: The data type: A reference to a type (bound to the The definition of And this is used in |
&self.module_type | ||
} | ||
|
||
pub(super) fn class_ty(&self, id: FileClassTypeId) -> &ClassType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think returning a refence would work if we use an actual Arena
that allocates a new vector when it runs out of space instead of resizing the existing one (which would invalidate previously returned Ids).
Or more generally. The way to return references here is by lifting the lifetime of types outside of type store by having the actual data owned further up.
I do like splitting out the type internet from the type inference result. I think it makes sense to have them separate and also allows more effective reuse. The part that's unclear to me and that you already mentioned on your write up is how to collect unused types. How can we prevent that this is an ever-growing arena? We could try to track type references by using an |
This now uses Salsa interning, which eliminates a lot of our own interning and ID boilerplate, and actually works! |
CodSpeed Performance ReportMerging #12061 will degrade performances by 4.03%Comparing Summary
Benchmarks breakdown
|
Some things in this PR that might require further attention:
|
|
The message says I'm supposed to acknowledge the regression on CodSpeed, but when I login to CodSpeed with GitHub, it says I'm not allowed to acknowledge the regression... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit surprised by the regression but I think it makes sense. Previously, accessing a field on ClassType
was reading a reference but it is now a lookup in the salsa ingredient table. Niko's work should help reduce that cost but certainly something to be aware of. The good news, we can still build a more fancy type interner if it turns out that this is the bottleneck
You now have the permissions to acknowledge regressions. Use it responsibly :P |
After offline discussion with @MichaReiser, going to switch to |
The updated perf results are a bit better; not sure if this is just noise or if not interning |
Intern types using Salsa interning instead of in the
TypeInference
result.This eliminates the need for
TypingContext
, and also paves the way for finer-grained type inference queries.