ZJIT: Parse opt_regexpmatch2 into HIR

This commit is contained in:
Alan Wu 2025-06-06 22:01:04 +09:00
parent ec1244cfd2
commit b8922a8d45
Notes: git 2025-06-09 13:37:07 +00:00
2 changed files with 22 additions and 0 deletions

View File

@ -240,6 +240,13 @@ class TestZJIT < Test::Unit::TestCase
RUBY RUBY
end 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 def test_opt_ge
assert_compiles '[false, true, true]', %q{ assert_compiles '[false, true, true]', %q{
def test(a, b) = a >= b def test(a, b) = a >= b

View File

@ -2380,6 +2380,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
YARVINSN_opt_and | YARVINSN_opt_and |
YARVINSN_opt_or | YARVINSN_opt_or |
YARVINSN_opt_not | YARVINSN_opt_not |
YARVINSN_opt_regexpmatch2 |
YARVINSN_opt_send_without_block => { YARVINSN_opt_send_without_block => {
let cd: *const rb_call_data = get_arg(pc, 0).as_ptr(); let cd: *const rb_call_data = get_arg(pc, 0).as_ptr();
let call_info = unsafe { rb_get_call_data_ci(cd) }; let call_info = unsafe { rb_get_call_data_ci(cd) };
@ -3879,6 +3880,20 @@ mod tests {
Return v4 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] #[test]
fn test_branchnil() { fn test_branchnil() {
eval(" eval("