@@ -206,10 +206,12 @@ impl Flags {
206206 const IS_OBJECT_PROFILING : u32 = 1 << 4 ;
207207 /// Class/module fields_obj is embedded (or absent)
208208 const IS_FIELDS_EMBEDDED : u32 = 1 << 5 ;
209- /// Object is a T_CLASS or T_MODULE
210- const IS_T_CLASS_OR_MODULE : u32 = 1 << 6 ;
209+ /// Object is a T_CLASS
210+ const IS_T_CLASS : u32 = 1 << 6 ;
211+ /// Object is a T_MODULE
212+ const IS_T_MODULE : u32 = 1 << 7 ;
211213 /// Object is a typed T_DATA (RTYPEDDATA_P)
212- const IS_TYPED_DATA : u32 = 1 << 7 ;
214+ const IS_TYPED_DATA : u32 = 1 << 8 ;
213215
214216 pub fn none ( ) -> Self { Self ( Self :: NONE ) }
215217
@@ -220,7 +222,8 @@ impl Flags {
220222 pub fn is_struct_embedded ( self ) -> bool { ( self . 0 & Self :: IS_STRUCT_EMBEDDED ) != 0 }
221223 pub fn is_object_profiling ( self ) -> bool { ( self . 0 & Self :: IS_OBJECT_PROFILING ) != 0 }
222224 pub fn is_fields_embedded ( self ) -> bool { ( self . 0 & Self :: IS_FIELDS_EMBEDDED ) != 0 }
223- pub fn is_t_class_or_module ( self ) -> bool { ( self . 0 & Self :: IS_T_CLASS_OR_MODULE ) != 0 }
225+ pub fn is_t_class ( self ) -> bool { ( self . 0 & Self :: IS_T_CLASS ) != 0 }
226+ pub fn is_t_module ( self ) -> bool { ( self . 0 & Self :: IS_T_MODULE ) != 0 }
224227 pub fn is_typed_data ( self ) -> bool { ( self . 0 & Self :: IS_TYPED_DATA ) != 0 }
225228}
226229
@@ -298,8 +301,14 @@ impl ProfiledType {
298301 if unsafe { RB_TYPE_P ( obj, RUBY_T_OBJECT ) } {
299302 flags. 0 |= Flags :: IS_T_OBJECT ;
300303 }
301- if unsafe { RB_TYPE_P ( obj, RUBY_T_CLASS ) || RB_TYPE_P ( obj, RUBY_T_MODULE ) } {
302- flags. 0 |= Flags :: IS_T_CLASS_OR_MODULE ;
304+ if unsafe { RB_TYPE_P ( obj, RUBY_T_CLASS ) } {
305+ flags. 0 |= Flags :: IS_T_CLASS ;
306+ if obj. class_fields_embedded_p ( ) {
307+ flags. 0 |= Flags :: IS_FIELDS_EMBEDDED ;
308+ }
309+ }
310+ if unsafe { RB_TYPE_P ( obj, RUBY_T_MODULE ) } {
311+ flags. 0 |= Flags :: IS_T_MODULE ;
303312 if obj. class_fields_embedded_p ( ) {
304313 flags. 0 |= Flags :: IS_FIELDS_EMBEDDED ;
305314 }
@@ -333,16 +342,19 @@ impl ProfiledType {
333342 self . flags
334343 }
335344
336- /// For ivar access
345+ /// For ivar access, you need to know the index in the fields array (described by the shape)
346+ /// and the way to get the fields array (described by the builtin type). Both pieces of
347+ /// information are on the `RBasic::flags` field. This method returns expected masked flags
348+ /// for guarding.
337349 pub fn rbasic_flags_and_mask ( & self ) -> ( u64 , u64 ) {
338350 let shape_flag_shift = u64:: from ( RB_SHAPE_FLAG_SHIFT ) ;
339351 let ( shape, shape_mask) = ( u64:: from ( self . shape ( ) . 0 ) << shape_flag_shift, !0 << shape_flag_shift) ;
340352 let ( builtin_type, type_mask) = if self . flags ( ) . is_t_object ( ) {
341353 ( RUBY_T_OBJECT , RUBY_T_MASK )
342- } else if self . class ( ) . is_subclass_of ( unsafe { rb_cClass } ) == ClassRelationship :: Subclass {
354+ } else if self . flags ( ) . is_t_class ( ) {
343355 // Check class first since `Class < Module`
344356 ( RUBY_T_CLASS , RUBY_T_MASK )
345- } else if self . class ( ) . is_subclass_of ( unsafe { rb_cModule } ) == ClassRelationship :: Subclass {
357+ } else if self . flags ( ) . is_t_module ( ) {
346358 ( RUBY_T_MODULE , RUBY_T_MASK )
347359 } else if self . flags ( ) . is_typed_data ( ) {
348360 ( RUBY_T_DATA | RUBY_TYPED_FL_IS_TYPED_DATA , RUBY_T_MASK | RUBY_TYPED_FL_IS_TYPED_DATA )
0 commit comments