@@ -8168,6 +8168,98 @@ mod hir_opt_tests {
81688168 " ) ;
81698169 }
81708170
8171+ #[ test]
8172+ fn test_specialize_kind_of_class ( ) {
8173+ eval ( r#"
8174+ def test(o) = o.kind_of?(String)
8175+ test("asdf")
8176+ "# ) ;
8177+ assert_snapshot ! ( hir_string( "test" ) , @r"
8178+ fn test@<compiled>:2:
8179+ bb0():
8180+ EntryPoint interpreter
8181+ v1:BasicObject = LoadSelf
8182+ v2:BasicObject = GetLocal l0, SP@4
8183+ Jump bb2(v1, v2)
8184+ bb1(v5:BasicObject, v6:BasicObject):
8185+ EntryPoint JIT(0)
8186+ Jump bb2(v5, v6)
8187+ bb2(v8:BasicObject, v9:BasicObject):
8188+ PatchPoint SingleRactorMode
8189+ PatchPoint StableConstantNames(0x1000, String)
8190+ v24:Class[String@0x1008] = Const Value(VALUE(0x1008))
8191+ PatchPoint MethodRedefined(String@0x1008, kind_of?@0x1009, cme:0x1010)
8192+ PatchPoint NoSingletonClass(String@0x1008)
8193+ v28:StringExact = GuardType v9, StringExact
8194+ v29:BoolExact = IsA v28, v24
8195+ IncrCounter inline_cfunc_optimized_send_count
8196+ CheckInterrupts
8197+ Return v29
8198+ " ) ;
8199+ }
8200+
8201+ #[ test]
8202+ fn test_dont_specialize_kind_of_module ( ) {
8203+ eval ( r#"
8204+ def test(o) = o.kind_of?(Kernel)
8205+ test("asdf")
8206+ "# ) ;
8207+ assert_snapshot ! ( hir_string( "test" ) , @r"
8208+ fn test@<compiled>:2:
8209+ bb0():
8210+ EntryPoint interpreter
8211+ v1:BasicObject = LoadSelf
8212+ v2:BasicObject = GetLocal l0, SP@4
8213+ Jump bb2(v1, v2)
8214+ bb1(v5:BasicObject, v6:BasicObject):
8215+ EntryPoint JIT(0)
8216+ Jump bb2(v5, v6)
8217+ bb2(v8:BasicObject, v9:BasicObject):
8218+ PatchPoint SingleRactorMode
8219+ PatchPoint StableConstantNames(0x1000, Kernel)
8220+ v24:ModuleExact[VALUE(0x1008)] = Const Value(VALUE(0x1008))
8221+ PatchPoint MethodRedefined(String@0x1010, kind_of?@0x1018, cme:0x1020)
8222+ PatchPoint NoSingletonClass(String@0x1010)
8223+ v28:StringExact = GuardType v9, StringExact
8224+ v29:BasicObject = CCallWithFrame Kernel#kind_of?@0x1048, v28, v24
8225+ CheckInterrupts
8226+ Return v29
8227+ " ) ;
8228+ }
8229+
8230+ #[ test]
8231+ fn test_elide_kind_of ( ) {
8232+ eval ( r#"
8233+ def test(o)
8234+ o.kind_of?(Integer)
8235+ 5
8236+ end
8237+ test("asdf")
8238+ "# ) ;
8239+ assert_snapshot ! ( hir_string( "test" ) , @r"
8240+ fn test@<compiled>:3:
8241+ bb0():
8242+ EntryPoint interpreter
8243+ v1:BasicObject = LoadSelf
8244+ v2:BasicObject = GetLocal l0, SP@4
8245+ Jump bb2(v1, v2)
8246+ bb1(v5:BasicObject, v6:BasicObject):
8247+ EntryPoint JIT(0)
8248+ Jump bb2(v5, v6)
8249+ bb2(v8:BasicObject, v9:BasicObject):
8250+ PatchPoint SingleRactorMode
8251+ PatchPoint StableConstantNames(0x1000, Integer)
8252+ v28:Class[Integer@0x1008] = Const Value(VALUE(0x1008))
8253+ PatchPoint MethodRedefined(String@0x1010, kind_of?@0x1018, cme:0x1020)
8254+ PatchPoint NoSingletonClass(String@0x1010)
8255+ v32:StringExact = GuardType v9, StringExact
8256+ IncrCounter inline_cfunc_optimized_send_count
8257+ v21:Fixnum[5] = Const Value(5)
8258+ CheckInterrupts
8259+ Return v21
8260+ " ) ;
8261+ }
8262+
81718263 #[ test]
81728264 fn counting_complex_feature_use_for_fallback ( ) {
81738265 eval ( "
0 commit comments