Skip to content

Commit 8ff9896

Browse files
Address review
1 parent 6c4f6db commit 8ff9896

7 files changed

Lines changed: 91 additions & 22 deletions

File tree

Include/internal/pycore_opcode_metadata.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.

Include/internal/pycore_uop_metadata.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.

Lib/test/test_capi/test_opt.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,67 @@ def __next__(self):
37923792
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
37933793
self.assertEqual(result[0].rc, 0, result)
37943794

3795+
def test_143820(self):
3796+
# https://github.com/python/cpython/issues/143358
3797+
3798+
result = script_helper.run_python_until_end('-c', textwrap.dedent(f"""
3799+
import sys
3800+
import random
3801+
3802+
int_v1 = 981679
3803+
int_v2 = -3791744241805517
3804+
any_v3 = 939.217
3805+
3806+
def f1(): int_v1 ^ int_v1
3807+
3808+
for i_f1 in range(300):
3809+
f1()
3810+
3811+
def f2():
3812+
class Int(int):
3813+
def __index__(self):...
3814+
3815+
inf = float('inf')
3816+
nzero = -0
3817+
zero = 0.0
3818+
dummy = 0
3819+
print('', file=sys.stderr)
3820+
3821+
def f_0_dc_6103(p): return p + 1
3822+
def f_1_dc_6103(p): return f_0_dc_6103(p) + 1
3823+
def f_2_dc_6103(p): return f_1_dc_6103(p) + 1
3824+
def f_3_dc_6103(p): return f_2_dc_6103(p) + 1
3825+
def f_4_dc_6103(p): return f_3_dc_6103(p) + 1
3826+
def f_5_dc_6103(p): return f_4_dc_6103(p) + 1
3827+
def f_6_dc_6103(p): return f_5_dc_6103(p) + 1
3828+
def f_7_dc_6103(p): return f_6_dc_6103(p) + 1
3829+
def f_8_dc_6103(p): return f_7_dc_6103(p) + 1
3830+
def f_9_dc_6103(p): return f_8_dc_6103(p) + 1
3831+
3832+
if inf == inf: dummy += 1
3833+
s = ''
3834+
try:
3835+
for _ in range(10):
3836+
s += ''
3837+
s += 'y'
3838+
except Exception: pass
3839+
int_v1 ^ int_v1
3840+
int_v1 ^ int_v1
3841+
int_v1 ^ int_v1
3842+
int_v2 - int_v1
3843+
int_v2 - int_v1
3844+
int_v2 - int_v1
3845+
int_v2 - int_v1
3846+
int_v2 - int_v1
3847+
not any_v3
3848+
not any_v3
3849+
not any_v3
3850+
3851+
for i_f2 in range(300):
3852+
f2()
3853+
"""), PYTHON_JIT="1", PYTHON_JIT_STRESS="1")
3854+
self.assertEqual(result[0].rc, 0, result)
3855+
37953856
def global_identity(x):
37963857
return x
37973858

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,15 @@
416416
assert(PyUnicode_CheckExact(PyStackRef_AsPyObjectBorrow(right)));
417417
int next_oparg;
418418
#if TIER_ONE
419-
assert(next_instr->op.code == STORE_FAST);
420419
next_oparg = next_instr->op.arg;
420+
#if _Py_TIER2
421+
422+
if (next_instr->op.code == ENTER_EXECUTOR) {
423+
_PyExecutorObject *exec = _PyFrame_GetCode(frame)->co_executors->executors[next_oparg];
424+
next_oparg = exec->vm_data.oparg;
425+
}
426+
#endif
427+
assert(next_instr->op.code == STORE_FAST || next_instr->op.code == ENTER_EXECUTOR);
421428
#else
422429
next_oparg = (int)CURRENT_OPERAND0_16();
423430
#endif

Python/bytecodes.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,16 @@ dummy_func(
783783

784784
int next_oparg;
785785
#if TIER_ONE
786-
#if _Py_TIER2
786+
next_oparg = next_instr->op.arg;
787+
#if _Py_TIER2
787788
// In JIT builds, we might have inserted an executor after this instruction,
788789
// which breaks this super instruction.
789-
DEOPT_IF(next_instr->op.code != STORE_FAST);
790-
#endif
791-
assert(next_instr->op.code == STORE_FAST);
792-
next_oparg = next_instr->op.arg;
790+
if (next_instr->op.code == ENTER_EXECUTOR) {
791+
_PyExecutorObject *exec = _PyFrame_GetCode(frame)->co_executors->executors[next_oparg];
792+
next_oparg = exec->vm_data.oparg;
793+
}
794+
#endif
795+
assert(next_instr->op.code == STORE_FAST || next_instr->op.code == ENTER_EXECUTOR);
793796
#else
794797
next_oparg = (int)CURRENT_OPERAND0_16();
795798
#endif

Python/executor_cases.c.h

Lines changed: 6 additions & 8 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: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)