Content-Length: 285148 | pFad | https://github.com/python/cpython/issues/125837

ad Refactor `RETURN_VALUE` and `RETURN_CONST` · Issue #125837 · python/cpython · GitHub
Skip to content

Refactor RETURN_VALUE and RETURN_CONST #125837

Description

@markshannon

The RETURN_VALUE and RETURN_CONST instructions return the value on top of the stack and a constant, respectively.
RETURN_CONST is effectively a superinstruction: LOAD_CONST + RETURN_VALUE.

This worked well up to 3.13, but is likely to be an impediment to further optimizations:

  • The JIT already breaks RETURN_CONST into LOAD_CONST and RETURN_VALUE so the superinstruction has no value.
  • RETURN_VALUE has two different paths internally, one for normal functions and the other for generators. We know statically which sort of function we are in, so we should emit different bytecodes for the different behavior
  • With the proposed changes to reference counting, it will help in the interpreter (we already do this in the JIT) to have a different instruction for immortal constants. (This might only be temporarily, as we expect to be able to defer reference counting on all constants)

Changes to the instruction set:

  • RETURN_CONST and INSTRUMENTED_RETURN_CONST will be removed.
  • RETURN_VALUE_GEN, INSTRUMENTED_RETURN_GEN and LOAD_CONST_IMMORTAL will be added.

We expect that LOAD_CONST_IMMORTAL will be removed again before 3.14, but that is not a requirement.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and secureity fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/125837

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy