Skip to content

Omitted impl method becomes a null vtable slot: dyn call traps (rc=133) with zero diagnostic #1002

Closed

Description

@eas4ai

Summary

When an impl block omits a trait method and the method is invoked through &dyn, the compiler emits a vtable with a NULL function pointer in that slot. The program builds cleanly (check ok, --validate-all ok) and dies at runtime with Trace/breakpoint trap (rc=133), no message, no location.

Repro (seed stage1 at 450733e; probe .audit/probes/codegentraits/ct_missing_dyn.w)

trait T:
    fn m(self: &Self) -> i32
    fn n(self: &Self) -> i32
type A { v: i32 }
impl T for A:
    fn m(self: &Self) -> i32: 1   // n omitted — accepted (cf. #988)
fn call_n(x: &dyn T) -> i32: x.n()
fn main:
    let a = A { v: 0 }
    assert(call_n(&a) == 2)

Re-run by primary: check ok rc=0, check --validate-all ok rc=0, built binary traps rc=133 with no output. Static call of the omitted method errors loudly (unknown method, rc=1 — negative control passes); only the dyn path traps.

Root-cause chain (verified by reading + execution)

  1. src/CodegenTraits.w:1006-1035: when neither the mangled name nor the slot lookup finds the impl function, the else pushes wl_const_null into the vtable entries — silently.
  2. The two sibling vtable builders diagnose loudly instead: ensure_monomorphized_trait_vtable (:1110-1113, eprint + had_error=1) and ensure_generic_inst_trait_vtable (:1178-1181, same). Same file, same situation, opposite discipline — internal inconsistency.
  3. Nothing downstream checks slot nullness before emitting the indirect call, so the null pointer reaches the running program and traps in LLVM-generated code with no With-level frame.

Severity

High: silent wrong-code generation violating No Silent Fallbacks — a missing method the frontend accepts (#988, fail-late by design) must error at vtable construction, never materialize as a null call target. Deterministic crash with zero diagnostic output.

Suggested fix (owner's call)

Mirror the siblings: eprint + had_error=1 on the null-slot path (or reject earlier). Optionally ALSO fix #988's declaration-site gap so the error surfaces sooner; either layer going loud fixes the trap.

Audit provenance

Read-only end-to-end audit, CodegenTraits leg (child complete examination, independently verified by primary: branch inspection + check/validate/build/run re-runs). Related: #988 (Sema accepts the omission — distinct layer, same program).

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced

    Verdict. Established on current main. An impl that omits a trait method compiles (per #988), the vtable builder pushes a null pointer into the omitted slot without any diagnostic, and calling that method through &dyn T dies with SIGTRAP (rc 133) and no output. with check, --validate-all, with analyze audit:all, and the dedicated audit:trait-tables all report ok on the program. The static call a.n() is rejected (unknown method 'n' for type 'A'), so only the dyn path is silent, as the report says. The two sibling vtable builders in the same file do diagnose the same condition loudly, so this is an internal inconsistency, not a design choice.

    Tested revision and compiler

    item value
    source main @ 5809ac1 (2026-09-14); the null-slot branch is unchanged since 450733e (#1129 and the D39 commits touched other parts of CodegenTraits.w)
    compiler with build of 5809ac1 in a detached worktree, self-reports with v0.15.2.1
    platform macOS Darwin 25.6.0, arm64

    Repro

    trait T:
        fn m(self: &Self) -> i32
        fn n(self: &Self) -> i32
    type A { v: i32 }
    impl T for A:
        fn m(self: &Self) -> i32: 1
    fn call_n(x: &dyn T) -> i32: x.n()
    fn main:
        let a = A { v: 0 }
        print(f"{call_n(&a)}")
    
    step result
    with check ok
    with check --validate-all validate-all: ok
    with analyze audit:all / audit:trait-tables violations=0 ok / trait-table-audit: ... violations=0 ok
    with build then run no output, rc 133
    lldb stop reason = EXC_BREAKPOINT, frame #0: dynbin\main + 16` (the call through the constant-null slot was inlined and folded to a trap)
    control: static a.n() error: unknown method 'n' for type 'A', rc 1

    Source

    • src/CodegenTraits.w:976-978: in the trait vtable builder, when no impl function is found for a trait method the else branch does entries.push(wl_const_null(wl_ptr_type(self.context))) with no diagnostic and no had_error.
    • src/CodegenTraits.w:1054-1055 (ensure_monomorphized_trait_vtable) and :1122-1123 (ensure_generic_inst_trait_vtable): the same situation emits error: missing monomorphized trait method '<Type>.<method>' for trait '<Trait>' and sets had_error = 1.
    • Nothing between the vtable global and mir_emit_dyn_trait_call checks for a null slot, so LLVM sees a call through a known-null constant and legally lowers it to unreachable, which on arm64 is a brk (hence SIGTRAP rather than SIGSEGV).

    Tools that stayed silent

    audit:trait-tables is documented in AGENTS.md as checking "codegen trait-table/vtable agreement with canonical AST method records"; a null entry for a method the trait declares is exactly a disagreement it should report. Per AGENTS.md that audit gap is part of this bug and should be fixed in the same batch.

    Spec

    §11.3 (spec around line 5100) describes the vtable as carrying every dispatchable trait method; nothing sanctions an empty slot. AGENTS.md §No Silent Fallbacks: emitting a placeholder (here a null function pointer) where translation failed is the forbidden shape, and the sibling builders show the intended discipline.

    Related PRs

    None merged or open touch the null-slot branch. #988 (this queue) is the Sema-side gap that lets the omission reach codegen; either layer going loud fixes the trap, both should.

    Would I champion a fix? Yes, one-line parity plus the audit.

    Acceptance criteria:

    1. The else at :978 mirrors its siblings: with_eprint("error: missing trait method '<Type>.<method>' for trait '<Trait>'") and had_error = 1; the build fails non-zero with that message for the repro.
    2. audit:trait-tables reports a violation for a vtable slot with no impl function.
    3. A test/compile_errors fixture for the repro (once Impl method arity is not checked against the trait (types are, D140): an extra parameter fails late #988's declaration-site check lands, the same program should fail there instead, and the codegen check remains as the backstop).

    Untested

    Generic-instance and monomorphized vtable paths were read, not run (they already diagnose). Linux and Windows not executed.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced.

    $ cat main.w
    trait T:
        fn m(self: &Self) -> i32
        fn n(self: &Self) -> i32
    type A { v: i32 }
    impl T for A:
        fn m(self: &Self) -> i32: 1
    fn call_n(x: &dyn T) -> i32: x.n()
    fn main:
        let a = A { v: 0 }
        print(call_n(&a))
    $ with check main.w
    ok
    $ with run main.w
    (no output)
    rc=133
    

    pre-release: a crash with no message from an ordinary omission; the fix is a missing-method error at the impl.

  3. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Fixed on main by acf2911 (#2684), merged through stack 5 whose seed-driven battery was green on its top (gate, uat and survey all green). Regression test: test/compile_errors/err_1002_impl_missing_trait_method.w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions