-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Use inferred type in “extract type as type alias” assist #20125
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
base: master
Are you sure you want to change the base?
Use inferred type in “extract type as type alias” assist #20125
Conversation
This adds a type_of_type arena to InferenceResult to record which type a given type reference gets inferred to.
This uses the new InferenceResult content to turn type references into completely resolved types instead of just returning the lexical type.
When met with types with placeholders, this ensures this assist extracts the inferred type instead of the type with placeholders. For instance, when met with this code: ``` fn main() { let vec: Vec<_> = vec![4]; } ``` selecting Vec<_> and extracting an alias will now yield `Vec<i32>` instead of `Vec<_>`.
I think that could be a lot of types to store, and we'd like to avoid making the InferenceResult bigger. I wonder if we could just store the inferred types of |
I don't think that's doable in the general case. In the case of LetStmt maybe, but as you say that would be a lot of work to map the selected part of the type to the correct part of the pattern. For other cases such as I'll rework this to only store the inferred |
We have the recorded type of Maybe before reworking it, take a look at how the memory usage changes for |
@flodiebold This regressed analysis-stats only by 3mb, so I think it's acceptable. |
Unfortunately this approach isn't enough, as all the intermediate types created during lowering won't appear in the |
This records the inferred type for type references in InferenceResult then uses that information in extract_type_alias to extract the inferred type.
Fixes #20108