Commit 3a748efd

3a748efd0df5Merged

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

Description

analyze: DCE backstop for BFS-reachable methods with TY_UNKNOWN params

BFS reachability marks all scopes with a given method name as reachable when that name is called anywhere. This over-approximates: a method may be name-matched but never have typed call sites bind its parameters, leaving them as TY_UNKNOWN, which causes exit(1) in codegen.

Add a post-fixpoint backstop that marks such methods unreachable so codegen silently skips them rather than crashing. This converts several ERR tests to PASS by allowing the rest of the program to compile when dead overloads have unresolvable param types.

Tests: 705 pass, 3 fail, 137 error (was 697/7/141)

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

Details

Commit
3a748efd0df5
Parent
4a2c4a5c9aa3

src/analyze.cmodifiedView file

@@ -5961,6 +5961,21 @@
59615961 }
59625962 }
59635963
5964+ /* Backstop: a reachable method still has TY_UNKNOWN params if it was never
5965+ called with typed arguments (BFS marked it live by name, but no typed call
5966+ site bound its args). Mark such methods unreachable so codegen skips them
5967+ rather than exit(1)ing on the unknown type. */
5968+ for (int s = 0; s < c->nscopes; s++) {
5969+ Scope *sc = &c->scopes[s];
5970+ if (!sc->reachable || sc->nparams == 0) continue;
5971+ int has_unknown = 0;
5972+ for (int i = 0; i < sc->nparams; i++) {
5973+ LocalVar *p = sc->pnames[i] ? scope_local(sc, sc->pnames[i]) : NULL;
5974+ if (p && p->type == TY_UNKNOWN) { has_unknown = 1; break; }
5975+ }
5976+ if (has_unknown) sc->reachable = 0;
5977+ }
5978+
59645979 /* finalize: gc-root needs + full node type cache */
59655980 for (int s = 0; s < c->nscopes; s++)
59665981 for (int i = 0; i < c->scopes[s].nlocals; i++)