Commit 5914c9e1

5914c9e1bef6Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · +1 added · ~1 modified

Description

codegen: box the throw value for a poly-typed catch

A catch whose result type is poly (e.g. its block's value is poly, as in catch(:t) { Fiber.yield }) emitted the throw-caught arm as _t = sp_catch_val[top], assigning an mrb_int to an sp_RbVal temp -- a hard C compile error. The ptr/non-ptr split didn't cover TY_POLY. This surfaced as the "catch/throw inside a fiber body" failure noted on #1474.

Add a TY_POLY arm that boxes the caught int (sp_box_int). The common shape is a poly block return with no matching throw, where the arm is dead; a throw with an int value to a poly catch now boxes correctly. (Carrying a non-int thrown value to a poly catch remains a limitation of the int-only throw value channel.)

Verified: catch in a fiber body and a poly catch with an int throw both match CRuby; existing catch/throw tests unchanged.

Gates: 952 tests pass, optcarrot checksum 59662.

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

Details

Commit
5914c9e1bef6
Parent
5a3daaa3d823

src/codegen_call.cmodifiedView file

@@ -3427,6 +3427,14 @@
34273427 buf_printf(g_pre, "_t%d = (", t); emit_ctype(c, bt, g_pre);
34283428 buf_printf(g_pre, ")(uintptr_t)sp_catch_val[sp_catch_top];\n");
34293429 }
3430+ else if (bt == TY_POLY) {
3431+ /* A poly-typed catch (e.g. its block's value is poly): the mrb_int
3432+ value channel can't carry a tagged value, so box the thrown int.
3433+ Common shape is a poly block return with no matching throw, where
3434+ this arm is dead; a thrown non-int to a poly catch is a separate
3435+ limitation of the int-only throw channel. */
3436+ buf_printf(g_pre, "_t%d = sp_box_int(sp_catch_val[sp_catch_top]);\n", t);
3437+ }
34303438 else {
34313439 buf_printf(g_pre, "_t%d = sp_catch_val[sp_catch_top];\n", t);
34323440 }