summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <[email protected]>2025-06-06 22:01:04 +0900
committerAlan Wu <[email protected]>2025-06-09 22:36:53 +0900
commitb8922a8d45812a23927228ecc3f21ae9ef5255f2 (patch)
tree5871fa294cb3bcf635f788e07bc2ac271677e846
parentec1244cfd2f115485bffa78fc9d887c1b5c43dbe (diff)
ZJIT: Parse opt_regexpmatch2 into HIR
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/13549
-rw-r--r--test/ruby/test_zjit.rb7
-rw-r--r--zjit/src/hir.rs15
2 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb
index b158052ad4..47a9f6f7dc 100644
--- a/test/ruby/test_zjit.rb
+++ b/test/ruby/test_zjit.rb
@@ -240,6 +240,13 @@ class TestZJIT < Test::Unit::TestCase
RUBY
end
+ def test_opt_regexpmatch2
+ assert_compiles('[1, nil]', <<~RUBY, insns: [:opt_regexpmatch2])
+ def test(haystack) = /needle/ =~ haystack
+ return test("kneedle"), test("")
+ RUBY
+ end
+
def test_opt_ge
assert_compiles '[false, true, true]', %q{
def test(a, b) = a >= b
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index f988b629d9..c93b603f53 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -2380,6 +2380,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
YARVINSN_opt_and |
YARVINSN_opt_or |
YARVINSN_opt_not |
+ YARVINSN_opt_regexpmatch2 |
YARVINSN_opt_send_without_block => {
let cd: *const rb_call_data = get_arg(pc, 0).as_ptr();
let call_info = unsafe { rb_get_call_data_ci(cd) };
@@ -3879,6 +3880,20 @@ mod tests {
Return v4
"#]]);
}
+
+ #[test]
+ fn opt_regexpmatch2() {
+ eval("
+ def test(regexp, matchee) = regexp =~ matchee
+ ");
+ assert_method_hir_with_opcode("test", YARVINSN_opt_regexpmatch2, expect![[r#"
+ fn test:
+ bb0(v0:BasicObject, v1:BasicObject, v2:BasicObject):
+ v5:BasicObject = SendWithoutBlock v1, :=~, v2
+ Return v5
+ "#]]);
+ }
+
#[test]
fn test_branchnil() {
eval("