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

@@ -2276,8 +2276,16 @@
22762276 for (int s = 0; s < c->nscopes; s++) {
22772277 Scope *sc = &c->scopes[s];
22782278 if (sc->ret == TY_INT) sc->ret = TY_POLY;
2279- for (int i = 0; i < sc->nlocals; i++)
2279+ for (int i = 0; i < sc->nlocals; i++) {
2280+ /* Skip block params: they are typed by the iterated collection's
2281+ element type (an IntArray yields int elements), and the block
2282+ emitters already retype the param to that element type for the body
2283+ (use_shadow). Widening them to poly only creates an int/poly shadow
2284+ and inconsistent reads (e.g. `x.even?` keeps the stale poly type
2285+ while `x*2` sees the retyped int). Method params still widen. */
2286+ if (sc->locals[i].is_block_param) continue;
22802287 if (sc->locals[i].type == TY_INT) sc->locals[i].type = TY_POLY;
2288+ }
22812289 }
22822290 for (int ci = 0; ci < c->nclasses; ci++) {
22832291 ClassInfo *cl = &c->classes[ci];