From 52cd922bac260ca2ed5ce27d2435f734be3c70fd Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Fri, 9 Aug 2024 11:37:53 -0700 Subject: [PATCH] Don't end traces or check eval breakers on our stupid instruction --- Include/internal/pycore_uop_ids.h | 273 +++++++++++++------------ Include/internal/pycore_uop_metadata.h | 4 + Python/bytecodes.c | 14 +- Python/executor_cases.c.h | 16 ++ Python/generated_cases.c.h | 19 +- Python/optimizer.c | 5 + Python/optimizer_cases.c.h | 4 + 7 files changed, 190 insertions(+), 145 deletions(-) diff --git a/Include/internal/pycore_uop_ids.h b/Include/internal/pycore_uop_ids.h index 1951c65a2871cf..6f07fd3fd12981 100644 --- a/Include/internal/pycore_uop_ids.h +++ b/Include/internal/pycore_uop_ids.h @@ -72,81 +72,82 @@ extern "C" { #define _CHECK_PEP_523 342 #define _CHECK_PERIODIC 343 #define _CHECK_PERIODIC_IF_NOT_YIELD_FROM 344 -#define _CHECK_STACK_SPACE 345 -#define _CHECK_STACK_SPACE_OPERAND 346 -#define _CHECK_VALIDITY 347 -#define _CHECK_VALIDITY_AND_SET_IP 348 -#define _COMPARE_OP 349 -#define _COMPARE_OP_FLOAT 350 -#define _COMPARE_OP_INT 351 -#define _COMPARE_OP_STR 352 -#define _CONTAINS_OP 353 +#define _CHECK_PERIODIC_IF_OPARG 345 +#define _CHECK_STACK_SPACE 346 +#define _CHECK_STACK_SPACE_OPERAND 347 +#define _CHECK_VALIDITY 348 +#define _CHECK_VALIDITY_AND_SET_IP 349 +#define _COMPARE_OP 350 +#define _COMPARE_OP_FLOAT 351 +#define _COMPARE_OP_INT 352 +#define _COMPARE_OP_STR 353 +#define _CONTAINS_OP 354 #define _CONTAINS_OP_DICT CONTAINS_OP_DICT #define _CONTAINS_OP_SET CONTAINS_OP_SET #define _CONVERT_VALUE CONVERT_VALUE #define _COPY COPY #define _COPY_FREE_VARS COPY_FREE_VARS -#define _CREATE_INIT_FRAME 354 +#define _CREATE_INIT_FRAME 355 #define _DELETE_ATTR DELETE_ATTR #define _DELETE_DEREF DELETE_DEREF #define _DELETE_FAST DELETE_FAST #define _DELETE_GLOBAL DELETE_GLOBAL #define _DELETE_NAME DELETE_NAME #define _DELETE_SUBSCR DELETE_SUBSCR -#define _DEOPT 355 +#define _DEOPT 356 #define _DICT_MERGE DICT_MERGE #define _DICT_UPDATE DICT_UPDATE -#define _DO_CALL 356 -#define _DO_CALL_FUNCTION_EX 357 -#define _DO_CALL_KW 358 -#define _DYNAMIC_EXIT 359 +#define _DO_CALL 357 +#define _DO_CALL_FUNCTION_EX 358 +#define _DO_CALL_KW 359 +#define _DYNAMIC_EXIT 360 #define _END_SEND END_SEND -#define _ERROR_POP_N 360 +#define _ERROR_POP_N 361 #define _EXIT_INIT_CHECK EXIT_INIT_CHECK -#define _EXPAND_METHOD 361 -#define _EXPAND_METHOD_KW 362 -#define _FATAL_ERROR 363 +#define _EXPAND_METHOD 362 +#define _EXPAND_METHOD_KW 363 +#define _FATAL_ERROR 364 #define _FORMAT_SIMPLE FORMAT_SIMPLE #define _FORMAT_WITH_SPEC FORMAT_WITH_SPEC -#define _FOR_ITER 364 -#define _FOR_ITER_GEN_FRAME 365 -#define _FOR_ITER_TIER_TWO 366 +#define _FOR_ITER 365 +#define _FOR_ITER_GEN_FRAME 366 +#define _FOR_ITER_TIER_TWO 367 #define _GET_AITER GET_AITER #define _GET_ANEXT GET_ANEXT #define _GET_AWAITABLE GET_AWAITABLE #define _GET_ITER GET_ITER #define _GET_LEN GET_LEN #define _GET_YIELD_FROM_ITER GET_YIELD_FROM_ITER -#define _GUARD_BOTH_FLOAT 367 -#define _GUARD_BOTH_INT 368 -#define _GUARD_BOTH_UNICODE 369 -#define _GUARD_BUILTINS_VERSION_PUSH_KEYS 370 -#define _GUARD_DORV_NO_DICT 371 -#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 372 -#define _GUARD_GLOBALS_VERSION 373 -#define _GUARD_GLOBALS_VERSION_PUSH_KEYS 374 -#define _GUARD_IS_FALSE_POP 375 -#define _GUARD_IS_NONE_POP 376 -#define _GUARD_IS_NOT_NONE_POP 377 -#define _GUARD_IS_TRUE_POP 378 -#define _GUARD_KEYS_VERSION 379 -#define _GUARD_NOS_FLOAT 380 -#define _GUARD_NOS_INT 381 -#define _GUARD_NOT_EXHAUSTED_LIST 382 -#define _GUARD_NOT_EXHAUSTED_RANGE 383 -#define _GUARD_NOT_EXHAUSTED_TUPLE 384 -#define _GUARD_TOS_FLOAT 385 -#define _GUARD_TOS_INT 386 -#define _GUARD_TYPE_VERSION 387 +#define _GUARD_BOTH_FLOAT 368 +#define _GUARD_BOTH_INT 369 +#define _GUARD_BOTH_UNICODE 370 +#define _GUARD_BUILTINS_VERSION_PUSH_KEYS 371 +#define _GUARD_DORV_NO_DICT 372 +#define _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT 373 +#define _GUARD_GLOBALS_VERSION 374 +#define _GUARD_GLOBALS_VERSION_PUSH_KEYS 375 +#define _GUARD_IS_FALSE_POP 376 +#define _GUARD_IS_NONE_POP 377 +#define _GUARD_IS_NOT_NONE_POP 378 +#define _GUARD_IS_TRUE_POP 379 +#define _GUARD_KEYS_VERSION 380 +#define _GUARD_NOS_FLOAT 381 +#define _GUARD_NOS_INT 382 +#define _GUARD_NOT_EXHAUSTED_LIST 383 +#define _GUARD_NOT_EXHAUSTED_RANGE 384 +#define _GUARD_NOT_EXHAUSTED_TUPLE 385 +#define _GUARD_TOS_FLOAT 386 +#define _GUARD_TOS_INT 387 +#define _GUARD_TYPE_VERSION 388 #define _IMPORT_FROM IMPORT_FROM #define _IMPORT_NAME IMPORT_NAME -#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 388 -#define _INIT_CALL_PY_EXACT_ARGS 389 -#define _INIT_CALL_PY_EXACT_ARGS_0 390 -#define _INIT_CALL_PY_EXACT_ARGS_1 391 -#define _INIT_CALL_PY_EXACT_ARGS_2 392 -#define _INIT_CALL_PY_EXACT_ARGS_3 393 -#define _INIT_CALL_PY_EXACT_ARGS_4 394 +#define _INIT_CALL_BOUND_METHOD_EXACT_ARGS 389 +#define _INIT_CALL_PY_EXACT_ARGS 390 +#define _INIT_CALL_PY_EXACT_ARGS_0 391 +#define _INIT_CALL_PY_EXACT_ARGS_1 392 +#define _INIT_CALL_PY_EXACT_ARGS_2 393 +#define _INIT_CALL_PY_EXACT_ARGS_3 394 +#define _INIT_CALL_PY_EXACT_ARGS_4 395 #define _INSTRUMENTED_CALL_FUNCTION_EX INSTRUMENTED_CALL_FUNCTION_EX #define _INSTRUMENTED_CALL_KW INSTRUMENTED_CALL_KW #define _INSTRUMENTED_FOR_ITER INSTRUMENTED_FOR_ITER @@ -158,135 +159,135 @@ extern "C" { #define _INSTRUMENTED_POP_JUMP_IF_NONE INSTRUMENTED_POP_JUMP_IF_NONE #define _INSTRUMENTED_POP_JUMP_IF_NOT_NONE INSTRUMENTED_POP_JUMP_IF_NOT_NONE #define _INSTRUMENTED_POP_JUMP_IF_TRUE INSTRUMENTED_POP_JUMP_IF_TRUE -#define _INTERNAL_INCREMENT_OPT_COUNTER 395 -#define _IS_NONE 396 +#define _INTERNAL_INCREMENT_OPT_COUNTER 396 +#define _IS_NONE 397 #define _IS_OP IS_OP -#define _ITER_CHECK_LIST 397 -#define _ITER_CHECK_RANGE 398 -#define _ITER_CHECK_TUPLE 399 -#define _ITER_JUMP_LIST 400 -#define _ITER_JUMP_RANGE 401 -#define _ITER_JUMP_TUPLE 402 -#define _ITER_NEXT_LIST 403 -#define _ITER_NEXT_RANGE 404 -#define _ITER_NEXT_TUPLE 405 -#define _JUMP_TO_TOP 406 +#define _ITER_CHECK_LIST 398 +#define _ITER_CHECK_RANGE 399 +#define _ITER_CHECK_TUPLE 400 +#define _ITER_JUMP_LIST 401 +#define _ITER_JUMP_RANGE 402 +#define _ITER_JUMP_TUPLE 403 +#define _ITER_NEXT_LIST 404 +#define _ITER_NEXT_RANGE 405 +#define _ITER_NEXT_TUPLE 406 +#define _JUMP_TO_TOP 407 #define _LIST_APPEND LIST_APPEND #define _LIST_EXTEND LIST_EXTEND -#define _LOAD_ATTR 407 -#define _LOAD_ATTR_CLASS 408 -#define _LOAD_ATTR_CLASS_0 409 -#define _LOAD_ATTR_CLASS_1 410 +#define _LOAD_ATTR 408 +#define _LOAD_ATTR_CLASS 409 +#define _LOAD_ATTR_CLASS_0 410 +#define _LOAD_ATTR_CLASS_1 411 #define _LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN -#define _LOAD_ATTR_INSTANCE_VALUE 411 -#define _LOAD_ATTR_INSTANCE_VALUE_0 412 -#define _LOAD_ATTR_INSTANCE_VALUE_1 413 -#define _LOAD_ATTR_METHOD_LAZY_DICT 414 -#define _LOAD_ATTR_METHOD_NO_DICT 415 -#define _LOAD_ATTR_METHOD_WITH_VALUES 416 -#define _LOAD_ATTR_MODULE 417 -#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 418 -#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 419 -#define _LOAD_ATTR_PROPERTY_FRAME 420 -#define _LOAD_ATTR_SLOT 421 -#define _LOAD_ATTR_SLOT_0 422 -#define _LOAD_ATTR_SLOT_1 423 -#define _LOAD_ATTR_WITH_HINT 424 +#define _LOAD_ATTR_INSTANCE_VALUE 412 +#define _LOAD_ATTR_INSTANCE_VALUE_0 413 +#define _LOAD_ATTR_INSTANCE_VALUE_1 414 +#define _LOAD_ATTR_METHOD_LAZY_DICT 415 +#define _LOAD_ATTR_METHOD_NO_DICT 416 +#define _LOAD_ATTR_METHOD_WITH_VALUES 417 +#define _LOAD_ATTR_MODULE 418 +#define _LOAD_ATTR_NONDESCRIPTOR_NO_DICT 419 +#define _LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES 420 +#define _LOAD_ATTR_PROPERTY_FRAME 421 +#define _LOAD_ATTR_SLOT 422 +#define _LOAD_ATTR_SLOT_0 423 +#define _LOAD_ATTR_SLOT_1 424 +#define _LOAD_ATTR_WITH_HINT 425 #define _LOAD_BUILD_CLASS LOAD_BUILD_CLASS #define _LOAD_COMMON_CONSTANT LOAD_COMMON_CONSTANT #define _LOAD_CONST LOAD_CONST -#define _LOAD_CONST_INLINE 425 -#define _LOAD_CONST_INLINE_BORROW 426 -#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 427 -#define _LOAD_CONST_INLINE_WITH_NULL 428 +#define _LOAD_CONST_INLINE 426 +#define _LOAD_CONST_INLINE_BORROW 427 +#define _LOAD_CONST_INLINE_BORROW_WITH_NULL 428 +#define _LOAD_CONST_INLINE_WITH_NULL 429 #define _LOAD_DEREF LOAD_DEREF -#define _LOAD_FAST 429 -#define _LOAD_FAST_0 430 -#define _LOAD_FAST_1 431 -#define _LOAD_FAST_2 432 -#define _LOAD_FAST_3 433 -#define _LOAD_FAST_4 434 -#define _LOAD_FAST_5 435 -#define _LOAD_FAST_6 436 -#define _LOAD_FAST_7 437 +#define _LOAD_FAST 430 +#define _LOAD_FAST_0 431 +#define _LOAD_FAST_1 432 +#define _LOAD_FAST_2 433 +#define _LOAD_FAST_3 434 +#define _LOAD_FAST_4 435 +#define _LOAD_FAST_5 436 +#define _LOAD_FAST_6 437 +#define _LOAD_FAST_7 438 #define _LOAD_FAST_AND_CLEAR LOAD_FAST_AND_CLEAR #define _LOAD_FAST_CHECK LOAD_FAST_CHECK #define _LOAD_FAST_LOAD_FAST LOAD_FAST_LOAD_FAST #define _LOAD_FROM_DICT_OR_DEREF LOAD_FROM_DICT_OR_DEREF #define _LOAD_FROM_DICT_OR_GLOBALS LOAD_FROM_DICT_OR_GLOBALS -#define _LOAD_GLOBAL 438 -#define _LOAD_GLOBAL_BUILTINS 439 -#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 440 -#define _LOAD_GLOBAL_MODULE 441 -#define _LOAD_GLOBAL_MODULE_FROM_KEYS 442 +#define _LOAD_GLOBAL 439 +#define _LOAD_GLOBAL_BUILTINS 440 +#define _LOAD_GLOBAL_BUILTINS_FROM_KEYS 441 +#define _LOAD_GLOBAL_MODULE 442 +#define _LOAD_GLOBAL_MODULE_FROM_KEYS 443 #define _LOAD_LOCALS LOAD_LOCALS #define _LOAD_NAME LOAD_NAME #define _LOAD_SPECIAL LOAD_SPECIAL #define _LOAD_SUPER_ATTR_ATTR LOAD_SUPER_ATTR_ATTR #define _LOAD_SUPER_ATTR_METHOD LOAD_SUPER_ATTR_METHOD -#define _MAKE_CALLARGS_A_TUPLE 443 +#define _MAKE_CALLARGS_A_TUPLE 444 #define _MAKE_CELL MAKE_CELL #define _MAKE_FUNCTION MAKE_FUNCTION -#define _MAKE_WARM 444 +#define _MAKE_WARM 445 #define _MAP_ADD MAP_ADD #define _MATCH_CLASS MATCH_CLASS #define _MATCH_KEYS MATCH_KEYS #define _MATCH_MAPPING MATCH_MAPPING #define _MATCH_SEQUENCE MATCH_SEQUENCE -#define _MAYBE_EXPAND_METHOD 445 -#define _MAYBE_EXPAND_METHOD_KW 446 -#define _MONITOR_CALL 447 -#define _MONITOR_JUMP_BACKWARD 448 -#define _MONITOR_RESUME 449 +#define _MAYBE_EXPAND_METHOD 446 +#define _MAYBE_EXPAND_METHOD_KW 447 +#define _MONITOR_CALL 448 +#define _MONITOR_JUMP_BACKWARD 449 +#define _MONITOR_RESUME 450 #define _NOP NOP #define _POP_EXCEPT POP_EXCEPT -#define _POP_JUMP_IF_FALSE 450 -#define _POP_JUMP_IF_TRUE 451 +#define _POP_JUMP_IF_FALSE 451 +#define _POP_JUMP_IF_TRUE 452 #define _POP_TOP POP_TOP -#define _POP_TOP_LOAD_CONST_INLINE_BORROW 452 +#define _POP_TOP_LOAD_CONST_INLINE_BORROW 453 #define _PUSH_EXC_INFO PUSH_EXC_INFO -#define _PUSH_FRAME 453 +#define _PUSH_FRAME 454 #define _PUSH_NULL PUSH_NULL -#define _PY_FRAME_GENERAL 454 -#define _PY_FRAME_KW 455 -#define _QUICKEN_RESUME 456 -#define _REPLACE_WITH_TRUE 457 +#define _PY_FRAME_GENERAL 455 +#define _PY_FRAME_KW 456 +#define _QUICKEN_RESUME 457 +#define _REPLACE_WITH_TRUE 458 #define _RESUME_CHECK RESUME_CHECK #define _RETURN_GENERATOR RETURN_GENERATOR #define _RETURN_VALUE RETURN_VALUE -#define _SAVE_RETURN_OFFSET 458 -#define _SEND 459 -#define _SEND_GEN_FRAME 460 +#define _SAVE_RETURN_OFFSET 459 +#define _SEND 460 +#define _SEND_GEN_FRAME 461 #define _SETUP_ANNOTATIONS SETUP_ANNOTATIONS #define _SET_ADD SET_ADD #define _SET_FUNCTION_ATTRIBUTE SET_FUNCTION_ATTRIBUTE #define _SET_UPDATE SET_UPDATE -#define _START_EXECUTOR 461 -#define _STORE_ATTR 462 -#define _STORE_ATTR_INSTANCE_VALUE 463 -#define _STORE_ATTR_SLOT 464 -#define _STORE_ATTR_WITH_HINT 465 +#define _START_EXECUTOR 462 +#define _STORE_ATTR 463 +#define _STORE_ATTR_INSTANCE_VALUE 464 +#define _STORE_ATTR_SLOT 465 +#define _STORE_ATTR_WITH_HINT 466 #define _STORE_DEREF STORE_DEREF -#define _STORE_FAST 466 -#define _STORE_FAST_0 467 -#define _STORE_FAST_1 468 -#define _STORE_FAST_2 469 -#define _STORE_FAST_3 470 -#define _STORE_FAST_4 471 -#define _STORE_FAST_5 472 -#define _STORE_FAST_6 473 -#define _STORE_FAST_7 474 +#define _STORE_FAST 467 +#define _STORE_FAST_0 468 +#define _STORE_FAST_1 469 +#define _STORE_FAST_2 470 +#define _STORE_FAST_3 471 +#define _STORE_FAST_4 472 +#define _STORE_FAST_5 473 +#define _STORE_FAST_6 474 +#define _STORE_FAST_7 475 #define _STORE_FAST_LOAD_FAST STORE_FAST_LOAD_FAST #define _STORE_FAST_STORE_FAST STORE_FAST_STORE_FAST #define _STORE_GLOBAL STORE_GLOBAL #define _STORE_NAME STORE_NAME -#define _STORE_SLICE 475 -#define _STORE_SUBSCR 476 +#define _STORE_SLICE 476 +#define _STORE_SUBSCR 477 #define _STORE_SUBSCR_DICT STORE_SUBSCR_DICT #define _STORE_SUBSCR_LIST_INT STORE_SUBSCR_LIST_INT #define _SWAP SWAP -#define _TIER2_RESUME_CHECK 477 -#define _TO_BOOL 478 +#define _TIER2_RESUME_CHECK 478 +#define _TO_BOOL 479 #define _TO_BOOL_BOOL TO_BOOL_BOOL #define _TO_BOOL_INT TO_BOOL_INT #define _TO_BOOL_LIST TO_BOOL_LIST @@ -296,13 +297,13 @@ extern "C" { #define _UNARY_NEGATIVE UNARY_NEGATIVE #define _UNARY_NOT UNARY_NOT #define _UNPACK_EX UNPACK_EX -#define _UNPACK_SEQUENCE 479 +#define _UNPACK_SEQUENCE 480 #define _UNPACK_SEQUENCE_LIST UNPACK_SEQUENCE_LIST #define _UNPACK_SEQUENCE_TUPLE UNPACK_SEQUENCE_TUPLE #define _UNPACK_SEQUENCE_TWO_TUPLE UNPACK_SEQUENCE_TWO_TUPLE #define _WITH_EXCEPT_START WITH_EXCEPT_START #define _YIELD_VALUE YIELD_VALUE -#define MAX_UOP_ID 479 +#define MAX_UOP_ID 480 #ifdef __cplusplus } diff --git a/Include/internal/pycore_uop_metadata.h b/Include/internal/pycore_uop_metadata.h index 2f0a7fb2f6e549..a0355d2c2c0cb8 100644 --- a/Include/internal/pycore_uop_metadata.h +++ b/Include/internal/pycore_uop_metadata.h @@ -21,6 +21,7 @@ extern int _PyUop_num_popped(int opcode, int oparg); const uint16_t _PyUop_Flags[MAX_UOP_ID+1] = { [_NOP] = HAS_PURE_FLAG, [_CHECK_PERIODIC] = HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, + [_CHECK_PERIODIC_IF_OPARG] = HAS_ARG_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_CHECK_PERIODIC_IF_NOT_YIELD_FROM] = HAS_ARG_FLAG | HAS_EVAL_BREAK_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, [_RESUME_CHECK] = HAS_DEOPT_FLAG, [_LOAD_FAST_CHECK] = HAS_ARG_FLAG | HAS_LOCAL_FLAG | HAS_ERROR_FLAG | HAS_ESCAPES_FLAG, @@ -355,6 +356,7 @@ const char *const _PyOpcode_uop_name[MAX_UOP_ID+1] = { [_CHECK_PEP_523] = "_CHECK_PEP_523", [_CHECK_PERIODIC] = "_CHECK_PERIODIC", [_CHECK_PERIODIC_IF_NOT_YIELD_FROM] = "_CHECK_PERIODIC_IF_NOT_YIELD_FROM", + [_CHECK_PERIODIC_IF_OPARG] = "_CHECK_PERIODIC_IF_OPARG", [_CHECK_STACK_SPACE] = "_CHECK_STACK_SPACE", [_CHECK_STACK_SPACE_OPERAND] = "_CHECK_STACK_SPACE_OPERAND", [_CHECK_VALIDITY] = "_CHECK_VALIDITY", @@ -568,6 +570,8 @@ int _PyUop_num_popped(int opcode, int oparg) return 0; case _CHECK_PERIODIC: return 0; + case _CHECK_PERIODIC_IF_OPARG: + return 0; case _CHECK_PERIODIC_IF_NOT_YIELD_FROM: return 0; case _RESUME_CHECK: diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 3e45c0c7253ab2..2d66d7f6773e4b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -156,6 +156,18 @@ dummy_func( } } + op(_CHECK_PERIODIC_IF_OPARG, (--)) { + (void)oparg; // XXX: Cases generator hangs without this? + if (oparg) { + _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); + QSBR_QUIESCENT_STATE(tstate); + if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) { + int err = _Py_HandlePending(tstate); + ERROR_IF(err != 0, error); + } + } + } + op(_CHECK_PERIODIC_IF_NOT_YIELD_FROM, (--)) { if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) { _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); @@ -2611,7 +2623,7 @@ dummy_func( } macro(JUMP_BACKWARD) = - _CHECK_PERIODIC + + _CHECK_PERIODIC_IF_OPARG + _JUMP_BACKWARD; pseudo(JUMP, (--)) = { diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index c359745f0c0930..0fc05670c5c518 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -24,6 +24,22 @@ break; } + case _CHECK_PERIODIC_IF_OPARG: { + oparg = CURRENT_OPARG(); + (void)oparg; // XXX: Cases generator hangs without this? + if (oparg) { + _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); + QSBR_QUIESCENT_STATE(tstate); + if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) { + _PyFrame_SetStackPointer(frame, stack_pointer); + int err = _Py_HandlePending(tstate); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (err != 0) JUMP_TO_ERROR(); + } + } + break; + } + case _CHECK_PERIODIC_IF_NOT_YIELD_FROM: { oparg = CURRENT_OPARG(); if ((oparg & RESUME_OPARG_LOCATION_MASK) < RESUME_AFTER_YIELD_FROM) { diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index efbf2fba8c3106..a4dd712f3cc198 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -5095,15 +5095,18 @@ (void)this_instr; next_instr += 2; INSTRUCTION_STATS(JUMP_BACKWARD); - // _CHECK_PERIODIC + // _CHECK_PERIODIC_IF_OPARG { - _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); - QSBR_QUIESCENT_STATE(tstate); - if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) { - _PyFrame_SetStackPointer(frame, stack_pointer); - int err = _Py_HandlePending(tstate); - stack_pointer = _PyFrame_GetStackPointer(frame); - if (err != 0) goto error; + (void)oparg; // XXX: Cases generator hangs without this? + if (oparg) { + _Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY(); + QSBR_QUIESCENT_STATE(tstate); + if (_Py_atomic_load_uintptr_relaxed(&tstate->eval_breaker) & _PY_EVAL_EVENTS_MASK) { + _PyFrame_SetStackPointer(frame, stack_pointer); + int err = _Py_HandlePending(tstate); + stack_pointer = _PyFrame_GetStackPointer(frame); + if (err != 0) goto error; + } } } // _JUMP_BACKWARD diff --git a/Python/optimizer.c b/Python/optimizer.c index b876b6c2bd72fd..4cb748acffb853 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -607,6 +607,10 @@ translate_bytecode_to_trace( // what we do here: goto done; } + if (opcode == JUMP_BACKWARD && oparg == 0) { + instr += 1 + _PyOpcode_Caches[JUMP_BACKWARD]; + goto top; + } assert(opcode != ENTER_EXECUTOR && opcode != EXTENDED_ARG); RESERVE_RAW(2, "_CHECK_VALIDITY_AND_SET_IP"); ADD_TO_TRACE(_CHECK_VALIDITY_AND_SET_IP, 0, (uintptr_t)instr, target); @@ -673,6 +677,7 @@ translate_bytecode_to_trace( } case JUMP_BACKWARD: + assert(oparg); ADD_TO_TRACE(_CHECK_PERIODIC, 0, 0, target); _Py_FALLTHROUGH; case JUMP_BACKWARD_NO_INTERRUPT: diff --git a/Python/optimizer_cases.c.h b/Python/optimizer_cases.c.h index 6ec9e69d1dbc44..ba7df39aabfa51 100644 --- a/Python/optimizer_cases.c.h +++ b/Python/optimizer_cases.c.h @@ -11,6 +11,10 @@ break; } + case _CHECK_PERIODIC_IF_OPARG: { + break; + } + case _CHECK_PERIODIC_IF_NOT_YIELD_FROM: { break; }