@@ -7507,6 +7507,68 @@ mod hir_opt_tests {
75077507 " ) ;
75087508 }
75097509
7510+ #[ test]
7511+ fn test_optimize_getivar_polymorphic_with_subclass ( ) {
7512+ set_call_threshold ( 3 ) ;
7513+ eval ( r#"
7514+ class C
7515+ def initialize
7516+ @foo = 3
7517+ end
7518+
7519+ def foo = @foo + 1
7520+ end
7521+
7522+ class D < C
7523+ def initialize
7524+ super
7525+ @bar = 4
7526+ end
7527+ end
7528+
7529+ O1 = C.new
7530+ O2 = D.new
7531+ O1.foo
7532+ O2.foo
7533+ "# ) ;
7534+ assert_snapshot ! ( hir_string_proc( "C.instance_method(:foo)" ) , @"
7535+ fn foo@<compiled>:7:
7536+ bb1():
7537+ EntryPoint interpreter
7538+ v1:BasicObject = LoadSelf
7539+ Jump bb3(v1)
7540+ bb2():
7541+ EntryPoint JIT(0)
7542+ v4:BasicObject = LoadArg :self@0
7543+ Jump bb3(v4)
7544+ bb3(v6:BasicObject):
7545+ PatchPoint SingleRactorMode
7546+ v11:HeapBasicObject = GuardType v6, HeapBasicObject
7547+ v12:CShape = LoadField v11, :_shape_id@0x1000
7548+ v14:CShape[0x1001] = Const CShape(0x1001)
7549+ v15:CBool = IsBitEqual v12, v14
7550+ IfTrue v15, bb5()
7551+ v19:CShape[0x1002] = Const CShape(0x1002)
7552+ v20:CBool = IsBitEqual v12, v19
7553+ IfTrue v20, bb6()
7554+ v24:BasicObject = GetIvar v11, :@foo
7555+ Jump bb4(v24)
7556+ bb5():
7557+ v17:BasicObject = LoadField v11, :@foo@0x1003
7558+ Jump bb4(v17)
7559+ bb6():
7560+ v22:BasicObject = LoadField v11, :@foo@0x1003
7561+ Jump bb4(v22)
7562+ bb4(v13:BasicObject):
7563+ v27:Fixnum[1] = Const Value(1)
7564+ PatchPoint MethodRedefined(Integer@0x1008, +@0x1010, cme:0x1018)
7565+ v38:Fixnum = GuardType v13, Fixnum
7566+ v39:Fixnum = FixnumAdd v38, v27
7567+ CheckInterrupts
7568+ Return v39
7569+ " ) ;
7570+ }
7571+
75107572 #[ test]
75117573 fn test_dont_optimize_attr_accessor_polymorphic ( ) {
75127574 set_call_threshold ( 3 ) ;
0 commit comments