@@ -8988,6 +8988,88 @@ mod hir_opt_tests {
89888988 " ) ;
89898989 }
89908990
8991+ #[ test]
8992+ fn test_fold_self_class ( ) {
8993+ eval ( r#"
8994+ class C; end
8995+ def test(o) = o.class
8996+ test(C.new)
8997+ "# ) ;
8998+ assert_snapshot ! ( hir_string( "test" ) , @r"
8999+ fn test@<compiled>:3:
9000+ bb0():
9001+ EntryPoint interpreter
9002+ v1:BasicObject = LoadSelf
9003+ v2:BasicObject = GetLocal l0, SP@4
9004+ Jump bb2(v1, v2)
9005+ bb1(v5:BasicObject, v6:BasicObject):
9006+ EntryPoint JIT(0)
9007+ Jump bb2(v5, v6)
9008+ bb2(v8:BasicObject, v9:BasicObject):
9009+ PatchPoint MethodRedefined(C@0x1000, class@0x1008, cme:0x1010)
9010+ PatchPoint NoSingletonClass(C@0x1000)
9011+ v21:HeapObject[class_exact:C] = GuardType v9, HeapObject[class_exact:C]
9012+ IncrCounter inline_iseq_optimized_send_count
9013+ v25:Class[C@0x1000] = Const Value(VALUE(0x1000))
9014+ IncrCounter inline_cfunc_optimized_send_count
9015+ CheckInterrupts
9016+ Return v25
9017+ " ) ;
9018+ }
9019+
9020+ #[ test]
9021+ fn test_fold_fixnum_class ( ) {
9022+ eval ( r#"
9023+ def test = 5.class
9024+ test
9025+ "# ) ;
9026+ assert_snapshot ! ( hir_string( "test" ) , @r"
9027+ fn test@<compiled>:2:
9028+ bb0():
9029+ EntryPoint interpreter
9030+ v1:BasicObject = LoadSelf
9031+ Jump bb2(v1)
9032+ bb1(v4:BasicObject):
9033+ EntryPoint JIT(0)
9034+ Jump bb2(v4)
9035+ bb2(v6:BasicObject):
9036+ v10:Fixnum[5] = Const Value(5)
9037+ PatchPoint MethodRedefined(Integer@0x1000, class@0x1008, cme:0x1010)
9038+ IncrCounter inline_iseq_optimized_send_count
9039+ v21:Class[Integer@0x1000] = Const Value(VALUE(0x1000))
9040+ IncrCounter inline_cfunc_optimized_send_count
9041+ CheckInterrupts
9042+ Return v21
9043+ " ) ;
9044+ }
9045+
9046+ #[ test]
9047+ fn test_fold_singleton_class ( ) {
9048+ eval ( r#"
9049+ def test = self.class
9050+ test
9051+ "# ) ;
9052+ assert_snapshot ! ( hir_string( "test" ) , @r"
9053+ fn test@<compiled>:2:
9054+ bb0():
9055+ EntryPoint interpreter
9056+ v1:BasicObject = LoadSelf
9057+ Jump bb2(v1)
9058+ bb1(v4:BasicObject):
9059+ EntryPoint JIT(0)
9060+ Jump bb2(v4)
9061+ bb2(v6:BasicObject):
9062+ PatchPoint MethodRedefined(Object@0x1000, class@0x1008, cme:0x1010)
9063+ PatchPoint NoSingletonClass(Object@0x1000)
9064+ v18:HeapObject[class_exact*:Object@VALUE(0x1000)] = GuardType v6, HeapObject[class_exact*:Object@VALUE(0x1000)]
9065+ IncrCounter inline_iseq_optimized_send_count
9066+ v22:Class[Object@0x1038] = Const Value(VALUE(0x1038))
9067+ IncrCounter inline_cfunc_optimized_send_count
9068+ CheckInterrupts
9069+ Return v22
9070+ " ) ;
9071+ }
9072+
89919073 #[ test]
89929074 fn no_load_from_ep_right_after_entrypoint ( ) {
89939075 let formatted = eval ( "
0 commit comments