python / python/cpython

_CHECK_FUNCTION interferes with partial evaluation

Open
#126,902 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

A reminder of how _CHECK_FUNCTION looks like:

        tier2 op(_CHECK_FUNCTION, (func_version/2 -- )) {
            assert(PyStackRef_FunctionCheck(frame->f_funcobj));
            PyFunctionObject *func = (PyFunctionObject *)PyStackRef_AsPyObjectBorrow(frame->f_funcobj);
            DEOPT_IF(func->func_version != func_version);
        }

frame->f_funcobj becomes invalid once we start inlining functions. Thus we should "burn in" the function object version to be checked whenever possible, to not interfere with inlining and partial evaluation.

An added benefit is that the "burned in" version is also cheaper as it doesn't have to read from the frame struct, rather reading from the instruction itself in the JIT.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-126856

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the _CHECK_FUNCTION tier2 operation shown in the issue and examine how frame->f_funcobj is used when functions are inlined. Review linked PR gh-126856 and determine whether the function version can be burned into the instruction without interfering with partial evaluation; done means the version check no longer depends on the invalidated frame reference where possible.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
backend, compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.