Commit 41c87970

41c879704177Merged

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

Description

Keep index-filled array ivars typed instead of promoting to a hash

@a[i] = v with an int key promoted a TY_UNKNOWN ivar slot toward an int-keyed hash, which then unified with the array-literal construction write (@a = [x]*n) to poly. The existing guard that skips usage-driven hash promotion when a typed construction write exists only applied to plain reads; extend it to []= index-writes. A genuine hash (@h = {}) infers UNKNOWN from its empty literal and is unaffected, so only ivars with a concrete array-typed construction are protected.

Together with the splat-literal fix this de-polys optcarrot's @palette -> @output_color -> render_pixel chain: best-of-15 628 -> 731 fps (legacy 735), checksum 59662 unchanged. Gates: 845 test, 57 bench green.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
41c879704177
Parent
ee4d5394f518

src/analyze_pass.cmodifiedView file

@@ -748,7 +748,12 @@
748748 (but allow push-driven array promotion through). Without this guard,
749749 @free[0] read promotes @free to poly_poly_hash before @free = []
750750 has been processed as an array. */
751- if (!is_push && !is_idx_write && *slot == TY_UNKNOWN && inm) {
751+ /* A typed (non-nil) construction write — `@a = [x]*n`, `@a = arr.map{}`,
752+ or an `@a = []` literal — means this ivar is an array filled by index,
753+ not a hash. Skip usage-driven hash promotion for both plain reads and
754+ `@a[k]=v` index-writes. A genuine hash (`@h = {}`) infers UNKNOWN from
755+ its empty literal and is unaffected. */
756+ if (!is_push && *slot == TY_UNKNOWN && inm) {
752757 int has_typed_write = 0;
753758 for (int _wi = 0; _wi < nt->count && !has_typed_write; _wi++) {
754759 if (!nt_type(nt, _wi) || strcmp(nt_type(nt, _wi), "InstanceVariableWriteNode")) continue;