@@ -88,17 +88,23 @@ dummy_func(void) {
8888 op (_LOAD_FAST , (-- value )) {
8989 value = GETLOCAL (oparg );
9090 PyObject * const_val = sym_get_const (ctx , value );
91- if (const_val != NULL && _Py_IsImmortal (const_val )) {
92- // Note: non-immortal is not safe to replace
93- // to _LOAD_CONST_INLINE, as it might not be held in co_const.
91+ PyCodeObject * co = get_current_code_object (ctx );
92+ // We don't reason about free variables yet, so we need to forbid
93+ // anything with those.
94+ if (const_val != NULL && co -> co_nfreevars == 0 ) {
95+ // It's safe to always borrow here, for
96+ // the same reason as _LOAD_CONST.
9497 REPLACE_OP (this_instr , _LOAD_CONST_INLINE_BORROW , 0 , (uintptr_t )const_val );
9598 }
9699 }
97100
98101 op (_LOAD_FAST_BORROW , (-- value )) {
99102 value = PyJitRef_Borrow (GETLOCAL (oparg ));
100103 PyObject * const_val = sym_get_const (ctx , value );
101- if (const_val != NULL ) {
104+ PyCodeObject * co = get_current_code_object (ctx );
105+ // We don't reason about free variables yet, so we need to forbid
106+ // anything with those.
107+ if (const_val != NULL && co -> co_nfreevars == 0 ) {
102108 // It's safe to always borrow here, because
103109 // _LOAD_FAST_BORROW guarantees it.
104110 REPLACE_OP (this_instr , _LOAD_CONST_INLINE_BORROW , 0 , (uintptr_t )const_val );
0 commit comments