Commit cc869197

cc869197cab3Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified

Description

Merge pull request #1433 from ryanseys/rs-c-iexec-direct-splat

feat(iexec): spread a sole splat arg across direct instance_exec block params

Details

Commit
cc869197cab3
Parent
e37b7ecf5d83
Merge parent
612af6c4b6f2

src/analyze_pass.cmodifiedView file

@@ -2045,9 +2045,16 @@
20452045 trampoline param read), not the caller's args. */
20462046 int tramp_argc = strcmp(cname, "instance_exec") ? ie_tramp_effective_argc(c, id) : -1;
20472047 /* auto-splat: a single array arg destructured across N>=2 params binds
2048- each to the element type. */
2049- if (tramp_argc < 0 && iac == 1 && rnp >= 2) {
2050- TyKind a0 = infer_type(c, iav[0]);
2048+ each to the element type. A sole splat (`instance_exec(*arr) { |a, b| }`)
2049+ spreads the same way -- unwrap it to its array operand. A splat also
2050+ spreads across a single param (`instance_exec(*arr) { |a| }` binds `a`
2051+ to `arr[0]`), unlike a directly-passed array (which binds the whole array
2052+ to a lone param), so allow `rnp >= 1` when explicitly splatted. */
2053+ int arg0 = (iac == 1 && iav) ? iav[0] : -1;
2054+ int is_splat = arg0 >= 0 && nt_type(nt, arg0) && !strcmp(nt_type(nt, arg0), "SplatNode");
2055+ if (is_splat) arg0 = nt_ref(nt, arg0, "expression");
2056+ if (tramp_argc < 0 && iac == 1 && (rnp >= 2 || (rnp >= 1 && is_splat)) && arg0 >= 0) {
2057+ TyKind a0 = infer_type(c, arg0);
20512058 if (ty_is_array(a0)) {
20522059 TyKind et = ty_array_elem(a0);
20532060 for (int k = 0; k < rnp; k++) {