-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Coroutines #53
Coroutines #53
Conversation
|
||
# Summary | ||
|
||
Add "shallow" coroutines similar to Python's generators. |
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.
@thestinger confused me a bit about the subject, but my last findings suggest Python is misusing the word "coroutines", which traditionally are a superset of "generators" (the difference being the ability to yield
through multiple stack frames).
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.
True, that's why I called them "shallow" coroutines.
I would much rather see all the tools required for implementing this (in a syntax extension, for example), than baking it into the language (like closures are today, and will be before you can implement |
I think you'd need some kind of "unsafe goto", which is ignored by borrow/lifetime checker passes for this to be possible as a syntax extension. Not likely, in my estimation... |
Why? When you can do a state machine transform and you get code that's easier to optimize. |
@eddyb, I would love to see how that transform looks like! |
Based on my experience with Python:
|
Assuming the coroutine->iterator "adapter" trait is provided by the standard library (as it should), your collection iterator implementation will look like this:
We could support that, but what would that save us vs the above? A pair of braces? (presumably, you'd still have to say
Quite the opposite, actually. This is where being wrapped in an outer function comes in handy: The initial set of arguments go to the outer function, which may perform some pre-processing, before constructing and returning the coroutine closure. |
Thanks for the RFC! The team has decided that while desirable, this is not needed for 1.0 at this time. I imagine that a library such as this will work best with as little language support as possible, so this may be best done as a new library rather than a language change per-se. Closing. |
:( Did the team have concrete suggestions of how this could be done as a library? |
We believe that it's possible to add support for this in a backwards-compatible fashion, especially because |
how should that be possible?
this needs first-class support of pauseable and resumable code. |
I think what Alex means is that a library in stdlib could provide the functionality. This is analogous to how (Caveat: I have not given any consideration to how the borrow-checking rules could be impacted by such a feature. I am assuming it's a solvable problem at worst.) |
ok, this is sadly far over my head. the implications and techniques necessary to create a data structure wrapping a function’s environment and stack is too deep to consider working on. i hope some heavy contributor takes this up. |
Rendered