From ec55b5b9aacf604634b6ca5b34366fba6e8b3f5e Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Thu, 28 Aug 2025 09:48:15 -0400 Subject: ZJIT: Generate code for ArrayPush --- test/ruby/test_zjit.rb | 9 +++++++++ zjit/src/codegen.rs | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/ruby/test_zjit.rb b/test/ruby/test_zjit.rb index 7c29fdeb19..075a7765c8 100644 --- a/test/ruby/test_zjit.rb +++ b/test/ruby/test_zjit.rb @@ -109,6 +109,15 @@ class TestZJIT < Test::Unit::TestCase }, insns: [:duphash] end + def test_pushtoarray + assert_compiles '[1, 2, 3]', %q{ + def test + [*[], 1, 2, 3] + end + test + }, insns: [:pushtoarray] + end + def test_setglobal_with_trace_var_exception assert_compiles '"rescued"', %q{ def test diff --git a/zjit/src/codegen.rs b/zjit/src/codegen.rs index 8b3f4f84be..f257e5c138 100644 --- a/zjit/src/codegen.rs +++ b/zjit/src/codegen.rs @@ -399,9 +399,9 @@ fn gen_insn(cb: &mut CodeBlock, jit: &mut JITState, asm: &mut Assembler, functio Insn::ObjToString { val, cd, state, .. } => gen_objtostring(jit, asm, opnd!(val), *cd, &function.frame_state(*state)), &Insn::CheckInterrupts { state } => no_output!(gen_check_interrupts(jit, asm, &function.frame_state(state))), &Insn::HashDup { val, state } => { gen_hash_dup(asm, opnd!(val), &function.frame_state(state)) }, + &Insn::ArrayPush { array, val, state } => { no_output!(gen_array_push(asm, opnd!(array), opnd!(val), &function.frame_state(state))) }, &Insn::ArrayExtend { state, .. } | &Insn::ArrayMax { state, .. } - | &Insn::ArrayPush { state, .. } | &Insn::DefinedIvar { state, .. } | &Insn::FixnumDiv { state, .. } | &Insn::FixnumMod { state, .. } @@ -689,6 +689,11 @@ fn gen_hash_dup(asm: &mut Assembler, val: Opnd, state: &FrameState) -> lir::Opnd asm_ccall!(asm, rb_hash_resurrect, val) } +fn gen_array_push(asm: &mut Assembler, array: Opnd, val: Opnd, state: &FrameState) { + gen_prepare_call_with_gc(asm, state); + asm_ccall!(asm, rb_ary_push, array, val); +} + /// Compile an interpreter entry block to be inserted into an ISEQ fn gen_entry_prologue(asm: &mut Assembler, iseq: IseqPtr) { asm_comment!(asm, "ZJIT entry point: {}", iseq_get_location(iseq, 0)); -- cgit v1.2.3