Skip to content

Commit

Permalink
RJIT: Support optional params on splat
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 25, 2023
1 parent 85a55d3 commit 9bc2dbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
18 changes: 11 additions & 7 deletions lib/ruby_vm/rjit/insn_compiler.rb
Expand Up @@ -4078,17 +4078,21 @@ def jit_call_iseq_setup(jit, ctx, asm, cme, flags, argc, iseq, block_handler, se
def jit_call_iseq_setup_normal(jit, ctx, asm, cme, flags, argc, iseq, block_handler, opt_pc, send_shift:, frame_type:, prev_ep: nil)
# Push splat args, which was skipped in jit_caller_setup_arg.
if flags & C::VM_CALL_ARGS_SPLAT != 0
if iseq.body.param.opt_num != 0
asm.incr_counter(:send_args_splat_opt_num) # not supported yet
return CantCompile
end
lead_num = iseq.body.param.lead_num
opt_num = iseq.body.param.opt_num

array_length = jit.peek_at_stack(flags & C::VM_CALL_ARGS_BLOCKARG != 0 ? 1 : 0)&.length || 0 # blockarg is not popped yet
if iseq.body.param.lead_num != array_length + argc - 1
if opt_num == 0 && lead_num != array_length + argc - 1
asm.incr_counter(:send_args_splat_arity_error)
return CantCompile
end

remaining_opt = (opt_num + lead_num) - (array_length + argc - 1)
if opt_num > 0
# We are going to jump to the correct offset based on how many optional params are remaining.
opt_pc = iseq.body.param.opt_table[opt_num - remaining_opt]
end

# We are going to assume that the splat fills all the remaining arguments.
# In the generated code we test if this is true and if not side exit.
argc = argc - 1 + array_length
Expand Down Expand Up @@ -4694,7 +4698,7 @@ def jit_callee_setup_arg(jit, ctx, asm, flags, argc, iseq)

return 0
elsif C.rb_iseq_only_optparam_p(iseq)
if jit_caller_setup_arg(jit, ctx, asm, flags) == CantCompile
if jit_caller_setup_arg(jit, ctx, asm, flags, splat: true) == CantCompile
return CantCompile
end
if jit_caller_remove_empty_kw_splat(jit, ctx, asm, flags) == CantCompile
Expand Down Expand Up @@ -4728,7 +4732,7 @@ def jit_callee_setup_arg(jit, ctx, asm, flags, argc, iseq)
# @param asm [RubyVM::RJIT::Assembler]
def jit_callee_setup_block_arg(jit, ctx, asm, calling, iseq, arg_setup_type:)
if C.rb_simple_iseq_p(iseq)
if jit_caller_setup_arg(jit, ctx, asm, calling.flags) == CantCompile
if jit_caller_setup_arg(jit, ctx, asm, calling.flags, splat: true) == CantCompile
return CantCompile
end

Expand Down
1 change: 0 additions & 1 deletion rjit_c.h
Expand Up @@ -24,7 +24,6 @@ RJIT_RUNTIME_COUNTERS(
send_args_splat,
send_args_splat_not_array,
send_args_splat_length_not_equal,
send_args_splat_opt_num,
send_args_splat_arity_error,
send_args_splat_ruby2_hash,
send_kw_splat,
Expand Down
1 change: 0 additions & 1 deletion rjit_c.rb
Expand Up @@ -1278,7 +1278,6 @@ def C.rb_rjit_runtime_counters
send_args_splat: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat)")],
send_args_splat_not_array: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat_not_array)")],
send_args_splat_length_not_equal: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat_length_not_equal)")],
send_args_splat_opt_num: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat_opt_num)")],
send_args_splat_arity_error: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat_arity_error)")],
send_args_splat_ruby2_hash: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_args_splat_ruby2_hash)")],
send_kw_splat: [CType::Immediate.parse("size_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_rjit_runtime_counters *)NULL)), send_kw_splat)")],
Expand Down

0 comments on commit 9bc2dbd

Please sign in to comment.