diff options
author | Takashi Kokubun <[email protected]> | 2023-03-25 01:07:36 -0700 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-25 01:17:05 -0700 |
commit | 9bc2dbd33cd25281fe14d01bbe5b460176db1010 (patch) | |
tree | df9fc7be7cc71f3341b987f25f02c11fcfd7e8cc /lib/ruby_vm/rjit/insn_compiler.rb | |
parent | 85a55d3e75fd98e7a0462ad289630d64ff31da84 (diff) |
RJIT: Support optional params on splat
Diffstat (limited to 'lib/ruby_vm/rjit/insn_compiler.rb')
-rw-r--r-- | lib/ruby_vm/rjit/insn_compiler.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb index 5fb2a5fa7a..395c0ba227 100644 --- a/lib/ruby_vm/rjit/insn_compiler.rb +++ b/lib/ruby_vm/rjit/insn_compiler.rb @@ -4078,17 +4078,21 @@ module RubyVM::RJIT 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 @@ -4694,7 +4698,7 @@ module RubyVM::RJIT 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 @@ -4728,7 +4732,7 @@ module RubyVM::RJIT # @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 |