Skip to content

Commit 49d9a5e

Browse files
DinoVmeta-codesync[bot]
authored andcommitted
Force usage of CinderX interpreter loop when it's enabled for inline dispatch
Summary: In 3.12 we don't use the eval frame hook and instead have our own hook that we check. The normal eval frame hook is checked for before doing inline dispatch but we don't check for our special hook. This adds one special check in DISPATCH_INLINED and then has a couple of additional checks in the opcodes which set "return_offset" to something other than 0 - these need special treatment so we push them down the normal deopt path. Reviewed By: alexmalyshev Differential Revision: D97347966 fbshipit-source-id: d03cc7039b866c82a3f2b698bcee08f16915c9c4
1 parent caa98cb commit 49d9a5e

3 files changed

Lines changed: 375 additions & 362 deletions

File tree

Python/bytecodes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ dummy_func(
841841
Ci_PyAwaitable_SetAwaiter(receiver, (PyObject *) _PyFrame_GetGenerator(frame));
842842
}
843843
if ((tstate->interp->eval_frame == NULL) &&
844+
(Ci_hook_EvalFrame == NULL) &&
844845
(Py_TYPE(receiver) == &PyGen_Type || Py_TYPE(receiver) == &PyCoro_Type) &&
845846
((PyGenObject *)receiver)->gi_frame_state < FRAME_EXECUTING)
846847
{
@@ -878,7 +879,7 @@ dummy_func(
878879
}
879880

880881
inst(SEND_GEN, (unused/1, receiver, v -- receiver, unused)) {
881-
DEOPT_IF(tstate->interp->eval_frame, SEND);
882+
DEOPT_IF(tstate->interp->eval_frame || Ci_hook_EvalFrame, SEND);
882883
PyGenObject *gen = (PyGenObject *)receiver;
883884
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type &&
884885
Py_TYPE(gen) != &PyCoro_Type, SEND);
@@ -2527,7 +2528,7 @@ dummy_func(
25272528
}
25282529

25292530
inst(FOR_ITER_GEN, (unused/1, iter -- iter, unused)) {
2530-
DEOPT_IF(tstate->interp->eval_frame, FOR_ITER);
2531+
DEOPT_IF(tstate->interp->eval_frame || Ci_hook_EvalFrame, FOR_ITER);
25312532
PyGenObject *gen = (PyGenObject *)iter;
25322533
DEOPT_IF(Py_TYPE(gen) != &PyGen_Type, FOR_ITER);
25332534
DEOPT_IF(gen->gi_frame_state >= FRAME_EXECUTING, FOR_ITER);

Python/ceval_macros.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,21 @@
105105

106106
#define DISPATCH_INLINED(NEW_FRAME) \
107107
do { \
108-
assert(tstate->interp->eval_frame == NULL); \
109108
_PyFrame_SetStackPointer(frame, stack_pointer); \
110109
frame->prev_instr = next_instr - 1; \
111110
(NEW_FRAME)->previous = frame; \
111+
if (Ci_hook_EvalFrame != NULL) { \
112+
PyObject *_hook_result = Ci_hook_EvalFrame( \
113+
tstate, (NEW_FRAME), 0); \
114+
stack_pointer = \
115+
_PyFrame_GetStackPointer(frame); \
116+
if (_hook_result == NULL) { \
117+
goto error; \
118+
} \
119+
STACK_GROW(1); \
120+
SET_TOP(_hook_result); \
121+
DISPATCH(); \
122+
} \
112123
frame = cframe.current_frame = (NEW_FRAME); \
113124
CALL_STAT_INC(inlined_py_calls); \
114125
goto start_frame; \

0 commit comments

Comments
 (0)