@@ -34,7 +34,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
3434#define sym_new_tuple _Py_uop_sym_new_tuple
3535#define sym_tuple_getitem _Py_uop_sym_tuple_getitem
3636#define sym_tuple_length _Py_uop_sym_tuple_length
37- #define sym_is_immortal _Py_uop_sym_is_immortal
37+ #define sym_is_immortal _Py_uop_symbol_is_immortal
3838#define sym_new_compact_int _Py_uop_sym_new_compact_int
3939#define sym_is_compact_int _Py_uop_sym_is_compact_int
4040#define sym_new_truthiness _Py_uop_sym_new_truthiness
@@ -534,15 +534,15 @@ dummy_func(void) {
534534 }
535535
536536 op (_LOAD_CONST_INLINE , (ptr /4 -- value )) {
537- value = PyJitRef_Borrow ( sym_new_const (ctx , ptr ) );
537+ value = sym_new_const (ctx , ptr );
538538 }
539539
540540 op (_LOAD_CONST_INLINE_BORROW , (ptr /4 -- value )) {
541541 value = PyJitRef_Borrow (sym_new_const (ctx , ptr ));
542542 }
543543
544544 op (_POP_TOP_LOAD_CONST_INLINE , (ptr /4 , pop -- value )) {
545- value = PyJitRef_Borrow ( sym_new_const (ctx , ptr ) );
545+ value = sym_new_const (ctx , ptr );
546546 }
547547
548548 op (_POP_TOP_LOAD_CONST_INLINE_BORROW , (ptr /4 , pop -- value )) {
@@ -561,6 +561,24 @@ dummy_func(void) {
561561 value = PyJitRef_Borrow (sym_new_const (ctx , ptr ));
562562 }
563563
564+ op (_POP_TOP , (value -- )) {
565+ PyTypeObject * typ = sym_get_type (value );
566+ if (PyJitRef_IsBorrowed (value ) ||
567+ sym_is_immortal (PyJitRef_Unwrap (value )) ||
568+ sym_is_null (value )) {
569+ REPLACE_OP (this_instr , _POP_TOP_NOP , 0 , 0 );
570+ }
571+ else if (typ == & PyLong_Type ) {
572+ REPLACE_OP (this_instr , _POP_TOP_INT , 0 , 0 );
573+ }
574+ else if (typ == & PyFloat_Type ) {
575+ REPLACE_OP (this_instr , _POP_TOP_FLOAT , 0 , 0 );
576+ }
577+ else if (typ == & PyUnicode_Type ) {
578+ REPLACE_OP (this_instr , _POP_TOP_UNICODE , 0 , 0 );
579+ }
580+ }
581+
564582 op (_COPY , (bottom , unused [oparg - 1 ] -- bottom , unused [oparg - 1 ], top )) {
565583 assert (oparg > 0 );
566584 top = bottom ;
@@ -803,7 +821,9 @@ dummy_func(void) {
803821 }
804822
805823 op (_RETURN_VALUE , (retval -- res )) {
806- JitOptRef temp = retval ;
824+ // We wrap and unwrap the value to mimic PyStackRef_MakeHeapSafe
825+ // in bytecodes.c
826+ JitOptRef temp = PyJitRef_Wrap (PyJitRef_Unwrap (retval ));
807827 DEAD (retval );
808828 SAVE_STACK ();
809829 ctx -> frame -> stack_pointer = stack_pointer ;
0 commit comments