summaryrefslogtreecommitdiff
path: root/test/ruby/test_zjit.rb
diff options
context:
space:
mode:
authorAndré Luiz Tiago Soares <andre.soares@altxtech.net>2025-09-09 11:58:03 -0400
committerGitHub <noreply@github.com>2025-09-09 08:58:03 -0700
commitf7fe43610b7598e35c538269a8adefbc5b59e524 (patch)
tree4c70e8453f171a679c490ce6261af84fafbddd23 /test/ruby/test_zjit.rb
parentfe362beb899a2b1a3d9012a4ad17b3c48d16b338 (diff)
ZJIT: Optimize `ObjToString` with type guards (#14469)
* failing test for ObjToString optimization with GuardType * profile ObjToString receiver and rewrite with guard * adjust integration tests for objtostring type guard optimization * Implement new GuardTypeNot HIR; objtostring sends to_s directly on profiled nonstrings * codegen for GuardTypeNot * typo fixes * better name for tests; fix side exit reason for GuardTypeNot * revert accidental change * make bindgen * Fix is_string to identify subclasses of String; fix codegen for identifying if val is String
Diffstat (limited to 'test/ruby/test_zjit.rb')
-rw-r--r--test/ruby/test_zjit.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index 4d8eb30c80..b5bdd0d12b 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -2088,6 +2088,61 @@ class TestZJIT < Test::Unit::TestCase
}
end
+ def test_objtostring_profiled_string_fastpath
+ assert_compiles '"foo"', %q{
+ def test(str)
+ "#{str}"
+ end
+ test('foo'); test('foo') # profile as string
+ }, call_threshold: 2
+ end
+
+ def test_objtostring_profiled_string_subclass_fastpath
+ assert_compiles '"foo"', %q{
+ class MyString < String; end
+
+ def test(str)
+ "#{str}"
+ end
+
+ foo = MyString.new("foo")
+ test(foo); test(foo) # still profiles as string
+ }, call_threshold: 2
+ end
+
+ def test_objtostring_profiled_string_fastpath_exits_on_nonstring
+ assert_compiles '"1"', %q{
+ def test(str)
+ "#{str}"
+ end
+
+ test('foo') # profile as string
+ test(1)
+ }, call_threshold: 2
+ end
+
+ def test_objtostring_profiled_nonstring_calls_to_s
+ assert_compiles '"[1, 2, 3]"', %q{
+ def test(str)
+ "#{str}"
+ end
+
+ test([1,2,3]); # profile as nonstring
+ test([1,2,3]);
+ }, call_threshold: 2
+ end
+
+ def test_objtostring_profiled_nonstring_guard_exits_when_string
+ assert_compiles '"foo"', %q{
+ def test(str)
+ "#{str}"
+ end
+
+ test([1,2,3]); # profiles as nonstring
+ test('foo');
+ }, call_threshold: 2
+ end
+
def test_string_bytesize_with_guard
assert_compiles '5', %q{
def test(str)