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.

  1. Transplanted-module param backstop: when include A::B copies 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.

  2. !is_push guard 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_push predicate 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

@@ -3719,10 +3719,11 @@
37193719 slot = &ci->ivar_types[iv];
37203720 /* If the slot is TY_UNKNOWN but has a direct InstanceVariableWriteNode
37213721 that assigns a typed value OR an empty array/hash literal (e.g.
3722- @buf = [nil]*7 or @free = []), skip usage-driven hash promotion.
3723- Without this guard, @free[0] read promotes @free to poly_poly_hash
3724- before @free = [] has been processed as an array. */
3725- if (*slot == TY_UNKNOWN && inm) {
3722+ @buf = [nil]*7 or @free = []), skip usage-driven hash promotion
3723+ (but allow push-driven array promotion through). Without this guard,
3724+ @free[0] read promotes @free to poly_poly_hash before @free = []
3725+ has been processed as an array. */
3726+ if (!is_push && *slot == TY_UNKNOWN && inm) {
37263727 int has_typed_write = 0;
37273728 for (int _wi = 0; _wi < nt->count && !has_typed_write; _wi++) {
37283729 if (!nt_type(nt, _wi) || strcmp(nt_type(nt, _wi), "InstanceVariableWriteNode")) continue;
@@ -5674,6 +5675,29 @@
56745675 }
56755676 }
56765677
5678+ /* Backstop: transplanted module scopes share the same def_node. If one
5679+ copy has known param types (from call sites) but another copy lacks callers
5680+ and has TY_UNKNOWN params, propagate the known types across. */
5681+ for (int s1 = 0; s1 < c->nscopes; s1++) {
5682+ Scope *sc1 = &c->scopes[s1];
5683+ if (sc1->nparams == 0 || sc1->def_node < 0 || !sc1->name) continue;
5684+ for (int pi = 0; pi < sc1->nparams; pi++) {
5685+ if (!sc1->pnames[pi]) continue;
5686+ LocalVar *p1 = scope_local(sc1, sc1->pnames[pi]);
5687+ if (!p1 || p1->type != TY_UNKNOWN) continue;
5688+ for (int s2 = 0; s2 < c->nscopes; s2++) {
5689+ if (s2 == s1) continue;
5690+ Scope *sc2 = &c->scopes[s2];
5691+ if (sc2->def_node != sc1->def_node || sc2->nparams != sc1->nparams) continue;
5692+ if (pi >= sc2->nparams || !sc2->pnames[pi]) continue;
5693+ LocalVar *p2 = scope_local(sc2, sc2->pnames[pi]);
5694+ if (!p2 || p2->type == TY_UNKNOWN) continue;
5695+ p1->type = p2->type;
5696+ break;
5697+ }
5698+ }
5699+ }
5700+
56775701 /* Backstop: an ivar assigned only an empty array literal (no element
56785702 evidence from usage) is left UNKNOWN, which falls back to int and a
56795703 scalar struct field. Default such a slot to an (empty) int array so the