Skip to content

Commit 9865aa9

Browse files
committed
ZJIT: Parse opt_empty_p into HIR
1 parent 96fdaf2 commit 9865aa9

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ def test(a, b) = a > b
205205
}, insns: [:opt_gt], call_threshold: 2
206206
end
207207

208+
def test_opt_empty_p
209+
assert_compiles('[false, false, true]', <<~RUBY, insns: [:opt_empty_p])
210+
def test(x) = x.empty?
211+
return test([1]), test("1"), test({})
212+
RUBY
213+
end
214+
208215
def test_opt_ge
209216
assert_compiles '[false, true, true]', %q{
210217
def test(a, b) = a >= b

zjit/src/hir.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2355,6 +2355,10 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23552355
break; // Don't enqueue the next block as a successor
23562356
}
23572357

2358+
// These are opt_send_without_block and all the opt_* instructions
2359+
// specialized to a certain method that could also be serviced
2360+
// using the general send implementation. The optimizer start from
2361+
// a general send for all of these later in the pipeline.
23582362
YARVINSN_opt_nil_p |
23592363
YARVINSN_opt_plus |
23602364
YARVINSN_opt_minus |
@@ -2371,6 +2375,7 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
23712375
YARVINSN_opt_length |
23722376
YARVINSN_opt_size |
23732377
YARVINSN_opt_aref |
2378+
YARVINSN_opt_empty_p |
23742379
YARVINSN_opt_send_without_block => {
23752380
let cd: *const rb_call_data = get_arg(pc, 0).as_ptr();
23762381
let call_info = unsafe { rb_get_call_data_ci(cd) };
@@ -3806,6 +3811,19 @@ mod tests {
38063811
"#]]);
38073812
}
38083813

3814+
#[test]
3815+
fn opt_empty_p() {
3816+
eval("
3817+
def test(x) = x.empty?
3818+
");
3819+
assert_method_hir_with_opcode("test", YARVINSN_opt_empty_p, expect![[r#"
3820+
fn test:
3821+
bb0(v0:BasicObject, v1:BasicObject):
3822+
v4:BasicObject = SendWithoutBlock v1, :empty?
3823+
Return v4
3824+
"#]]);
3825+
}
3826+
38093827
#[test]
38103828
fn test_branchnil() {
38113829
eval("

0 commit comments

Comments
 (0)