Commit 190998ce

190998ceb5a8Merged

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

Description

analyze,codegen: support poly proc captures and re-derive proc_ret after the promote widen

Under --int-overflow=promote an int local captured by an escaping proc widens to poly, and a proc whose body returns such a value now returns poly. Two coupled gaps blocked this:

  1. Capture cell: the closure machinery had no poly cell, only int/float/ptr, so a poly capture was rejected ("unsupported closure capturing a non-integer variable"). Add a real sp_RbVal cell with an RbVal-marking scan (sp_cell_scan_rbval), an sp_RbVal* cap-struct field, and allow TY_POLY in the proc-capture check. The existing read/write paths already handle a non-int cell. Also publish a poly proc arg into the mrb_int slot via sp_poly_to_i, so a proc whose param stayed int (block params are not widened) reads the right value, not the 0 placeholder.

  2. proc_ret consistency: the widen can change a proc body's return type, but the caller-side proc_ret and a factory method's ret_proc_ret were computed pre-widen. A proc.call then read the wrong return channel (raw mrb_int slot vs the poly side-channel) and got 0. Re-derive proc_ret and ret_proc_ret as a focused post-widen fixpoint (mirroring infer_return_types / infer_write_types) -- it touches only proc-return metadata, never the widened slot types -- then refresh the node-type cache so proc.call nodes pick up the new proc_ret (codegen reads comp_ntype, not lv->proc_ret).

promote test 927->932 (proc, proc_closure, case_local_in_lambda, enum_for_each, lowered_block_given), zero regressions; default 992/0/0 and optcarrot 59662 unchanged (all gated by g_promote_mode).

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

Details

Commit
190998ceb5a8
Parent
8652b49aa4a7

lib/sp_gc.hmodifiedView file

@@ -92,6 +92,7 @@
9292 referent so it survives as long as the capturing proc does. */
9393 static inline void sp_cell_scan_str(void *p) { sp_mark_string(*(const char **)p); }
9494 static inline void sp_cell_scan_ptr(void *p) { sp_gc_mark(*(void **)p); }
95+static inline void sp_cell_scan_rbval(void *p) { sp_mark_rbval(*(sp_RbVal *)p); }
9596 /* A low-bit-tagged root entry is an sp_RbVal* (see SP_GC_ROOT_RBVAL);
9697 an untagged entry is a plain void** to a direct GC pointer. */
9798 static inline void sp_gc_mark_root_entry(void **e) {