Skip to content

Commit 45e1839

Browse files
authored
ZJIT: Handle opt_case_dispatch insn (ruby#14433)
ZJIT: Handle opt_case_dispatch insn
1 parent 837d741 commit 45e1839

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

test/ruby/test_zjit.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,24 @@ def foo = 1
22402240
}
22412241
end
22422242

2243+
def test_opt_case_dispatch
2244+
assert_compiles '[true, false]', %q{
2245+
def test(x)
2246+
case x
2247+
when :foo
2248+
true
2249+
else
2250+
false
2251+
end
2252+
end
2253+
2254+
results = []
2255+
results << test(:foo)
2256+
results << test(1)
2257+
results
2258+
}, insns: [:opt_case_dispatch]
2259+
end
2260+
22432261
private
22442262

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

zjit/src/hir.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,12 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> {
32743274
});
32753275
queue.push_back((state.clone(), target, target_idx));
32763276
}
3277+
YARVINSN_opt_case_dispatch => {
3278+
// TODO: Some keys are visible at compile time, so in the future we can
3279+
// compile jump targets for certain cases
3280+
// Pop the key from the stack and fallback to the === branches for now
3281+
state.stack_pop()?;
3282+
}
32773283
YARVINSN_opt_new => {
32783284
let exit_id = fun.push_insn(block, Insn::Snapshot { state: exit_state });
32793285
fun.push_insn(block, Insn::CheckInterrupts { state: exit_id });

0 commit comments

Comments
 (0)