-
Notifications
You must be signed in to change notification settings - Fork 181
Implement generators #593
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
Implement generators #593
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,5 +22,50 @@ _)`) or "fixed-length array" `[_; _]`. Note that the precise set of | |
| these built-in types is defined by the `Interner` and is unknown to | ||
| chalk-ir. | ||
|
|
||
| ## [`TypeName`] variants | ||
|
|
||
| ### Generator | ||
|
|
||
| A `Generator` represents a Rust generator. There are three major components | ||
| to a generator: | ||
|
|
||
| * Upvars - similar to closure upvars, they reference values outside of the generator, | ||
| and are stored across al yield points. | ||
| * Resume/yield/return types - the types produced/consumed by various generator methods. | ||
| These are not stored in the generator across yield points - they are only | ||
| used when the generator is running. | ||
| * Generator witness - see the `Generator Witness` section below. | ||
|
|
||
| Of these types, only upvars and resume/yield/return are stored directly in | ||
| `TypeName::Generator`. The generator witness is implicitly associated with the generator | ||
| by virtue of sharing the same `GeneratorId`. It is only used when determining auto trait | ||
| impls, where it is considered a 'constituent type'. | ||
|
|
||
| ### Generator witness types | ||
|
|
||
| The `GeneratorWitness` variant represents the generator witness of | ||
| the generator with id `GeneratorId`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be good to explain the purpose of a witness: The witness type captures the types of all variables that may be live across a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just moved this entire block from a different section of the book :) - I'm happy to expand on it. |
||
|
|
||
| The generator witness contains multiple witness types, | ||
| which represent the types that may be part of a generator | ||
| state - that is, the types of all variables that may be live across | ||
| a `yield` point. | ||
|
|
||
| Unlike other types, witnesses include bound, existential | ||
| lifetimes, which refer to lifetimes within the suspended stack frame. | ||
| You can think of it as a type like `exists<'a> { (T...) }`. | ||
|
|
||
| Witnesses are very similar to an `Apply` type, but it has a binder for | ||
| the erased lifetime(s), which must be handled specifically in equating | ||
| and so forth. In many ways, witnesses are also quite similar to `Fn` | ||
| types, and it is not out of the question that these two could be | ||
| unified; however, they are quite distinct semantically and so that | ||
| would be an annoying mismatch in other parts of the system. | ||
| Witnesses are also similar to a `Dyn` type, in that they represent an | ||
| existential type, but in contrast to `Dyn`, what we know here is | ||
| not a *predicate* but rather some upper bound on the set of types | ||
| contained within. | ||
|
|
||
|
|
||
| [`TypeName`]: http://rust-lang.github.io/chalk/chalk_ir/enum.TypeName.html | ||
| [`Substitution`]: http://rust-lang.github.io/chalk/chalk_ir/struct.Substitution.html | ||
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.
thank you for writing docs! wonderful.