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
widening its return to poly would force every caller's comparison onto the poly path while the result never overflows. Keep it int. */ int is_spaceship = sc->name && !strcmp(sc->name, "<=>"); if (sc->ret == TY_INT && !is_spaceship) sc->ret = TY_POLY; /* A lowered self-recursive yield method returns its block's value through a raw mrb_int carrier (a string is laundered through the slot, an int rides it directly), and every call site casts that carrier back to its own block's concrete type. Widening the return to poly would emit a `sp_box_str(mrb_int)` over that raw carrier and mismatch the per-call casts; keep it as the carrier, exactly as default/wrap mode does. */ if (sc->ret == TY_INT && !is_spaceship && !sc->is_lowered_yield) sc->ret = TY_POLY; 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