bpo-46409: Make generators in bytecode#30633
Conversation
|
Fixes https://bugs.python.org/issue46389 and https://bugs.python.org/issue46374, but does not include tests for those issues. |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @markshannon for commit c33abbf 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @markshannon for commit 243e441 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
gvanrossum
left a comment
There was a problem hiding this comment.
I'm still trying to follow the rest of the C code here, but in case I fail, here's the rest of my review. :-)
Sorry, something went wrong.
|
PS. What do you mean by "coroutines are stackful"? (I was hoping that reading the code would clarify this, but either I didn't get to that point in the code yet or it's hidden by details.) |
Sorry, something went wrong.
Stackful coroutines have their own stack, like Lua coroutines or greenlets. |
Sorry, something went wrong.
e31703c to
17b453a
Compare
January 19, 2022 15:17
Adds a
RETURN_GENERATORbytecode which makes a generator (or coroutine) from the current frame.This has a number of advantages:
This PR also adds a
JUMP_NO_INTERRUPTbytecode. This is the same asJUMP_ABSOLUTEwithout any checks for interrupts. Checking for interrupts inyield fromwould destroy the flaky pretense that Python coroutines are stackful. (They are not, but PEPs 380 and 489 like to pretend that they are), so we need the extra, seemingly redundant instruction.We use
RETURN_GENERATORrather thanMAKE_GENERATOR; RETURN_VALUEas theRETURN_VALUEwould make the compiler treat all the following code as unreachable. We could fix that using artificial instructions, but I think that is best left to another PR.https://bugs.python.org/issue46409