Skip to content

hook for JIT to support _PyFrame_GetFrameObject #575

@carljm

Description

@carljm

A JIT will likely not want to maintain the full state of a _PyInterpreterFrame (most importantly, stack/locals; maybe also prev_instr) during execution of JITted code. In general, it should be the JIT's responsibility to ensure the interpreter frame is in the correct state before it returns control to the interpreter.

However, the functions PyEval_GetFrame and PyThreadState_GetFrame, which return a full PyFrameObject for the current interpreter frame, are public C API. PyThreadState_GetFrame is used internally by the coroutine_origin_tracking_depth feature and by PyErr_WriteUnraisable.

sys._getframe, sys._getframemodulename,sys._current_frames, and construction of tracebacks also reify one or more PyFrameObject from interpreter frames.

All of the above ultimately use _PyFrame_GetFrameObject, which takes a _PyInterpreterFrame and returns a PyFrameObject.

A JIT that does not constantly maintain the full state of the executing _PyInterpreterFrame will need some way to be notified when a full PyFrameObject is needed for one of its frames, so that it can populate the frame object appropriately based on its own internal execution state.

I'd ideally like to find a solution here that will work both for Cinder JIT and for future faster-cpython JIT, even given their differing designs.

So, questions:

  1. Is the feature request sensible? Is there an entirely different way that a JIT should handle this?
  2. What shape should the API take? Perhaps the simplest possibility is a single interpreter-wide function pointer that can be set, whose default value is _PyFrame_GetFrameObject.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions