@@ -7253,7 +7253,8 @@ mod hir_opt_tests {
72537253 }
72547254
72557255 #[ test]
7256- fn test_optimize_getivar_on_t_data ( ) {
7256+ fn test_optimize_getivar_on_t_struct ( ) {
7257+ // Range is T_STRUCT (not T_DATA): falls back to CCall
72577258 eval ( "
72587259 class C < Range
72597260 def test = @a
@@ -7285,6 +7286,78 @@ mod hir_opt_tests {
72857286 " ) ;
72867287 }
72877288
7289+ #[ test]
7290+ fn test_optimize_getivar_on_typed_data ( ) {
7291+ // Thread is typed T_DATA: uses LoadField chain via RTypedData fields_obj
7292+ eval ( "
7293+ class C < Thread
7294+ def test = @a
7295+ end
7296+ obj = C.new { }
7297+ obj.join
7298+ obj.instance_variable_set(:@a, 1)
7299+ obj.test
7300+ TEST = C.instance_method(:test)
7301+ " ) ;
7302+ assert_snapshot ! ( hir_string_proc( "TEST" ) , @r"
7303+ fn test@<compiled>:3:
7304+ bb1():
7305+ EntryPoint interpreter
7306+ v1:BasicObject = LoadSelf
7307+ Jump bb3(v1)
7308+ bb2():
7309+ EntryPoint JIT(0)
7310+ v4:BasicObject = LoadArg :self@0
7311+ Jump bb3(v4)
7312+ bb3(v6:BasicObject):
7313+ PatchPoint SingleRactorMode
7314+ v17:HeapBasicObject = GuardType v6, HeapBasicObject
7315+ v18:CShape = LoadField v17, :_shape_id@0x1000
7316+ v19:CShape[0x1001] = GuardBitEquals v18, CShape(0x1001)
7317+ v20:RubyValue = LoadField v17, :_fields_obj@0x1002
7318+ v21:BasicObject = LoadField v20, :@a@0x1002
7319+ CheckInterrupts
7320+ Return v21
7321+ " ) ;
7322+ }
7323+
7324+ #[ test]
7325+ fn test_optimize_getivar_on_typed_data_heap_fields ( ) {
7326+ // Typed T_DATA with enough ivars to force heap field storage
7327+ eval ( "
7328+ class C < Thread
7329+ def test = @var1000
7330+ end
7331+ obj = C.new { }
7332+ obj.join
7333+ 1000.times { |i| obj.instance_variable_set(:\" @var#{i}\" , 1) }
7334+ obj.instance_variable_set(:@var1000, 42)
7335+ obj.test
7336+ TEST = C.instance_method(:test)
7337+ " ) ;
7338+ assert_snapshot ! ( hir_string_proc( "TEST" ) , @r"
7339+ fn test@<compiled>:3:
7340+ bb1():
7341+ EntryPoint interpreter
7342+ v1:BasicObject = LoadSelf
7343+ Jump bb3(v1)
7344+ bb2():
7345+ EntryPoint JIT(0)
7346+ v4:BasicObject = LoadArg :self@0
7347+ Jump bb3(v4)
7348+ bb3(v6:BasicObject):
7349+ PatchPoint SingleRactorMode
7350+ v17:HeapBasicObject = GuardType v6, HeapBasicObject
7351+ v18:CShape = LoadField v17, :_shape_id@0x1000
7352+ v19:CShape[0x1001] = GuardBitEquals v18, CShape(0x1001)
7353+ v20:RubyValue = LoadField v17, :_fields_obj@0x1002
7354+ v21:CPtr = LoadField v20, :_as_heap@0x1002
7355+ v22:BasicObject = LoadField v21, :@var1000@0x1003
7356+ CheckInterrupts
7357+ Return v22
7358+ " ) ;
7359+ }
7360+
72887361 #[ test]
72897362 fn test_optimize_getivar_on_module_multi_ractor ( ) {
72907363 eval ( "
0 commit comments