mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Feedback, tests, and rebase for kwargs
This commit is contained in:
parent
c5acbd0208
commit
56b1b93a0c
3 changed files with 58 additions and 30 deletions
|
@ -2074,37 +2074,60 @@ assert_equal '["sub", "sub"]', %q{
|
||||||
[foo(sub), foo(sub)]
|
[foo(sub), foo(sub)]
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_equal '[[1, 2, 3, 4]]', %q{
|
# leading and keyword arguments are swapped into the right order
|
||||||
def four(a:, b:, c:, d:)
|
assert_equal '[[1, 2, 3, 4, 5, 6]]', %q{
|
||||||
[a, b, c, d]
|
def kwargs(five, six, a:, b:, c:, d:)
|
||||||
|
[a, b, c, d, five, six]
|
||||||
end
|
end
|
||||||
|
|
||||||
5.times.flat_map do
|
5.times.flat_map do
|
||||||
[
|
[
|
||||||
four(a: 1, b: 2, c: 3, d: 4),
|
kwargs(5, 6, a: 1, b: 2, c: 3, d: 4),
|
||||||
four(a: 1, b: 2, d: 4, c: 3),
|
kwargs(5, 6, a: 1, b: 2, d: 4, c: 3),
|
||||||
four(a: 1, c: 3, b: 2, d: 4),
|
kwargs(5, 6, a: 1, c: 3, b: 2, d: 4),
|
||||||
four(a: 1, c: 3, d: 4, b: 2),
|
kwargs(5, 6, a: 1, c: 3, d: 4, b: 2),
|
||||||
four(a: 1, d: 4, b: 2, c: 3),
|
kwargs(5, 6, a: 1, d: 4, b: 2, c: 3),
|
||||||
four(a: 1, d: 4, c: 3, b: 2),
|
kwargs(5, 6, a: 1, d: 4, c: 3, b: 2),
|
||||||
four(b: 2, a: 1, c: 3, d: 4),
|
kwargs(5, 6, b: 2, a: 1, c: 3, d: 4),
|
||||||
four(b: 2, a: 1, d: 4, c: 3),
|
kwargs(5, 6, b: 2, a: 1, d: 4, c: 3),
|
||||||
four(b: 2, c: 3, a: 1, d: 4),
|
kwargs(5, 6, b: 2, c: 3, a: 1, d: 4),
|
||||||
four(b: 2, c: 3, d: 4, a: 1),
|
kwargs(5, 6, b: 2, c: 3, d: 4, a: 1),
|
||||||
four(b: 2, d: 4, a: 1, c: 3),
|
kwargs(5, 6, b: 2, d: 4, a: 1, c: 3),
|
||||||
four(b: 2, d: 4, c: 3, a: 1),
|
kwargs(5, 6, b: 2, d: 4, c: 3, a: 1),
|
||||||
four(c: 3, a: 1, b: 2, d: 4),
|
kwargs(5, 6, c: 3, a: 1, b: 2, d: 4),
|
||||||
four(c: 3, a: 1, d: 4, b: 2),
|
kwargs(5, 6, c: 3, a: 1, d: 4, b: 2),
|
||||||
four(c: 3, b: 2, a: 1, d: 4),
|
kwargs(5, 6, c: 3, b: 2, a: 1, d: 4),
|
||||||
four(c: 3, b: 2, d: 4, a: 1),
|
kwargs(5, 6, c: 3, b: 2, d: 4, a: 1),
|
||||||
four(c: 3, d: 4, a: 1, b: 2),
|
kwargs(5, 6, c: 3, d: 4, a: 1, b: 2),
|
||||||
four(c: 3, d: 4, b: 2, a: 1),
|
kwargs(5, 6, c: 3, d: 4, b: 2, a: 1),
|
||||||
four(d: 4, a: 1, b: 2, c: 3),
|
kwargs(5, 6, d: 4, a: 1, b: 2, c: 3),
|
||||||
four(d: 4, a: 1, c: 3, b: 2),
|
kwargs(5, 6, d: 4, a: 1, c: 3, b: 2),
|
||||||
four(d: 4, b: 2, a: 1, c: 3),
|
kwargs(5, 6, d: 4, b: 2, a: 1, c: 3),
|
||||||
four(d: 4, b: 2, c: 3, a: 1),
|
kwargs(5, 6, d: 4, b: 2, c: 3, a: 1),
|
||||||
four(d: 4, c: 3, a: 1, b: 2),
|
kwargs(5, 6, d: 4, c: 3, a: 1, b: 2),
|
||||||
four(d: 4, c: 3, b: 2, a: 1)
|
kwargs(5, 6, d: 4, c: 3, b: 2, a: 1)
|
||||||
]
|
]
|
||||||
end.uniq
|
end.uniq
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# implicit hashes get skipped and don't break compilation
|
||||||
|
assert_equal '[[:key]]', %q{
|
||||||
|
def implicit(hash)
|
||||||
|
hash.keys
|
||||||
|
end
|
||||||
|
|
||||||
|
5.times.map { implicit(key: :value) }.uniq
|
||||||
|
}
|
||||||
|
|
||||||
|
# default values on keywords don't mess up argument order
|
||||||
|
assert_equal '[2]', %q{
|
||||||
|
def default_value
|
||||||
|
1
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_expression(value: default_value)
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
|
5.times.map { default_expression(value: 2) }.uniq
|
||||||
|
}
|
||||||
|
|
5
yjit.c
5
yjit.c
|
@ -73,9 +73,14 @@ YJIT_DECLARE_COUNTERS(
|
||||||
send_cfunc_argc_mismatch,
|
send_cfunc_argc_mismatch,
|
||||||
send_cfunc_toomany_args,
|
send_cfunc_toomany_args,
|
||||||
send_cfunc_tracing,
|
send_cfunc_tracing,
|
||||||
|
send_cfunc_kwargs,
|
||||||
|
send_attrset_kwargs,
|
||||||
send_iseq_tailcall,
|
send_iseq_tailcall,
|
||||||
send_iseq_arity_error,
|
send_iseq_arity_error,
|
||||||
send_iseq_only_keywords,
|
send_iseq_only_keywords,
|
||||||
|
send_iseq_kwargs_req_and_opt_missing,
|
||||||
|
send_iseq_kwargs_none_passed,
|
||||||
|
send_iseq_kwargs_mismatch,
|
||||||
send_iseq_complex_callee,
|
send_iseq_complex_callee,
|
||||||
send_not_implemented_method,
|
send_not_implemented_method,
|
||||||
send_getter_arity,
|
send_getter_arity,
|
||||||
|
|
|
@ -775,7 +775,7 @@ gen_dupn(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stack_swap(ctx_t* ctx, codeblock_t* cb, int offset0, int offset1, x86opnd_t reg0, x86opnd_t reg1)
|
stack_swap(ctx_t *ctx, codeblock_t *cb, int offset0, int offset1, x86opnd_t reg0, x86opnd_t reg1)
|
||||||
{
|
{
|
||||||
x86opnd_t opnd0 = ctx_stack_opnd(ctx, offset0);
|
x86opnd_t opnd0 = ctx_stack_opnd(ctx, offset0);
|
||||||
x86opnd_t opnd1 = ctx_stack_opnd(ctx, offset1);
|
x86opnd_t opnd1 = ctx_stack_opnd(ctx, offset1);
|
||||||
|
@ -794,7 +794,7 @@ stack_swap(ctx_t* ctx, codeblock_t* cb, int offset0, int offset1, x86opnd_t reg0
|
||||||
|
|
||||||
// Swap top 2 stack entries
|
// Swap top 2 stack entries
|
||||||
static codegen_status_t
|
static codegen_status_t
|
||||||
gen_swap(jitstate_t* jit, ctx_t* ctx, codeblock_t* cb)
|
gen_swap(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb)
|
||||||
{
|
{
|
||||||
stack_swap(ctx , cb, 0, 1, REG0, REG1);
|
stack_swap(ctx , cb, 0, 1, REG0, REG1);
|
||||||
return YJIT_KEEP_COMPILING;
|
return YJIT_KEEP_COMPILING;
|
||||||
|
@ -3819,7 +3819,7 @@ gen_send_general(jitstate_t *jit, ctx_t *ctx, struct rb_call_data *cd, rb_iseq_t
|
||||||
}
|
}
|
||||||
case VM_METHOD_TYPE_ATTRSET:
|
case VM_METHOD_TYPE_ATTRSET:
|
||||||
if ((vm_ci_flag(ci) & VM_CALL_KWARG) != 0) {
|
if ((vm_ci_flag(ci) & VM_CALL_KWARG) != 0) {
|
||||||
GEN_COUNTER_INC(cb, send_attrset_keywords);
|
GEN_COUNTER_INC(cb, send_attrset_kwargs);
|
||||||
return YJIT_CANT_COMPILE;
|
return YJIT_CANT_COMPILE;
|
||||||
} else if (argc != 1 || !RB_TYPE_P(comptime_recv, T_OBJECT)) {
|
} else if (argc != 1 || !RB_TYPE_P(comptime_recv, T_OBJECT)) {
|
||||||
GEN_COUNTER_INC(cb, send_ivar_set_method);
|
GEN_COUNTER_INC(cb, send_ivar_set_method);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue