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

@@ -1526,7 +1526,7 @@
15261526 if (kmi < 0) continue;
15271527 TyKind kr = (TyKind)c->scopes[kmi].ret;
15281528 buf_printf(b, " case %d: ", k);
1529- if (unified == TY_POLY && (kr == TY_UNKNOWN || kr == TY_VOID || kr == TY_NIL)) {
1529+ if (unified == TY_POLY && method_is_void(&c->scopes[kmi])) {
15301530 /* void-return (raises): call then fall through with nil */
15311531 emit_method_cname(c, &c->scopes[kmi], b);
15321532 buf_puts(b, "(");
@@ -1559,7 +1559,7 @@
15591559 buf_printf(b, " default: ");
15601560 {
15611561 TyKind dr = (TyKind)c->scopes[defmi].ret;
1562- if (unified == TY_POLY && (dr == TY_UNKNOWN || dr == TY_VOID || dr == TY_NIL)) {
1562+ if (unified == TY_POLY && method_is_void(&c->scopes[defmi])) {
15631563 emit_method_cname(c, &c->scopes[defmi], b);
15641564 buf_puts(b, "(");
15651565 emit_args_filled(c, defmi, nt_ref(nt, id, "arguments"), "", b);