Commit 20a6038f
20a6038f97f3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Optimistically re-narrow poly slots after the fixpoint
The monotonic fixpoint locks a slot to poly the first time it sees a transient poly -- a value read before its type settled, or an index/hash promotion driven by a key that was poly at the time. Once an upstream value later resolves to int (e.g. @io_addr after the nested-array narrow), the downstream slots that locked on its earlier poly state stay stuck.
After the fixpoint, reset every poly ivar and poly non-block param to UNKNOWN once and re-run the monotonic passes. The non-poly slots are now stable, so a slot whose entire contribution closure is concrete re-narrows to that type; a genuinely heterogeneous slot re-widens to poly. This is a sound monotonic re-derivation over fixed inputs.
Dissolves the cleared transient-poly cycles (the PPU register/sprite slots that had locked on @io_addr's earlier poly). optcarrot ~527 -> ~626 fps, checksum 59662. make test 845, make bench 57.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 20a6038f97f3
- Parent
- 1862c705e7fd
src/analyze.cmodifiedView file
if (!ch) break; } /* Optimistic re-narrow: the monotonic fixpoint locks a slot to poly the first time it sees a transient poly (a value read before its type settled, or an index/hash promotion driven by a then-poly key). Reset every poly ivar and poly (non-block) param to UNKNOWN once, then re-run the monotonic passes. With the now-stable concrete slots feeding them, a slot whose entire contribution closure is concrete re-narrows; one with a genuine heterogeneous contribution re-widens to poly. Sound (monotonic re-derive over fixed inputs); dissolves the cleared transient-poly cycles. */ { int any = 0; for (int ci = 0; ci < c->nclasses; ci++) for (int iv = 0; iv < c->classes[ci].nivars; iv++) if (c->classes[ci].ivar_types[iv] == TY_POLY) { c->classes[ci].ivar_types[iv] = TY_UNKNOWN; any = 1; } for (int s = 0; s < c->nscopes; s++) { Scope *sc = &c->scopes[s]; for (int i = 0; i < sc->nparams; i++) { LocalVar *p = scope_local(sc, sc->pnames[i]); if (p && p->type == TY_POLY && !p->is_block_param) { p->type = TY_UNKNOWN; any = 1; } } } if (any) { for (int iter = 0; iter < 128; iter++) { int ch = 0; ch |= infer_write_types(c); ch |= infer_param_types(c); ch |= propagate_prep_params(c); ch |= infer_string_params(c); ch |= infer_default_param_types(c); ch |= infer_block_params(c); ch |= infer_for_index(c); ch |= infer_global_const_types(c); ch |= infer_multiwrite_const_types(c); ch |= infer_ivar_types(c); ch |= infer_cvar_types(c); ch |= infer_inherited_ivars(c); ch |= infer_return_types(c); if (!ch) break; } } } /* Backstop: a parameter still unknown but with a `= nil` default is a nullable param -- represent it as poly so it can hold nil or a value. Also widen TY_SYMBOL/TY_BOOL params: those types have no nil sentinel