File tree 4 files changed +30
-3
lines changed
Filter options
4 files changed +30
-3
lines changed
Original file line number Diff line number Diff line change @@ -62,13 +62,14 @@ typedef struct _PyInterpreterFrame {
62
62
int stacktop ; /* Offset of TOS from localsplus */
63
63
uint16_t yield_offset ;
64
64
char owner ;
65
+ bool is_tier2 ;
65
66
/* Locals and stack and unboxed bit mask */
66
67
PyObject * localsplus [1 ];
67
68
} _PyInterpreterFrame ;
68
69
69
70
static inline int
70
71
_PyInterpreterFrame_LASTI (_PyInterpreterFrame * f ) {
71
- if (f -> f_code -> _tier2_info != NULL ) {
72
+ if (f -> is_tier2 && f -> f_code -> _tier2_info != NULL ) {
72
73
return ((int )((f )-> prev_instr - f -> f_code -> _tier2_info -> _bb_space -> u_code ));
73
74
}
74
75
return ((int )((f )-> prev_instr - _PyCode_CODE ((f )-> f_code )));
@@ -130,9 +131,11 @@ _PyFrame_Initialize(
130
131
frame -> stacktop = code -> co_nlocalsplus ;
131
132
frame -> frame_obj = NULL ;
132
133
if (code -> _tier2_info != NULL ) {
134
+ frame -> is_tier2 = true;
133
135
frame -> prev_instr = code -> _tier2_info -> _entry_bb -> tier2_start - 1 ;
134
136
}
135
137
else {
138
+ frame -> is_tier2 = false;
136
139
frame -> prev_instr = _PyCode_CODE (code ) - 1 ;
137
140
}
138
141
frame -> yield_offset = 0 ;
Original file line number Diff line number Diff line change @@ -17,10 +17,13 @@ _PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg)
17
17
Py_VISIT (frame -> f_code );
18
18
/* locals */
19
19
PyObject * * locals = _PyFrame_GetLocalsArray (frame );
20
+ char * unboxed_bitmask = _PyFrame_GetUnboxedBitMask (frame );
20
21
int i = 0 ;
21
22
/* locals and stack */
22
23
for (; i < frame -> stacktop ; i ++ ) {
23
- Py_VISIT (locals [i ]);
24
+ if (!unboxed_bitmask [i ]) {
25
+ Py_VISIT (locals [i ]);
26
+ }
24
27
}
25
28
return 0 ;
26
29
}
Original file line number Diff line number Diff line change @@ -2486,6 +2486,7 @@ _Py_CODEUNIT *
2486
2486
_PyCode_Tier2Warmup (_PyInterpreterFrame * frame , _Py_CODEUNIT * next_instr )
2487
2487
{
2488
2488
PyCodeObject * code = frame -> f_code ;
2489
+ frame -> is_tier2 = false;
2489
2490
if (code -> _tier2_warmup != 0 ) {
2490
2491
code -> _tier2_warmup ++ ;
2491
2492
if (code -> _tier2_warmup >= 0 ) {
@@ -2494,6 +2495,11 @@ _PyCode_Tier2Warmup(_PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr)
2494
2495
// just fall back to the tier 1 interpreter.
2495
2496
_Py_CODEUNIT * next = _PyCode_Tier2Initialize (frame , next_instr );
2496
2497
if (next != NULL ) {
2498
+ assert (!frame -> is_tier2 );
2499
+ frame -> is_tier2 = true;
2500
+ _Py_CODEUNIT * curr = (next_instr - 1 );
2501
+ assert (curr -> op .code == RESUME || curr -> op .code == RESUME_QUICK );
2502
+ curr -> op .code = RESUME_QUICK ;
2497
2503
return next ;
2498
2504
}
2499
2505
}
Original file line number Diff line number Diff line change @@ -519,7 +519,7 @@ def f(a):
519
519
######################################################################
520
520
# Tests for: Tier 2 recursive functions block generation #
521
521
######################################################################
522
- with TestInfo ("tier 2 BB_TEST_POP_IF_FALSE flag setting " ):
522
+ with TestInfo ("tier 2 recursive functions block generation " ):
523
523
# See https://github.com/pylbbv/pylbbv/issues/23 for more information.
524
524
def f (x ):
525
525
# Force specialisation
@@ -535,4 +535,19 @@ def f(x):
535
535
536
536
# As long as it doesn't crash, everything's good.
537
537
538
+ ######################################################################
539
+ # Tests for: Tier 2 specialisation in inner call #
540
+ ######################################################################
541
+ with TestInfo ("tier 2 specialisation in inner call" ):
542
+ # See https://github.com/pylbbv/pylbbv/issues/33 for more information.
543
+ def f (x ):
544
+ if x == 0 : return 0
545
+ if x % 2 : return f (x - 1 )
546
+ return f (x - 1 )
547
+
548
+ for i in range (15 ): f (3 )
549
+ f (3 )
550
+
551
+ # As long as it doesn't crash, everything's good.
552
+
538
553
print ("Tests completed ^-^" )
You can’t perform that action at this time.
0 commit comments