Commit 612af6c4
612af6c4b6f2Merged
Ryan Seys <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
feat(iexec): spread a sole splat arg across direct instance_exec block params
recv.instance_exec(*arr) { |a, b| } on a direct (explicit-receiver) lift
rejected the *arr with "unsupported expression: SplatNode". CRuby spreads a
single splat across the block's params exactly as passing the array directly
does (the auto-splat path).
Unwrap a sole SplatNode arg to its array operand in both the analyze-side
block-param typing and the codegen splice, then reuse the existing auto-splat
logic (bind each param to an element, typed from the array's element type). The
directly-passed-array form (instance_exec([3, 4]) { |a, b| }) is unchanged.
A splat also spreads across a single block param: instance_exec(*arr) { |a| }
binds a to arr[0] (the first spread positional arg), whereas a directly
passed array binds the whole array to a lone param. Gate the auto-splat path on
rnp >= 1 (analyze) / npar >= 1 (codegen) when the arg is explicitly
splatted, so the lone-param splat is spread rather than emitted as a raw
SplatNode (which would crash codegen).
Adds test/instance_exec_direct_splat.rb (int-array splat across two params, a
directly-passed array regression anchor, a string-array splat, and the
single-param splat for both int and string arrays).
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 612af6c4b6f2
- Parent
- 884b6f664d8e
src/analyze_pass.cmodifiedView file
trampoline param read), not the caller's args. */ int tramp_argc = strcmp(cname, "instance_exec") ? ie_tramp_effective_argc(c, id) : -1; /* auto-splat: a single array arg destructured across N>=2 params binds each to the element type. */ if (tramp_argc < 0 && iac == 1 && rnp >= 2) { TyKind a0 = infer_type(c, iav[0]); each to the element type. A sole splat (`instance_exec(*arr) { |a, b| }`) spreads the same way -- unwrap it to its array operand. A splat also spreads across a single param (`instance_exec(*arr) { |a| }` binds `a` to `arr[0]`), unlike a directly-passed array (which binds the whole array to a lone param), so allow `rnp >= 1` when explicitly splatted. */ int arg0 = (iac == 1 && iav) ? iav[0] : -1; int is_splat = arg0 >= 0 && nt_type(nt, arg0) && !strcmp(nt_type(nt, arg0), "SplatNode"); if (is_splat) arg0 = nt_ref(nt, arg0, "expression"); if (tramp_argc < 0 && iac == 1 && (rnp >= 2 || (rnp >= 1 && is_splat)) && arg0 >= 0) { TyKind a0 = infer_type(c, arg0); if (ty_is_array(a0)) { TyKind et = ty_array_elem(a0); for (int k = 0; k < rnp; k++) {src/codegen_call.cmodifiedView file
Loading diff…
test/instance_exec_direct_splat.rbaddedView file
Loading diff…
test/instance_exec_direct_splat.rb.expectedaddedView file
Loading diff…