-
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
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 |
f08ffb3
to
2ece970
Compare
This comment has been minimized.
This comment has been minimized.
This new version doesn't store the inferred type of full patterns but only the inferred type of type placeholders. This also helps towards solving #11722. The association between placeholders'
I'd like to have feedback on this approach before cleaning this up. I didn't find any exiting instance of unifying a This still only incurs a small increase in memory usage on self analysis-stats (+4MB total). analysis-stats output
Current master:
This PR:
|
09d65ac
to
f208132
Compare
f208132
to
249b8be
Compare
The failing test is an issue with the new-solver-based type inference, see #20644. |
249b8be
to
14c9473
Compare
This adds a type_of_type_placeholder arena to InferenceResult to record which type a given type placeholder gets inferred to.
This uses the new InferenceResult::type_of_type_placeholder data 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<_>`.
With the extra InferenceResult that maps type placeholders to their inferred type, we can now easily display inlay hints for them.
14c9473
to
007b9ba
Compare
Any comments on that approach that tries to unify placeholders in (Can I change labels myself? Let's try:) |
Or you could try Sorry for the delayed reviews since rust-analyzer team is currently focused on finishing trait-solver migration. I think Chayim would be the right person to review this but I'll review this if they is busy or couldn't make time for this within 2~3 days. |
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