Commit d426578d

d426578de4e9Merged

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

Description

analyze: push wins over [] read when promoting empty-array locals

A variable assigned [] then used both as a << x and a[i] (read) was being mis-typed as TY_POLY_POLY_HASH. The body-usage pass iterates nodes in source order; a[i] read promotion fires before a << x can set the type when the element type is unknown on the first fixpoint pass. On the next pass the hash type blocked the array promotion (line !ty_is_array(*slot) guard).

Fix: when the push case sees a hash-typed slot, reset it to UNKNOWN so the array promotion can fire. A variable that receives << is always an array, not a hash.

Fixes: file_basename_gc, module_ivar_empty_hash_reset, and two related implicit_alloc_site tests (+4 pass, 624->620 ERR).

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

Details

Commit
d426578de4e9
Parent
cc1ae79a0c0d

src/analyze.cmodifiedView file

@@ -2913,6 +2913,10 @@
29132913 PolyArray (ty_unify would return TY_POLY scalar, so use array-aware
29142914 widening instead). */
29152915 if (vt == TY_UNKNOWN) continue;
2916+ /* If a [] read already promoted this slot to a hash type, the push
2917+ wins: a variable that is pushed to is an array, not a hash.
2918+ Reset the slot so the array promotion below can fire. */
2919+ if (ty_is_hash(*slot)) *slot = TY_UNKNOWN;
29162920 if (*slot != TY_UNKNOWN && !ty_is_array(*slot)) continue;
29172921 if (*slot == TY_POLY_ARRAY) continue; /* already widest array type */
29182922 TyKind want = ty_array_of(vt);