Commit 3d4efd9a
3d4efd9a07a7Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · +2 added · ~2 modified
Description
Merge PR #1517: carry a proc's explicit return value out through #call
A lambda/proc whose body ends in an explicit return <expr> lost its value
(lambda { return 7 }.call yielded 0). The proc was typed by the tail
statement, but a ReturnNode tail is not value-typed by infer_type, so the
proc was typed poly while its body returned through the mrb_int channel and
the call site read the never-written poly slot.
proc_node_ret now types the proc by the ReturnNode's value (return_node_type), and emit_proc_literal derives the body-return ABI from the effective tail value node, routing the pointer-launder and poly/float return-slot paths through it. Adds test/lambda_explicit_return.rb.
Combined-state gates: test 1002/0/0, bench 57/57, optcarrot checksum 59662.
Closes #1517
Co-authored-by: Ryan Seys [email protected] Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 3d4efd9a07a7
- Parent
- 1d70498652a8
- Merge parent
- f1e3773cedf1
src/analyze_util.cmodifiedView file
if (body < 0) return TY_NIL; int bn = 0; const int *bb = nt_arr(nt, body, "body", &bn); return bn > 0 ? infer_type(c, bb[bn - 1]) : TY_NIL; if (bn <= 0) return TY_NIL; /* An explicit `return <expr>` tail is a ReturnNode, which infer_type does not value-type -- type the proc by the returned expression so the call site and the body's return channel agree (otherwise the value is silently lost). */ int tail = bb[bn - 1]; const char *tty = nt_type(nt, tail); if (tty && !strcmp(tty, "ReturnNode")) return return_node_type(c, tail); return infer_type(c, tail);}TyKind proc_ret_of(Compiler *c, int node) { const NodeTable *nt = c->nt;src/codegen.cmodifiedView file
Loading diff…
test/lambda_explicit_return.rbaddedView file
Loading diff…
test/lambda_explicit_return.rb.expectedaddedView file
Loading diff…