Commit 522af46c

522af46cbfedMerged

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

Description

analyze(promote): keep a lowered yield method's raw mrb_int return carrier

A self-recursive implicit-yield method (countdown(n-1) { yield }) is lowered to an &block form whose return rides a raw mrb_int carrier: a string block value is laundered through the slot, an int rides it directly, and every call site casts the carrier back to its own block's concrete type. This is how default/wrap mode emits and runs it.

The promote-mode blanket ret == TY_INT -> TY_POLY widen converted that carrier to poly, after which the lowered yield emitted sp_box_str(...) over a raw mrb_int and failed to compile (and mismatched the per-call casts). Exclude lowered-yield scopes from the widen so promote emits the same working raw-carrier code as default. Method params still widen to poly, so integer-overflow safety inside the body is unaffected.

Resolves the last promote compile-failure (recursive_implicit_yield_value). Default test 992/0/0 and optcarrot checksum 59662 unchanged.

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

Details

Commit
522af46cbfed
Parent
07d3dc697cb8

src/analyze.cmodifiedView file

@@ -2279,7 +2279,13 @@
22792279 widening its return to poly would force every caller's comparison onto
22802280 the poly path while the result never overflows. Keep it int. */
22812281 int is_spaceship = sc->name && !strcmp(sc->name, "<=>");
2282- if (sc->ret == TY_INT && !is_spaceship) sc->ret = TY_POLY;
2282+ /* A lowered self-recursive yield method returns its block's value through
2283+ a raw mrb_int carrier (a string is laundered through the slot, an int
2284+ rides it directly), and every call site casts that carrier back to its
2285+ own block's concrete type. Widening the return to poly would emit a
2286+ `sp_box_str(mrb_int)` over that raw carrier and mismatch the per-call
2287+ casts; keep it as the carrier, exactly as default/wrap mode does. */
2288+ if (sc->ret == TY_INT && !is_spaceship && !sc->is_lowered_yield) sc->ret = TY_POLY;
22832289 for (int i = 0; i < sc->nlocals; i++) {
22842290 /* Skip block params: they are typed by the iterated collection's
22852291 element type (an IntArray yields int elements), and the block