Commit a56df0b5
a56df0b5f9c0Merged
Sam Ruby <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Poly dispatch: void-arm guards must cover the full no-value set {VOID,NIL,UNKNOWN}
Both poly-receiver dispatchers choose between the void arm (call the override as a statement, assign a default to the result temp) and the value arm (box the call's return) from the arm's stored return TyKind. Each tested only a SUBSET of the "no usable value" types, and the two were mirror-incomplete:
- codegen_fold.c (instance self-dispatch): {VOID, NIL} -- missing UNKNOWN
- codegen_call.c (class-method dispatch): {UNKNOWN, VOID} -- missing NIL
A method with any of those rets is emitted void (method_is_void is
!is_scalar_ret, true for all of VOID/NIL/UNKNOWN). When such a method's ret is
the one type the local guard omits, the dispatch takes the value arm and emits
_t = <void call> / sp_box_int(<void call>), which gcc rejects:
"invalid use of void expression".
Surfaced by real-blog: has_many :comments, dependent: :destroy generates
def before_destroy; comments.each { |c| c.destroy }; end. The inferred return
of that body is layout-sensitive -- TY_NIL on some builds, TY_UNKNOWN on others
(valgrind + UBSan both clean, so it's a well-defined-but-allocation-order-
dependent inference result, not UB). The function is emitted void either way;
on builds where ret landed TY_UNKNOWN, codegen_fold's case arm missed it and
emitted sp_box_int(), so the AOT compile failed only on those
machines while passing on others at the same commit.
Make all four arms (case + default, both dispatchers) test the full set {VOID, NIL, UNKNOWN}, so the dispatch is robust to that inference wobble regardless of which of the three a void method's ret lands on.
make test: 950 pass / 0 fail / 0 error.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- a56df0b5f9c0
- Parent
- 77a27c0c0213
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)) { if (unified == TY_POLY && (kr == TY_UNKNOWN || kr == TY_VOID || kr == TY_NIL)) { /* 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)) { if (unified == TY_POLY && (dr == TY_UNKNOWN || dr == TY_VOID || dr == TY_NIL)) { 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…