Skip to content
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

Break up the YIELD_FROM instruction. #90197

Closed
markshannon opened this issue Dec 10, 2021 · 2 comments
Closed

Break up the YIELD_FROM instruction. #90197

markshannon opened this issue Dec 10, 2021 · 2 comments
Assignees
Labels
3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@markshannon
Copy link
Member

BPO 46039
Nosy @markshannon
PRs
  • bpo-46039: Split yield from in two #30035
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/markshannon'
    closed_at = <Date 2022-01-06.12:53:07.294>
    created_at = <Date 2021-12-10.17:48:52.500>
    labels = ['interpreter-core', '3.11']
    title = 'Break up the YIELD_FROM instruction.'
    updated_at = <Date 2022-01-06.12:53:07.293>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2022-01-06.12:53:07.293>
    actor = 'Mark.Shannon'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2022-01-06.12:53:07.294>
    closer = 'Mark.Shannon'
    components = ['Interpreter Core']
    creation = <Date 2021-12-10.17:48:52.500>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46039
    keywords = ['patch']
    message_count = 2.0
    messages = ['408232', '408593']
    nosy_count = 1.0
    nosy_names = ['Mark.Shannon']
    pr_nums = ['30035']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue46039'
    versions = ['Python 3.11']

    @markshannon
    Copy link
    Member Author

    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:

    @markshannon markshannon added the 3.11 only security fixes label Dec 10, 2021
    @markshannon markshannon self-assigned this Dec 10, 2021
    @markshannon markshannon added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.11 only security fixes labels Dec 10, 2021
    @markshannon markshannon self-assigned this Dec 10, 2021
    @markshannon markshannon added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Dec 10, 2021
    @markshannon
    Copy link
    Member Author

    New changeset 0b50a4f by Mark Shannon in branch 'main':
    bpo-46039: Split yield from in two (GH-30035)
    0b50a4f

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant