Skip to content

Commit 082d56d

Browse files
committed
ZJIT: Parse opt_regexpmatch2 into HIR
1 parent 2541d73 commit 082d56d

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ def test(obj) = !obj
240240
RUBY
241241
end
242242

243+
def test_opt_regexpmatch2
244+
assert_compiles('[1, nil]', <<~RUBY, insns: [:opt_regexpmatch2])
245+
def test(haystack) = /needle/ =~ haystack
246+
return test("kneedle"), test("")
247+
RUBY
248+
end
249+
243250
def test_opt_ge
244251
assert_compiles '[false, true, true]', %q{
245252
def test(a, b) = a >= b

zjit/src/hir.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23502350
YARVINSN_opt_and |
23512351
YARVINSN_opt_or |
23522352
YARVINSN_opt_not |
2353+
YARVINSN_opt_regexpmatch2 |
23532354
YARVINSN_opt_send_without_block => {
23542355
let cd: *const rb_call_data = get_arg(pc, 0).as_ptr();
23552356
let call_info = unsafe { rb_get_call_data_ci(cd) };
@@ -3818,6 +3819,20 @@ mod tests {
38183819
Return v4
38193820
"#]]);
38203821
}
3822+
3823+
#[test]
3824+
fn opt_regexpmatch2() {
3825+
eval("
3826+
def test(regexp, matchee) = regexp =~ matchee
3827+
");
3828+
assert_method_hir_with_opcode("test", YARVINSN_opt_regexpmatch2, expect![[r#"
3829+
fn test:
3830+
bb0(v0:BasicObject, v1:BasicObject, v2:BasicObject):
3831+
v5:BasicObject = SendWithoutBlock v1, :=~, v2
3832+
Return v5
3833+
"#]]);
3834+
}
3835+
38213836
#[test]
38223837
fn test_branchnil() {
38233838
eval("

0 commit comments

Comments
 (0)