-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: type inference for generators #13209
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
Conversation
|
I deliberately did not link #4309 for automatic close because there are still some features missing as mentioned in the PR description. However I think this PR enables type inference in most of the real-world use cases and we might want to close #4309 and create a new issue for the missing features (only if this PR is merged, of course). |
I think those are some key implementations so adding them to minicore seems fine to me
Probably just like closures but maybe with |
| /// closures, but currently this is the only field that will change there, | ||
| /// so it doesn't make sense. | ||
| return_ty: Ty, | ||
| resume_yield_tys: Option<(Ty, Ty)>, |
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.
Comment might be nice about which one the yield and return type is
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.
Added doc comment
I'd love to reuse the closure syntax, but I'm not sure how we can encode yield type of a generator. Another option I thought of was |
3ee75f9 to
4b5a66e
Compare
We can probably just make something up here like |
|
Sorry for the delay! I decided to go for the initial implementation like so: This is now ready for (another?) full review. note to self: some parts of generator substitution handling need to be adjusted when we change the generic parameter ordering. |
|
@bors r+ |
|
☀️ Test successful - checks-actions |
This PR implements basic type inference for generator and yield expressions.
Things not included in this PR:
Open questions:
HirDisplayforTyKind::Generator, so generator types are just shown as "{{generator}}" (in tests, inlay hints, hovers, etc.), which is not really nice. How should we show them?impl<T> Deref for &Tandimpl<T> Deref for &mut Texclusively for tests for generators; should I move them into the test fixtures or can they be placed in minicore?cc #4309