feat: type inference for generators
This PR implements basic type inference for generator and yield expressions.
Things not included in this PR:
- Generator upvars and generator witnesses are not implemented. They are only used to determine auto trait impls, so basic type inference should be fine without them, but method resolutions with auto trait bounds may not be resolved correctly.
Open questions:
- I haven't (yet) implemented
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? - I added moderate amount of stuffs to minicore. I especially didn't want to add
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
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 added moderate amount of stuffs to minicore. I especially didn't want to add impl<T> Deref for &T and impl<T> Deref for &mut T exclusively for tests for generators; should I move them into the test fixtures or can they be placed in minicore?
I think those are some key implementations so adding them to minicore seems fine to me
I haven't (yet) implemented HirDisplay for TyKind::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?
Probably just like closures but maybe with gen prefixed or something along those lines?
I haven't (yet) implemented HirDisplay for TyKind::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?
Probably just like closures but maybe with
genprefixed or something along those lines?
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 impl Generator<ResumeType, Yield = YieldType, Return = ReturnType>, it's clear but too long to show imo (maybe it's suitable for DisplayTarget::Test though).
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 impl Generator<ResumeType, Yield = YieldType, Return = ReturnType>, it's clear but too long to show imo (maybe it's suitable for DisplayTarget::Test though).
We can probably just make something up here like gen<YieldTy> |ResumeType| -> ReturnType or yield<YieldTy> |ResumeType| -> ReturnType?
Sorry for the delay! I decided to go for the initial implementation like so: |ResumeType| yields YieldType -> ReturnType.
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+
:pushpin: Commit 9ede5f073564f140194229546fc2bf5eb6267b62 has been approved by Veykril
It is now in the queue for this repository.
:hourglass: Testing commit 9ede5f073564f140194229546fc2bf5eb6267b62 with merge 1f929659acff378adad85fcea747f8b19a0f819f...
:sunny: Test successful - checks-actions Approved by: Veykril Pushing 1f929659acff378adad85fcea747f8b19a0f819f to master...