Commit 226d77e1
226d77e17962Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
codegen: use method_is_void for poly-dispatch void arms (single source of truth)
Follow-up to #1469. That fix closed a box() hole by adding the
missing tokens to four hand-maintained void-arm guards in the two poly
dispatchers, each spelled ret == TY_VOID || TY_NIL || TY_UNKNOWN. But that
set is exactly what method_is_void() already computes (!is_scalar_ret(ret),
since is_scalar_ret covers every value-bearing TyKind), and it is the same
predicate codegen.c uses to decide whether to emit the function void at all.
Replace the four inline triples with method_is_void(scope) so the dispatch's
"don't box the result" decision and the function's actual void emission share
one source of truth. This makes the mirror-incompleteness that caused #1469
structurally impossible to reintroduce, and stays correct if a new no-value
TyKind is ever added.
Pure refactor: generated C is byte-for-byte identical across optcarrot and all
1007 benchmark/test inputs (method_is_void's only extra case over the triple,
initialize, never reaches these named-override dispatch arms today).
Gates: 950 tests pass, optcarrot checksum 59662.
Refs #1469
Co-Authored-By: Claude Opus 4.8 [email protected]
Details
- Commit
- 226d77e17962
- Parent
- e28c85eabd52
src/codegen_call.cmodifiedView file
if (kmi < 0) continue; TyKind kr = (TyKind)c->scopes[kmi].ret; buf_printf(b, " case %d: ", k); if (unified == TY_POLY && (kr == TY_UNKNOWN || kr == TY_VOID || kr == TY_NIL)) { if (unified == TY_POLY && method_is_void(&c->scopes[kmi])) { /* void-return (raises): call then fall through with nil */ emit_method_cname(c, &c->scopes[kmi], b); buf_puts(b, "("); buf_printf(b, " default: "); { TyKind dr = (TyKind)c->scopes[defmi].ret; if (unified == TY_POLY && (dr == TY_UNKNOWN || dr == TY_VOID || dr == TY_NIL)) { if (unified == TY_POLY && method_is_void(&c->scopes[defmi])) { emit_method_cname(c, &c->scopes[defmi], b); buf_puts(b, "("); emit_args_filled(c, defmi, nt_ref(nt, id, "arguments"), "", b);src/codegen_fold.cmodifiedView file
Loading diff…