Commit 87ff5492

87ff5492ae57Merged

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

Description

Add poly receiver multi-param block destructuring in each iteration

When a poly receiver is iterated with 2+ block params, auto-splat the poly element across the params. Analyze assigns TY_POLY to all block params; codegen fetches the element then indexes into it for each param.

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
87ff5492ae57
Parent
d0104eb864c8

src/analyze.cmodifiedView file

@@ -3833,6 +3833,21 @@
38333833
38343834 if (pt == TY_UNKNOWN) continue;
38353835 Scope *s = comp_scope_of(c, block);
3836+ /* When iterating a poly receiver (TY_POLY) with 2+ block params, all params
3837+ are poly (auto-splat from the poly element). Assign TY_POLY to all. */
3838+ if (pt == TY_POLY) {
3839+ int npp2 = 0; while (block_param_name(c, block, npp2)) npp2++;
3840+ if (npp2 >= 2) {
3841+ for (int pj2 = 0; pj2 < npp2; pj2++) {
3842+ const char *pnj2 = block_param_name(c, block, pj2);
3843+ if (!pnj2) continue;
3844+ LocalVar *lp2 = scope_local_intern(s, pnj2); lp2->is_block_param = 1;
3845+ TyKind m2 = ty_unify(lp2->type, TY_POLY);
3846+ if (m2 != lp2->type) { lp2->type = m2; changed = 1; }
3847+ }
3848+ continue;
3849+ }
3850+ }
38363851 LocalVar *lv = scope_local_intern(s, p0); lv->is_block_param = 1;
38373852 /* Don't widen an array-typed variable to a scalar via block-param
38383853 inference. When the variable already holds an array (set by a write