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:
- Is the feature request sensible? Is there an entirely different way that a JIT should handle this?
- 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.
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_GetFrameandPyThreadState_GetFrame, which return a fullPyFrameObjectfor the current interpreter frame, are public C API.PyThreadState_GetFrameis used internally by thecoroutine_origin_tracking_depthfeature and byPyErr_WriteUnraisable.sys._getframe,sys._getframemodulename,sys._current_frames, and construction of tracebacks also reify one or morePyFrameObjectfrom interpreter frames.All of the above ultimately use
_PyFrame_GetFrameObject, which takes a_PyInterpreterFrameand returns aPyFrameObject.A JIT that does not constantly maintain the full state of the executing
_PyInterpreterFramewill need some way to be notified when a fullPyFrameObjectis 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:
_PyFrame_GetFrameObject.