summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJeff Zhang <jeff.j.zhang@shopify.com>2026-01-20 10:50:43 -0500
committerGitHub <noreply@github.com>2026-01-20 10:50:43 -0500
commitd225bb8b464e4e03d2eb6c09ef15adf727af9e2b (patch)
tree62b212032cf2e84188b4e491daa2faf3e3391a24 /test
parentc27ae8d91aadca0660070ee1eeae9598b1fe47ee (diff)
ZJIT: Compile IsA into load + compare for String/Array/Hash (#15878)
Resolves https://github.com/Shopify/ruby/issues/880 Implemented this by using the code generation for `GuardType` as a reference. Not sure if this is the best way to go about it, but it seems to work.
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_zjit.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index ad2df806d5..2cfe9dd7e3 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -4417,6 +4417,60 @@ class TestZJIT < Test::Unit::TestCase
}, call_threshold: 14, num_profiles: 5
end
+ def test_is_a_string_special_case
+ assert_compiles '[true, false, false, false, false, false]', %q{
+ def test(x)
+ x.is_a?(String)
+ end
+ test("foo")
+ [test("bar"), test(1), test(false), test(:foo), test([]), test({})]
+ }
+ end
+
+ def test_is_a_array_special_case
+ assert_compiles '[true, true, false, false, false, false, false]', %q{
+ def test(x)
+ x.is_a?(Array)
+ end
+ test([])
+ [test([1,2,3]), test([]), test(1), test(false), test(:foo), test("foo"), test({})]
+ }
+ end
+
+ def test_is_a_hash_special_case
+ assert_compiles '[true, true, false, false, false, false, false]', %q{
+ def test(x)
+ x.is_a?(Hash)
+ end
+ test({})
+ [test({:a => "b"}), test({}), test(1), test(false), test(:foo), test([]), test("foo")]
+ }
+ end
+
+ def test_is_a_hash_subclass
+ assert_compiles 'true', %q{
+ class MyHash < Hash
+ end
+ def test(x)
+ x.is_a?(Hash)
+ end
+ test({})
+ test(MyHash.new)
+ }
+ end
+
+ def test_is_a_normal_case
+ assert_compiles '[true, false]', %q{
+ class MyClass
+ end
+ def test(x)
+ x.is_a?(MyClass)
+ end
+ test("a")
+ [test(MyClass.new), test("a")]
+ }
+ end
+
private
# Assert that every method call in `test_script` can be compiled by ZJIT