[red-knot] intern types separately from type inference result #12061
+280
−333
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.
Initial exploration of what it might look like to intern types independent of the type inference result, so the granularity of type inference and the granularity of type interning don't have to be coupled.
The goal of this is to make it possible to add
definition_ty
queries, but this PR doesn't do that yet.This PR also doesn't work yet :) Just for illustration, I'm using
Arc::get_mut
in the places where we need to mutate theFileTypeStore
, but we can't actually do this because Salsa is still holding on to a reference to the Arc also. To make this work, we'll need to introduce interior mutability to theFileTypeStore
, which is a bit tricky along with wanting to return references to type structs stored inside it. The oldTypeStore
in the oldred_knot
crate shows one approach to this, but I'm not sure it's the best option.Having the
FileTypeStore
returned by a salsa query at all might require the Salsa "mutable arena" feature discussed in salsa-rs/salsa#490 (comment) -- if so, for now we could instead just keep our our own dashmap ofVfsFile
toFileTypeStore
on the Db, but not actually in Salsa.Some nice things about interning types ourselves: a lot fewer lifetimes (no lifetime on
Type
enum anymore), and we can eliminate theTypingContext
indirection layer and just use Db in all APIs.