Commit 2d752437

2d7524373b5dMerged

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

Description

analyze: keep a <=> method's return int under the promote widen

A user <=> returns a bounded -1/0/1 and is consumed as (a <=> b) <cmp> 0. Widening its return to poly forces every comparison onto a poly path while the result can never overflow, and leaves sp_RbVal <cmp> int mismatches at the call sites. Exclude scopes named <=> from the return widen. Unblocks lrama_features. (g_promote_mode-gated; default unchanged.)

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
2d7524373b5d
Parent
bc3ea827e489

src/analyze.cmodifiedView file

@@ -2275,7 +2275,11 @@
22752275 if (g_promote_mode) {
22762276 for (int s = 0; s < c->nscopes; s++) {
22772277 Scope *sc = &c->scopes[s];
2278- if (sc->ret == TY_INT) sc->ret = TY_POLY;
2278+ /* `<=>` yields a bounded -1/0/1 and is consumed as `(a <=> b) <cmp> 0`;
2279+ widening its return to poly would force every caller's comparison onto
2280+ the poly path while the result never overflows. Keep it int. */
2281+ int is_spaceship = sc->name && !strcmp(sc->name, "<=>");
2282+ if (sc->ret == TY_INT && !is_spaceship) sc->ret = TY_POLY;
22792283 for (int i = 0; i < sc->nlocals; i++) {
22802284 /* Skip block params: they are typed by the iterated collection's
22812285 element type (an IntArray yields int elements), and the block