Skip to content

Commit 2af2a91

Browse files
committed
Add guard for code object when projecting traces through calls
1 parent 392c520 commit 2af2a91

7 files changed

Lines changed: 124 additions & 100 deletions

File tree

Include/internal/pycore_uop_ids.h

Lines changed: 96 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,6 @@ dummy_func(
699699

700700
op(_BINARY_SUBSCR_INIT_CALL, (container, sub, getitem --new_frame: _PyInterpreterFrame* )) {
701701
new_frame = _PyFrame_PushUnchecked(tstate, (PyFunctionObject *)getitem, 2);
702-
SYNC_SP();
703702
new_frame->localsplus[0] = container;
704703
new_frame->localsplus[1] = sub;
705704
frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR);
@@ -4300,6 +4299,10 @@ dummy_func(
43004299
DEOPT_IF(!((_PyExecutorObject *)executor)->vm_data.valid);
43014300
}
43024301

4302+
tier2 op(_GUARD_CODE, (version/2 -- )) {
4303+
DEOPT_IF(((PyCodeObject *)frame->f_executable)->co_version != version);
4304+
}
4305+
43034306
tier2 op(_FATAL_ERROR, (--)) {
43044307
assert(0);
43054308
Py_FatalError("Fatal error uop executed.");

Python/executor_cases.c.h

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,13 @@ translate_bytecode_to_trace(
893893
operand = 0;
894894
}
895895
ADD_TO_TRACE(uop, oparg, operand, target);
896+
/* We need to guard that the runtime code object is
897+
* the same one we are projecting into */
896898
code = new_code;
897899
func = new_func;
898900
instr = _PyCode_CODE(code);
901+
assert(code->co_version != 0);
902+
ADD_TO_TRACE(_GUARD_CODE, 0, code->co_version, 0);
899903
DPRINTF(2,
900904
"Continuing in %s (%s:%d) at byte offset %d\n",
901905
PyUnicode_AsUTF8(code->co_qualname),

Python/optimizer_cases.c.h

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)