From 22e488464a412afa58f201c49e54773aa8011320 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 23 Nov 2023 10:47:24 -0800 Subject: Add VM_CALL_ARGS_SPLAT_MUT callinfo flag This flag is set when the caller has already created a new array to handle a splat, such as for `f(*a, b)` and `f(*a, *b)`. Previously, if `f` was defined as `def f(*a)`, these calls would create an extra array on the callee side, instead of using the new array created by the caller. This modifies `setup_args_core` to set the flag whenver it would add a `splatarray true` instruction. However, when `splatarray true` is changed to `splatarray false` in the peephole optimizer, to avoid unnecessary allocations on the caller side, the flag must be removed. Add `optimize_args_splat_no_copy` and have the peephole optimizer call that. This significantly simplifies the related peephole optimizer code. On the callee side, in `setup_parameters_complex`, set `args->rest_dupped` to true if the flag is set. This takes a similar approach for optimizing regular splats that was previiously used for keyword splats in d2c41b1bff1f3102544bb0d03d4e82356d034d33 (via VM_CALL_KW_SPLAT_MUT). --- vm_callinfo.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'vm_callinfo.h') diff --git a/vm_callinfo.h b/vm_callinfo.h index 8437f2176c..2165582a2f 100644 --- a/vm_callinfo.h +++ b/vm_callinfo.h @@ -25,6 +25,7 @@ enum vm_call_flag_bits { VM_CALL_ZSUPER_bit, // zsuper VM_CALL_OPT_SEND_bit, // internal flag VM_CALL_KW_SPLAT_MUT_bit, // kw splat hash can be modified (to avoid allocating a new one) + VM_CALL_ARGS_SPLAT_MUT_bit, // args splat can be modified (to avoid allocating a new one) VM_CALL__END }; @@ -40,6 +41,7 @@ enum vm_call_flag_bits { #define VM_CALL_ZSUPER (0x01 << VM_CALL_ZSUPER_bit) #define VM_CALL_OPT_SEND (0x01 << VM_CALL_OPT_SEND_bit) #define VM_CALL_KW_SPLAT_MUT (0x01 << VM_CALL_KW_SPLAT_MUT_bit) +#define VM_CALL_ARGS_SPLAT_MUT (0x01 << VM_CALL_ARGS_SPLAT_MUT_bit) struct rb_callinfo_kwarg { int keyword_len; -- cgit v1.2.3