diff options
| author | Max Bernstein <ruby@bernsteinbear.com> | 2025-12-03 20:53:50 -0500 |
|---|---|---|
| committer | Max Bernstein <tekknolagi@gmail.com> | 2025-12-09 08:52:05 -0500 |
| commit | c8441e8db52fe260545b83ffbe5278aff242bd14 (patch) | |
| tree | bd4fef84fc51696db3f7bf8b952988d3392332c7 | |
| parent | edca81a1bb72a9dc54a37766d2c80790dec13884 (diff) | |
ZJIT: Clean up opt_newarray_send
| -rw-r--r-- | zjit/src/hir.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index abf48e04d6..7b1374f9f4 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -5252,20 +5252,25 @@ pub fn iseq_to_hir(iseq: *const rb_iseq_t) -> Result<Function, ParseError> { YARVINSN_opt_newarray_send => { let count = get_arg(pc, 0).as_usize(); let method = get_arg(pc, 1).as_u32(); - let elements = state.stack_pop_n(count)?; let (bop, insn) = match method { - VM_OPT_NEWARRAY_SEND_MAX => (BOP_MAX, Insn::ArrayMax { elements, state: exit_id }), - VM_OPT_NEWARRAY_SEND_HASH => (BOP_HASH, Insn::ArrayHash { elements, state: exit_id }), + VM_OPT_NEWARRAY_SEND_MAX => { + let elements = state.stack_pop_n(count)?; + (BOP_MAX, Insn::ArrayMax { elements, state: exit_id }) + } + VM_OPT_NEWARRAY_SEND_HASH => { + let elements = state.stack_pop_n(count)?; + (BOP_HASH, Insn::ArrayHash { elements, state: exit_id }) + } VM_OPT_NEWARRAY_SEND_INCLUDE_P => { - let target = elements[elements.len() - 1]; - let array_elements = elements[..elements.len() - 1].to_vec(); - (BOP_INCLUDE_P, Insn::ArrayInclude { elements: array_elements, target, state: exit_id }) - }, + let target = state.stack_pop()?; + let elements = state.stack_pop_n(count - 1)?; + (BOP_INCLUDE_P, Insn::ArrayInclude { elements, target, state: exit_id }) + } _ => { // Unknown opcode; side-exit into the interpreter fun.push_insn(block, Insn::SideExit { state: exit_id, reason: SideExitReason::UnhandledNewarraySend(method) }); break; // End the block - }, + } }; if !unsafe { rb_BASIC_OP_UNREDEFINED_P(bop, ARRAY_REDEFINED_OP_FLAG) } { // If the basic operation is already redefined, we cannot optimize it. |
