@@ -113,12 +113,17 @@ _PyTier2TypeContext_Copy(const _PyTier2TypeContext *type_context)
113
113
_Py_TYPENODE_t * parent = (_Py_TYPENODE_t * )_Py_TYPENODE_CLEAR_TAG (node );
114
114
115
115
// Check if part of locals
116
- if (parent - type_context -> type_locals < nlocals ) {
117
- type_locals [i ] = node - (uintptr_t )orig_type_locals + (uintptr_t )type_locals ;
116
+ int offset_locals = (int )(parent - type_context -> type_locals );
117
+ if (0 <= offset_locals && offset_locals < nlocals ) {
118
+ type_locals [i ] = _Py_TYPENODE_MAKE_REF ((_Py_TYPENODE_t )(& type_locals [offset_locals ]));
118
119
}
119
120
// Is part of stack
120
121
else {
121
- type_locals [i ] = node - (uintptr_t )orig_type_stack + (uintptr_t )type_stack ;
122
+ #if TYPEPROP_DEBUG
123
+ int offset_stack = (int )(parent - type_context -> type_stack );
124
+ assert (0 <= offset_stack && offset_stack < nstack );
125
+ #endif
126
+ type_locals [i ] = _Py_TYPENODE_MAKE_REF ((_Py_TYPENODE_t )(& type_stack [offset_stack ]));
122
127
}
123
128
break ;
124
129
}
@@ -139,12 +144,17 @@ _PyTier2TypeContext_Copy(const _PyTier2TypeContext *type_context)
139
144
_Py_TYPENODE_t * parent = (_Py_TYPENODE_t * )_Py_TYPENODE_CLEAR_TAG (node );
140
145
141
146
// Check if part of locals
142
- if (parent - type_context -> type_locals < nlocals ) {
143
- type_stack [i ] = node - (uintptr_t )orig_type_locals + (uintptr_t )type_locals ;
147
+ int plocals = (int )(parent - type_context -> type_locals );
148
+ if (0 <= plocals && plocals < nlocals ) {
149
+ type_stack [i ] = _Py_TYPENODE_MAKE_REF ((_Py_TYPENODE_t )(& type_locals [plocals ]));
144
150
}
145
151
// Is part of stack
146
152
else {
147
- type_stack [i ] = node - (uintptr_t )orig_type_stack + (uintptr_t )type_stack ;
153
+ #if TYPEPROP_DEBUG
154
+ int offset_stack = (int )(parent - type_context -> type_stack );
155
+ assert (0 <= offset_stack && offset_stack < nstack );
156
+ #endif
157
+ type_stack [i ] = _Py_TYPENODE_MAKE_REF ((_Py_TYPENODE_t )(& type_stack [offset_stack ]));
148
158
}
149
159
break ;
150
160
}
@@ -394,23 +404,62 @@ print_typestack(const _PyTier2TypeContext *type_context)
394
404
395
405
int nstack_use = (int )(type_stackptr - type_stack );
396
406
int nstack = type_context -> type_stack_len ;
407
+ int nlocals = type_context -> type_locals_len ;
408
+
409
+ int plocals = 0 ;
410
+ int pstack = 0 ;
411
+ bool is_local = false;
412
+
397
413
fprintf (stderr , " Stack: %p: [" , type_stack );
398
414
for (int i = 0 ; i < nstack ; i ++ ) {
399
- PyTypeObject * type = typenode_get_type (type_stack [i ]);
400
- _Py_TYPENODE_t tag = _Py_TYPENODE_GET_TAG (type_stack [i ]);
401
- fprintf (stderr , "%s%s%s" ,
415
+ _Py_TYPENODE_t node = type_stack [i ];
416
+ PyTypeObject * type = typenode_get_type (node );
417
+ _Py_TYPENODE_t tag = _Py_TYPENODE_GET_TAG (node );
418
+
419
+ if (tag == TYPE_REF ) {
420
+ _Py_TYPENODE_t * parent = (_Py_TYPENODE_t * )(_Py_TYPENODE_CLEAR_TAG (node ));
421
+ plocals = (int )(parent - type_context -> type_locals );
422
+ pstack = (int )(parent - type_context -> type_stack );
423
+ is_local = (0 <= plocals ) && (plocals < nlocals );
424
+ if (!is_local ) {
425
+ assert ((0 <= pstack ) && (pstack < nstack ));
426
+ }
427
+ }
428
+
429
+ fprintf (stderr , "%s%s" ,
402
430
i == nstack_use ? "." : " " ,
403
- type == NULL ? "?" : type -> tp_name ,
404
- tag == TYPE_REF ? "*" : "" );
431
+ type == NULL ? "?" : type -> tp_name );
432
+ if (tag == TYPE_REF ) {
433
+ fprintf (stderr , "%s%d]" ,
434
+ is_local ? "->locals[" : "->stack[" ,
435
+ is_local ? plocals : pstack );
436
+ }
405
437
}
406
438
fprintf (stderr , "]\n" );
439
+
407
440
fprintf (stderr , " Locals %p: [" , type_locals );
408
- for (int i = 0 ; i < type_context -> type_locals_len ; i ++ ) {
409
- PyTypeObject * type = typenode_get_type (type_locals [i ]);
410
- _Py_TYPENODE_t tag = _Py_TYPENODE_GET_TAG (type_locals [i ]);
411
- fprintf (stderr , "%s%s " ,
412
- type == NULL ? "?" : type -> tp_name ,
413
- tag == TYPE_REF ? "*" : "" );
441
+ for (int i = 0 ; i < nlocals ; i ++ ) {
442
+ _Py_TYPENODE_t node = type_locals [i ];
443
+ PyTypeObject * type = typenode_get_type (node );
444
+ _Py_TYPENODE_t tag = _Py_TYPENODE_GET_TAG (node );
445
+
446
+ if (tag == TYPE_REF ) {
447
+ _Py_TYPENODE_t * parent = (_Py_TYPENODE_t * )(_Py_TYPENODE_CLEAR_TAG (node ));
448
+ plocals = (int )(parent - type_context -> type_locals );
449
+ pstack = (int )(parent - type_context -> type_stack );
450
+ is_local = (0 <= plocals ) && (plocals < nlocals );
451
+ if (!is_local ) {
452
+ assert ((0 <= pstack ) && (pstack < nstack ));
453
+ }
454
+ }
455
+
456
+ fprintf (stderr , " %s" ,
457
+ type == NULL ? "?" : type -> tp_name );
458
+ if (tag == TYPE_REF ) {
459
+ fprintf (stderr , "%s%d]" ,
460
+ is_local ? "->locals[" : "->stack[" ,
461
+ is_local ? plocals : pstack );
462
+ }
414
463
}
415
464
fprintf (stderr , "]\n" );
416
465
}
@@ -1669,7 +1718,11 @@ _PyCode_Tier2Initialize(_PyInterpreterFrame *frame, _Py_CODEUNIT *next_instr)
1669
1718
int deopt = _PyOpcode_Deopt [_Py_OPCODE (* curr_instr )];
1670
1719
if (IS_FORBIDDEN_OPCODE (deopt )) {
1671
1720
#if BB_DEBUG
1721
+ #ifdef Py_DEBUG
1722
+ fprintf (stderr , "FORBIDDEN OPCODE %s\n" , _PyOpcode_OpName [_Py_OPCODE (* curr_instr )]);
1723
+ #else
1672
1724
fprintf (stderr , "FORBIDDEN OPCODE %d\n" , _Py_OPCODE (* curr_instr ));
1725
+ #endif
1673
1726
#endif
1674
1727
return NULL ;
1675
1728
}
0 commit comments