@@ -7453,10 +7453,7 @@ impl ExecutingFrame<'_> {
74537453 . load ( )
74547454 . is_some_and ( |f| f as usize == PyBaseObject :: getattro as * const ( ) as usize ) ;
74557455 if !is_default_getattro {
7456- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7457- if type_version == 0 {
7458- type_version = cls. assign_version_tag ( ) ;
7459- }
7456+ let type_version = cls. version_for_specialization ( _vm) ;
74607457 if type_version != 0
74617458 && !oparg. is_method ( )
74627459 && !self . specialization_eval_frame_active ( _vm)
@@ -7494,10 +7491,7 @@ impl ExecutingFrame<'_> {
74947491 }
74957492
74967493 // Get or assign type version
7497- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7498- if type_version == 0 {
7499- type_version = cls. assign_version_tag ( ) ;
7500- }
7494+ let type_version = cls. version_for_specialization ( _vm) ;
75017495 if type_version == 0 {
75027496 // Version counter overflow — backoff to avoid re-attempting every execution
75037497 unsafe {
@@ -7717,10 +7711,7 @@ impl ExecutingFrame<'_> {
77177711 let owner_type = obj. downcast_ref :: < PyType > ( ) . unwrap ( ) ;
77187712
77197713 // Get or assign type version for the type object itself
7720- let mut type_version = owner_type. tp_version_tag . load ( Acquire ) ;
7721- if type_version == 0 {
7722- type_version = owner_type. assign_version_tag ( ) ;
7723- }
7714+ let type_version = owner_type. version_for_specialization ( _vm) ;
77247715 if type_version == 0 {
77257716 unsafe {
77267717 self . code . instructions . write_adaptive_counter (
@@ -7755,10 +7746,7 @@ impl ExecutingFrame<'_> {
77557746 }
77567747 let mut metaclass_version = 0 ;
77577748 if !mcl. slots . flags . has_feature ( PyTypeFlags :: IMMUTABLETYPE ) {
7758- metaclass_version = mcl. tp_version_tag . load ( Acquire ) ;
7759- if metaclass_version == 0 {
7760- metaclass_version = mcl. assign_version_tag ( ) ;
7761- }
7749+ metaclass_version = mcl. version_for_specialization ( _vm) ;
77627750 if metaclass_version == 0 {
77637751 unsafe {
77647752 self . code . instructions . write_adaptive_counter (
@@ -7945,16 +7933,14 @@ impl ExecutingFrame<'_> {
79457933 Some ( Instruction :: BinaryOpSubscrListSlice )
79467934 } else {
79477935 let cls = a. class ( ) ;
7936+ let ( getitem, type_version) =
7937+ cls. lookup_ref_and_version_interned ( identifier ! ( vm, __getitem__) , vm) ;
79487938 if cls. slots . flags . has_feature ( PyTypeFlags :: HEAPTYPE )
79497939 && !self . specialization_eval_frame_active ( vm)
7950- && let Some ( _getitem) = cls . get_attr ( identifier ! ( vm , __getitem__ ) )
7940+ && let Some ( _getitem) = getitem
79517941 && let Some ( func) = _getitem. downcast_ref_if_exact :: < PyFunction > ( vm)
79527942 && func. can_specialize_call ( 2 )
79537943 {
7954- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7955- if type_version == 0 {
7956- type_version = cls. assign_version_tag ( ) ;
7957- }
79587944 if type_version != 0 {
79597945 if cls. cache_getitem_for_specialization (
79607946 func. to_owned ( ) ,
@@ -8493,11 +8479,8 @@ impl ExecutingFrame<'_> {
84938479 && cls_new_fn as usize == obj_new_fn as usize
84948480 && cls_alloc_fn as usize == obj_alloc_fn as usize
84958481 {
8496- let init = cls. get_attr ( identifier ! ( vm, __init__) ) ;
8497- let mut version = cls. tp_version_tag . load ( Acquire ) ;
8498- if version == 0 {
8499- version = cls. assign_version_tag ( ) ;
8500- }
8482+ let ( init, version) =
8483+ cls. lookup_ref_and_version_interned ( identifier ! ( vm, __init__) , vm) ;
85018484 if version == 0 {
85028485 unsafe {
85038486 self . code . instructions . write_adaptive_counter (
@@ -8817,10 +8800,7 @@ impl ExecutingFrame<'_> {
88178800 && cls. slots . as_sequence . length . load ( ) . is_none ( )
88188801 {
88198802 // Cache type version for ToBoolAlwaysTrue guard
8820- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
8821- if type_version == 0 {
8822- type_version = cls. assign_version_tag ( ) ;
8823- }
8803+ let type_version = cls. version_for_specialization ( vm) ;
88248804 if type_version != 0 {
88258805 unsafe {
88268806 self . code
@@ -9158,10 +9138,7 @@ impl ExecutingFrame<'_> {
91589138 }
91599139
91609140 // Get or assign type version
9161- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
9162- if type_version == 0 {
9163- type_version = cls. assign_version_tag ( ) ;
9164- }
9141+ let type_version = cls. version_for_specialization ( vm) ;
91659142 if type_version == 0 {
91669143 unsafe {
91679144 self . code . instructions . write_adaptive_counter (
0 commit comments