@@ -7316,10 +7316,7 @@ impl ExecutingFrame<'_> {
73167316 . load ( )
73177317 . is_some_and ( |f| f as usize == PyBaseObject :: getattro as * const ( ) as usize ) ;
73187318 if !is_default_getattro {
7319- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7320- if type_version == 0 {
7321- type_version = cls. assign_version_tag ( ) ;
7322- }
7319+ let type_version = cls. version_for_specialization ( _vm) ;
73237320 if type_version != 0
73247321 && !oparg. is_method ( )
73257322 && !self . specialization_eval_frame_active ( _vm)
@@ -7357,10 +7354,7 @@ impl ExecutingFrame<'_> {
73577354 }
73587355
73597356 // Get or assign type version
7360- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7361- if type_version == 0 {
7362- type_version = cls. assign_version_tag ( ) ;
7363- }
7357+ let type_version = cls. version_for_specialization ( _vm) ;
73647358 if type_version == 0 {
73657359 // Version counter overflow — backoff to avoid re-attempting every execution
73667360 unsafe {
@@ -7580,10 +7574,7 @@ impl ExecutingFrame<'_> {
75807574 let owner_type = obj. downcast_ref :: < PyType > ( ) . unwrap ( ) ;
75817575
75827576 // Get or assign type version for the type object itself
7583- let mut type_version = owner_type. tp_version_tag . load ( Acquire ) ;
7584- if type_version == 0 {
7585- type_version = owner_type. assign_version_tag ( ) ;
7586- }
7577+ let type_version = owner_type. version_for_specialization ( _vm) ;
75877578 if type_version == 0 {
75887579 unsafe {
75897580 self . code . instructions . write_adaptive_counter (
@@ -7618,10 +7609,7 @@ impl ExecutingFrame<'_> {
76187609 }
76197610 let mut metaclass_version = 0 ;
76207611 if !mcl. slots . flags . has_feature ( PyTypeFlags :: IMMUTABLETYPE ) {
7621- metaclass_version = mcl. tp_version_tag . load ( Acquire ) ;
7622- if metaclass_version == 0 {
7623- metaclass_version = mcl. assign_version_tag ( ) ;
7624- }
7612+ metaclass_version = mcl. version_for_specialization ( _vm) ;
76257613 if metaclass_version == 0 {
76267614 unsafe {
76277615 self . code . instructions . write_adaptive_counter (
@@ -7808,16 +7796,14 @@ impl ExecutingFrame<'_> {
78087796 Some ( Instruction :: BinaryOpSubscrListSlice )
78097797 } else {
78107798 let cls = a. class ( ) ;
7799+ let ( getitem, type_version) =
7800+ cls. lookup_ref_and_version_interned ( identifier ! ( vm, __getitem__) , vm) ;
78117801 if cls. slots . flags . has_feature ( PyTypeFlags :: HEAPTYPE )
78127802 && !self . specialization_eval_frame_active ( vm)
7813- && let Some ( _getitem) = cls . get_attr ( identifier ! ( vm , __getitem__ ) )
7803+ && let Some ( _getitem) = getitem
78147804 && let Some ( func) = _getitem. downcast_ref_if_exact :: < PyFunction > ( vm)
78157805 && func. can_specialize_call ( 2 )
78167806 {
7817- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
7818- if type_version == 0 {
7819- type_version = cls. assign_version_tag ( ) ;
7820- }
78217807 if type_version != 0 {
78227808 if cls. cache_getitem_for_specialization (
78237809 func. to_owned ( ) ,
@@ -8356,11 +8342,8 @@ impl ExecutingFrame<'_> {
83568342 && cls_new_fn as usize == obj_new_fn as usize
83578343 && cls_alloc_fn as usize == obj_alloc_fn as usize
83588344 {
8359- let init = cls. get_attr ( identifier ! ( vm, __init__) ) ;
8360- let mut version = cls. tp_version_tag . load ( Acquire ) ;
8361- if version == 0 {
8362- version = cls. assign_version_tag ( ) ;
8363- }
8345+ let ( init, version) =
8346+ cls. lookup_ref_and_version_interned ( identifier ! ( vm, __init__) , vm) ;
83648347 if version == 0 {
83658348 unsafe {
83668349 self . code . instructions . write_adaptive_counter (
@@ -8680,10 +8663,7 @@ impl ExecutingFrame<'_> {
86808663 && cls. slots . as_sequence . length . load ( ) . is_none ( )
86818664 {
86828665 // Cache type version for ToBoolAlwaysTrue guard
8683- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
8684- if type_version == 0 {
8685- type_version = cls. assign_version_tag ( ) ;
8686- }
8666+ let type_version = cls. version_for_specialization ( vm) ;
86878667 if type_version != 0 {
86888668 unsafe {
86898669 self . code
@@ -9021,10 +9001,7 @@ impl ExecutingFrame<'_> {
90219001 }
90229002
90239003 // Get or assign type version
9024- let mut type_version = cls. tp_version_tag . load ( Acquire ) ;
9025- if type_version == 0 {
9026- type_version = cls. assign_version_tag ( ) ;
9027- }
9004+ let type_version = cls. version_for_specialization ( vm) ;
90289005 if type_version == 0 {
90299006 unsafe {
90309007 self . code . instructions . write_adaptive_counter (
0 commit comments