Commit 76e18f57
76e18f573934Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
WIP: experimental full int->poly widen under promote (g_promote_mode gate)
Widen every statically-int slot (param/return/local/ivar/cvar) to poly so a
function-argument overflow promotes at runtime: def mul(x,y)=x*y; mul(10**15,10**15) now yields 10**30 (the plan's "本丸" #1). Small values stay
inline (SP_TAG_INT, no heap), so this is far cheaper than legacy's all-bigint
widen -- validating the poly direction.
Default gate intact (g_promote_mode gate). Promote suite regresses 993 -> 831 (32 fail / 130 error): the boundary buckets where a widened poly slot meets a non-poly site and codegen does not yet coerce. NOT for master until the buckets are closed.
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 76e18f573934
- Parent
- 3c24d8128da7
src/analyze.cmodifiedView file
if (!ch) break; } /* --int-overflow=promote: widen every statically-int slot (param / return / local / ivar / cvar) to poly so an arithmetic result that overflows int64 can be carried as a boxed bigint (sp_poly_add/mul promote at runtime). A poly slot still holds a small value inline (SP_TAG_INT, no heap), so this is far cheaper than the legacy "everything becomes sp_Bigint*" widen. Done after the fixpoint and before the final node-type cache so reads pick up the widened slot types. TY_BIGINT loop vars (detect_bigint_loop_vars) stay bigint. EXPERIMENTAL: gated by g_promote_mode; default/wrap untouched. */ if (g_promote_mode) { for (int s = 0; s < c->nscopes; s++) { Scope *sc = &c->scopes[s]; if (sc->ret == TY_INT) sc->ret = TY_POLY; for (int i = 0; i < sc->nlocals; i++) if (sc->locals[i].type == TY_INT) sc->locals[i].type = TY_POLY; } for (int ci = 0; ci < c->nclasses; ci++) { ClassInfo *cl = &c->classes[ci]; for (int i = 0; i < cl->nivars; i++) if (cl->ivar_types[i] == TY_INT) cl->ivar_types[i] = TY_POLY; for (int i = 0; i < cl->ncvars; i++) if (cl->cvar_types[i] == TY_INT) cl->cvar_types[i] = TY_POLY; } } /* finalize: gc-root needs + full node type cache */ for (int s = 0; s < c->nscopes; s++) for (int i = 0; i < c->scopes[s].nlocals; i++)