[New-bugs-announce] [issue46039] Break up the YIELD_FROM instruction.

Mark Shannon report at bugs.python.org
Fri Dec 10 12:48:52 EST 2021


New submission from Mark Shannon <mark at hotpy.org>:

The YIELD_FROM instruction does three things:

* It sends a value to the sub-iterator
* It yields the value from the sub-iterator back up to its caller
* Loops back on itself

So we should implement this as:

SEND        <--+
YIELD_VALUE    |
JUMP_ABSOLUTE -+

Doing so would allow us to simplify gen.send and gen.throw as they wouldn't need all the special cases for 'yield from'.

Zero cost exception handling allows us to handle throw in the bytecode with no runtime overhead:

while True:
    SEND -> exit
    try:
        YIELD_VALUE
    except BaseException as ex:
        sub_iterator.throw(ex)
exit:

----------
assignee: Mark.Shannon
components: Interpreter Core
messages: 408232
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: Break up the YIELD_FROM instruction.
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46039>
_______________________________________


More information about the New-bugs-announce mailing list