Skip to content

Commit e639aaa

Browse files
XrXrk0kubuntekknolagi
committed
ZJIT: Prepare for rb_range_new() calling <=>
gen_prepare_call_with_gc() was not enough because of the rb_funcall() usage in range_init(). Co-authored-by: Takashi Kokubun <[email protected]> Co-authored-by: Max Bernstein <[email protected]>
1 parent c1f16fc commit e639aaa

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

test/ruby/test_zjit.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,6 +1855,21 @@ def test = /#{1}#{2}#{3}/
18551855
}, insns: [:toregexp]
18561856
end
18571857

1858+
def test_new_range_non_leaf
1859+
assert_compiles '(0/1)..1', %q{
1860+
def jit_entry(v) = make_range_then_exit(v)
1861+
1862+
def make_range_then_exit(v)
1863+
range = (v..1)
1864+
super rescue range # TODO(alan): replace super with side-exit intrinsic
1865+
end
1866+
1867+
jit_entry(0) # profile
1868+
jit_entry(0) # compile
1869+
jit_entry(0/1r) # run without stub
1870+
}, call_threshold: 2
1871+
end
1872+
18581873
private
18591874

18601875
# Assert that every method call in `test_script` can be compiled by ZJIT

zjit/src/codegen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio
338338
Insn::Const { val: Const::Value(val) } => gen_const(*val),
339339
Insn::NewArray { elements, state } => gen_new_array(asm, opnds!(elements), &function.frame_state(*state)),
340340
Insn::NewHash { elements, state } => gen_new_hash(jit, asm, elements, &function.frame_state(*state)),
341-
Insn::NewRange { low, high, flag, state } => gen_new_range(asm, opnd!(low), opnd!(high), *flag, &function.frame_state(*state)),
341+
Insn::NewRange { low, high, flag, state } => gen_new_range(jit, asm, opnd!(low), opnd!(high), *flag, &function.frame_state(*state)),
342342
Insn::ArrayDup { val, state } => gen_array_dup(asm, opnd!(val), &function.frame_state(*state)),
343343
Insn::StringCopy { val, chilled, state } => gen_string_copy(asm, opnd!(val), *chilled, &function.frame_state(*state)),
344344
// concatstrings shouldn't have 0 strings
@@ -1040,13 +1040,15 @@ fn gen_new_hash(
10401040

10411041
/// Compile a new range instruction
10421042
fn gen_new_range(
1043+
jit: &JITState,
10431044
asm: &mut Assembler,
10441045
low: lir::Opnd,
10451046
high: lir::Opnd,
10461047
flag: RangeType,
10471048
state: &FrameState,
10481049
) -> lir::Opnd {
1049-
gen_prepare_call_with_gc(asm, state);
1050+
// Sometimes calls `low.<=>(high)`
1051+
gen_prepare_non_leaf_call(jit, asm, state);
10501052

10511053
// Call rb_range_new(low, high, flag)
10521054
asm_ccall!(asm, rb_range_new, low, high, (flag as i64).into())

0 commit comments

Comments
 (0)