@@ -7983,6 +7983,191 @@ mod hir_opt_tests {
79837983 " ) ;
79847984 }
79857985
7986+ #[ test]
7987+ fn test_specialize_class_eqq ( ) {
7988+ eval ( r#"
7989+ def test(o) = String === o
7990+ test("asdf")
7991+ "# ) ;
7992+ assert_snapshot ! ( hir_string( "test" ) , @r"
7993+ fn test@<compiled>:2:
7994+ bb0():
7995+ EntryPoint interpreter
7996+ v1:BasicObject = LoadSelf
7997+ v2:BasicObject = GetLocal l0, SP@4
7998+ Jump bb2(v1, v2)
7999+ bb1(v5:BasicObject, v6:BasicObject):
8000+ EntryPoint JIT(0)
8001+ Jump bb2(v5, v6)
8002+ bb2(v8:BasicObject, v9:BasicObject):
8003+ PatchPoint SingleRactorMode
8004+ PatchPoint StableConstantNames(0x1000, String)
8005+ v26:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8006+ PatchPoint NoEPEscape(test)
8007+ PatchPoint MethodRedefined(Class@0x1010, ===@0x1018, cme:0x1020)
8008+ PatchPoint NoSingletonClass(Class@0x1010)
8009+ v30:BoolExact = IsA v9, v26
8010+ IncrCounter inline_cfunc_optimized_send_count
8011+ CheckInterrupts
8012+ Return v30
8013+ " ) ;
8014+ }
8015+
8016+ #[ test]
8017+ fn test_dont_specialize_module_eqq ( ) {
8018+ eval ( r#"
8019+ def test(o) = Kernel === o
8020+ test("asdf")
8021+ "# ) ;
8022+ assert_snapshot ! ( hir_string( "test" ) , @r"
8023+ fn test@<compiled>:2:
8024+ bb0():
8025+ EntryPoint interpreter
8026+ v1:BasicObject = LoadSelf
8027+ v2:BasicObject = GetLocal l0, SP@4
8028+ Jump bb2(v1, v2)
8029+ bb1(v5:BasicObject, v6:BasicObject):
8030+ EntryPoint JIT(0)
8031+ Jump bb2(v5, v6)
8032+ bb2(v8:BasicObject, v9:BasicObject):
8033+ PatchPoint SingleRactorMode
8034+ PatchPoint StableConstantNames(0x1000, Kernel)
8035+ v26:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8036+ PatchPoint NoEPEscape(test)
8037+ PatchPoint MethodRedefined(Module@0x1010, ===@0x1018, cme:0x1020)
8038+ PatchPoint NoSingletonClass(Module@0x1010)
8039+ IncrCounter inline_cfunc_optimized_send_count
8040+ v31:BoolExact = CCall Module#===@0x1048, v26, v9
8041+ CheckInterrupts
8042+ Return v31
8043+ " ) ;
8044+ }
8045+
8046+ #[ test]
8047+ fn test_specialize_is_a_class ( ) {
8048+ eval ( r#"
8049+ def test(o) = o.is_a?(String)
8050+ test("asdf")
8051+ "# ) ;
8052+ assert_snapshot ! ( hir_string( "test" ) , @r"
8053+ fn test@<compiled>:2:
8054+ bb0():
8055+ EntryPoint interpreter
8056+ v1:BasicObject = LoadSelf
8057+ v2:BasicObject = GetLocal l0, SP@4
8058+ Jump bb2(v1, v2)
8059+ bb1(v5:BasicObject, v6:BasicObject):
8060+ EntryPoint JIT(0)
8061+ Jump bb2(v5, v6)
8062+ bb2(v8:BasicObject, v9:BasicObject):
8063+ PatchPoint SingleRactorMode
8064+ PatchPoint StableConstantNames(0x1000, String)
8065+ v24:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8066+ PatchPoint MethodRedefined(String@0x1008, is_a?@0x1010, cme:0x1018)
8067+ PatchPoint NoSingletonClass(String@0x1008)
8068+ v28:StringExact = GuardType v9, StringExact
8069+ v29:BoolExact = IsA v28, v24
8070+ IncrCounter inline_cfunc_optimized_send_count
8071+ CheckInterrupts
8072+ Return v29
8073+ " ) ;
8074+ }
8075+
8076+ #[ test]
8077+ fn test_dont_specialize_is_a_module ( ) {
8078+ eval ( r#"
8079+ def test(o) = o.is_a?(Kernel)
8080+ test("asdf")
8081+ "# ) ;
8082+ assert_snapshot ! ( hir_string( "test" ) , @r"
8083+ fn test@<compiled>:2:
8084+ bb0():
8085+ EntryPoint interpreter
8086+ v1:BasicObject = LoadSelf
8087+ v2:BasicObject = GetLocal l0, SP@4
8088+ Jump bb2(v1, v2)
8089+ bb1(v5:BasicObject, v6:BasicObject):
8090+ EntryPoint JIT(0)
8091+ Jump bb2(v5, v6)
8092+ bb2(v8:BasicObject, v9:BasicObject):
8093+ PatchPoint SingleRactorMode
8094+ PatchPoint StableConstantNames(0x1000, Kernel)
8095+ v24:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8096+ PatchPoint MethodRedefined(String@0x1010, is_a?@0x1018, cme:0x1020)
8097+ PatchPoint NoSingletonClass(String@0x1010)
8098+ v28:StringExact = GuardType v9, StringExact
8099+ v29:BasicObject = CCallWithFrame Kernel#is_a?@0x1048, v28, v24
8100+ CheckInterrupts
8101+ Return v29
8102+ " ) ;
8103+ }
8104+
8105+ #[ test]
8106+ fn test_elide_is_a ( ) {
8107+ eval ( r#"
8108+ def test(o)
8109+ o.is_a?(Integer)
8110+ 5
8111+ end
8112+ test("asdf")
8113+ "# ) ;
8114+ assert_snapshot ! ( hir_string( "test" ) , @r"
8115+ fn test@<compiled>:3:
8116+ bb0():
8117+ EntryPoint interpreter
8118+ v1:BasicObject = LoadSelf
8119+ v2:BasicObject = GetLocal l0, SP@4
8120+ Jump bb2(v1, v2)
8121+ bb1(v5:BasicObject, v6:BasicObject):
8122+ EntryPoint JIT(0)
8123+ Jump bb2(v5, v6)
8124+ bb2(v8:BasicObject, v9:BasicObject):
8125+ PatchPoint SingleRactorMode
8126+ PatchPoint StableConstantNames(0x1000, Integer)
8127+ v28:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8128+ PatchPoint MethodRedefined(String@0x1010, is_a?@0x1018, cme:0x1020)
8129+ PatchPoint NoSingletonClass(String@0x1010)
8130+ v32:StringExact = GuardType v9, StringExact
8131+ IncrCounter inline_cfunc_optimized_send_count
8132+ v21:Fixnum[5] = Const Value(5)
8133+ CheckInterrupts
8134+ Return v21
8135+ " ) ;
8136+ }
8137+
8138+ #[ test]
8139+ fn test_elide_class_eqq ( ) {
8140+ eval ( r#"
8141+ def test(o)
8142+ Integer === o
8143+ 5
8144+ end
8145+ test("asdf")
8146+ "# ) ;
8147+ assert_snapshot ! ( hir_string( "test" ) , @r"
8148+ fn test@<compiled>:3:
8149+ bb0():
8150+ EntryPoint interpreter
8151+ v1:BasicObject = LoadSelf
8152+ v2:BasicObject = GetLocal l0, SP@4
8153+ Jump bb2(v1, v2)
8154+ bb1(v5:BasicObject, v6:BasicObject):
8155+ EntryPoint JIT(0)
8156+ Jump bb2(v5, v6)
8157+ bb2(v8:BasicObject, v9:BasicObject):
8158+ PatchPoint SingleRactorMode
8159+ PatchPoint StableConstantNames(0x1000, Integer)
8160+ v30:Class[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8161+ PatchPoint NoEPEscape(test)
8162+ PatchPoint MethodRedefined(Class@0x1010, ===@0x1018, cme:0x1020)
8163+ PatchPoint NoSingletonClass(Class@0x1010)
8164+ IncrCounter inline_cfunc_optimized_send_count
8165+ v23:Fixnum[5] = Const Value(5)
8166+ CheckInterrupts
8167+ Return v23
8168+ " ) ;
8169+ }
8170+
79868171 #[ test]
79878172 fn counting_complex_feature_use_for_fallback ( ) {
79888173 eval ( "
0 commit comments