Commit 9c94f540
9c94f5400377Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
analyze: exclude block params from the promote int->poly widen
Block parameters are typed by the collection they iterate (an IntArray yields
int elements), and the block emitters already retype the param to that element
type for the body (the use_shadow path). Widening such a param to poly only
creates an int/poly shadow declaration plus inconsistent reads: x.even? reads
the stale poly slot type (emitting sp_poly_to_i on an int C variable) while
x*2 sees the retyped int, because operator inference refreshes its operands
but method-call inference reads the receiver type from cache. Skipping
is_block_param locals makes promote treat block params exactly like default
mode -- consistent and correct. Method params still widen (that is the whole
point of promote: a caller may pass an overflowing value).
promote test 860->901 (+41; also clears the matching output-mismatch FAILs). default and optcarrot are g_promote_mode-gated and unchanged (992/0/0, checksum 59662).
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 9c94f5400377
- Parent
- e9e3d43d23d3
src/analyze.cmodifiedView file
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++) for (int i = 0; i < sc->nlocals; i++) { /* Skip block params: they are typed by the iterated collection's element type (an IntArray yields int elements), and the block emitters already retype the param to that element type for the body (use_shadow). Widening them to poly only creates an int/poly shadow and inconsistent reads (e.g. `x.even?` keeps the stale poly type while `x*2` sees the retyped int). Method params still widen. */ if (sc->locals[i].is_block_param) continue; 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];