diff options
author | John Hawthorn <john@hawthorn.email> | 2022-01-05 01:07:52 -0800 |
---|---|---|
committer | John Hawthorn <john@hawthorn.email> | 2022-01-08 11:40:55 -0800 |
commit | 18b97eee5ace0fc70bf4e6d61092ad9fbade5f56 (patch) | |
tree | c4f14fbf3d514a78499caaf007bd2dd7b8bc652b /yjit_codegen.c | |
parent | b5c039125fe375f91b9795a5e1b29febaa12d072 (diff) |
YJIT: Add support for ruby array cfuncs (argc=-2)
This adds support for cfuncs which take variable arguments using a Ruby
array. This is specified with the method entry's argc == -2.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5396
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index c9a4404550..c8de630747 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -3244,12 +3244,6 @@ gen_send_cfunc(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const { const rb_method_cfunc_t *cfunc = UNALIGNED_MEMBER_PTR(cme->def, body.cfunc); - // If the function expects a Ruby array of arguments - if (cfunc->argc < 0 && cfunc->argc != -1) { - GEN_COUNTER_INC(cb, send_cfunc_ruby_array_varg); - return YJIT_CANT_COMPILE; - } - // If the argument count doesn't match if (cfunc->argc >= 0 && cfunc->argc != argc) { GEN_COUNTER_INC(cb, send_cfunc_argc_mismatch); @@ -3402,6 +3396,28 @@ gen_send_cfunc(jitstate_t *jit, ctx_t *ctx, const struct rb_callinfo *ci, const lea(cb, C_ARG_REGS[1], ctx_stack_opnd(ctx, argc - 1)); mov(cb, C_ARG_REGS[2], ctx_stack_opnd(ctx, argc)); } + // Variadic method with Ruby array + if (cfunc->argc == -2) { + // Create a Ruby array from the arguments. + // + // This follows similar behaviour to vm_call_cfunc_with_frame() and + // call_cfunc_m2(). We use rb_ec_ary_new_from_values() instead of + // rb_ary_new4() since we have REG_EC available. + // + // Before getting here we will have set the new CFP in the EC, and the + // stack at CFP's SP will contain the values we are inserting into the + // Array, so they will be properly marked if we hit a GC. + + // rb_ec_ary_new_from_values(rb_execution_context_t *ec, long n, const VLAUE *elts) + mov(cb, C_ARG_REGS[0], REG_EC); + mov(cb, C_ARG_REGS[1], imm_opnd(argc)); + lea(cb, C_ARG_REGS[2], ctx_stack_opnd(ctx, argc - 1)); + call_ptr(cb, REG0, (void *)rb_ec_ary_new_from_values); + + // rb_file_s_join(VALUE recv, VALUE args) + mov(cb, C_ARG_REGS[0], ctx_stack_opnd(ctx, argc)); + mov(cb, C_ARG_REGS[1], RAX); + } // Pop the C function arguments from the stack (in the caller) ctx_stack_pop(ctx, argc + 1); |