Commit 9c0c192b
9c0c192be53aMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
spinel-c: fix transplanted-method param type propagation and ivar push inference
Two analyzer fixes that together move 6 ERR tests to PASS.
-
Transplanted-module param backstop: when
include A::Bcopies methods to multiple classes (e.g. Host and Nested::Sub), all copies share the same def_node. If one copy gets param types from call sites but another is never called, the uncalled copy had TY_UNKNOWN params and failed emit. New backstop after the main fixpoint propagates known types from sibling scopes (same def_node) to param slots still TY_UNKNOWN. Fixes: include_constant_path, inlined_yield_block_param_type, inlined_yield_self_locals, module_ivar_nil_poly, poly_each_receiver_gc_root. -
!is_pushguard in ivar usage inference: the empty-array/hash guard that prevents@ivar = []from being hash-promoted via a [] read was also preventing push-driven array type inference. Added!is_pushpredicate so @ivar.push(str) correctly widens @ivar to StrArray. Fixes: bundle_classd_09 (log ivar typed as IntArray instead of StrArray).
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 9c0c192be53a
- Parent
- ad64624868d9
src/analyze.cmodifiedView file
slot = &ci->ivar_types[iv]; /* If the slot is TY_UNKNOWN but has a direct InstanceVariableWriteNode that assigns a typed value OR an empty array/hash literal (e.g. @buf = [nil]*7 or @free = []), skip usage-driven hash promotion. Without this guard, @free[0] read promotes @free to poly_poly_hash before @free = [] has been processed as an array. */ if (*slot == TY_UNKNOWN && inm) { @buf = [nil]*7 or @free = []), skip usage-driven hash promotion (but allow push-driven array promotion through). Without this guard, @free[0] read promotes @free to poly_poly_hash before @free = [] has been processed as an array. */ if (!is_push && *slot == TY_UNKNOWN && inm) { int has_typed_write = 0; for (int _wi = 0; _wi < nt->count && !has_typed_write; _wi++) { if (!nt_type(nt, _wi) || strcmp(nt_type(nt, _wi), "InstanceVariableWriteNode")) continue; } } /* Backstop: transplanted module scopes share the same def_node. If one copy has known param types (from call sites) but another copy lacks callers and has TY_UNKNOWN params, propagate the known types across. */ for (int s1 = 0; s1 < c->nscopes; s1++) { Scope *sc1 = &c->scopes[s1]; if (sc1->nparams == 0 || sc1->def_node < 0 || !sc1->name) continue; for (int pi = 0; pi < sc1->nparams; pi++) { if (!sc1->pnames[pi]) continue; LocalVar *p1 = scope_local(sc1, sc1->pnames[pi]); if (!p1 || p1->type != TY_UNKNOWN) continue; for (int s2 = 0; s2 < c->nscopes; s2++) { if (s2 == s1) continue; Scope *sc2 = &c->scopes[s2]; if (sc2->def_node != sc1->def_node || sc2->nparams != sc1->nparams) continue; if (pi >= sc2->nparams || !sc2->pnames[pi]) continue; LocalVar *p2 = scope_local(sc2, sc2->pnames[pi]); if (!p2 || p2->type == TY_UNKNOWN) continue; p1->type = p2->type; break; } } } /* Backstop: an ivar assigned only an empty array literal (no element evidence from usage) is left UNKNOWN, which falls back to int and a scalar struct field. Default such a slot to an (empty) int array so the