Skip to content

Ownership audit misses unregistered temporaries in synthesized default trait methods #1117

Closed

Description

@ehartford

analyze repro.w audit:all --prelude=core reports facts=1910 violations=0 ok for a program whose generated default trait method leaks a temporary string. The runtime defect is being fixed in the FnAbi batch; the audit's missing coverage needs a hard check.

trait Named:
    fn name(self: &Self) -> str
    fn label(self: &Self) -> str: self.name() ++ "!"
type Person { text: str }
impl Named for Person:
    fn name: self.text.clone()
fn main:
    let person = Person { text: "Ada" }
    assert(person.label() == "Ada!")

Expected: temporary owners in synthesized method bodies receive the same ownership validation and completeness checks as ordinary functions (spec ownership/scope cleanup, D6 common lowering).

Observed on base 1710985 and the FnAbi candidate: native debug allocator with WITH_ALLOC_NO_REUSE=1 reports one leaked 16-byte allocation. Address trap in LLDB resolves it through str.clone / Person.name. LLDB on the compiler stops at MirBuilder.register_stmt_temp +36: x0=0 (frame count), w20=2 (local), w21=16 (str); cbz x0 skips registration, called from Codegen.generate_default_trait_method_for_impl via string concatenation lowering. That code builds MIR after the ordinary audit snapshot and omitted the function-level temporary frame.

The runtime fix adds the missing frame and a native debug-allocator regression (da_trait_default_tail.w). Follow-up: expose synthesized default-method MIR to the ordinary audits and detect an owning call result that neither transfers nor receives cleanup. A green ordinary MIR audit currently does not establish this coverage. No workaround in user source.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced in source as a coverage gap. The runtime leak is fixed (the program below is clean under the debug allocator), so no program shows the audit staying silent today; but no audit check in src/Analysis*.w covers ownership of temporaries in synthesized default trait methods.

    $ with run --debug-alloc main.w   # the report's Named/Person program
    ok
    debug-alloc: leak count=0 allocations=2
    

    post-release: audit coverage with no live defect behind it.

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
  3. ehartford commented on Nov 16, 2026

    @ehartford
    ContributorAuthor

    Closed by #3359 and #3361 (2026-11-15/16): an inherited default method's body is no longer built by Codegen.generate_default_trait_method_for_impl after the audit's snapshot. It is lowered in the MIR phase by the same core as any function (MirLower.lower_fn_shape), so it is a MIR body like the others and the ownership validators and audit:all read it. On main 9edaa62, for the program in this report:

    $ with analyze repro.w 'select:stage=mir,name~label'
    fact  mir  body   …  Person.label  locals=5 blocks=2 calls=2 failed=0
    fact  mir  local  …  Person.label  _2 ty=16 mut=1      (the temporaries of `self.name() ++ "!"`)
    fact  mir  call   …  Person.label  …
    $ with analyze repro.w audit:all
    compiler-analysis-audit: facts=24349 violations=0 ok
    

    Before, the analysis had no MIR facts for Person.label at all, which is why the audit could not see its temporaries. Since #3382 Sema checks that body with the function-body check too. The leak itself was fixed earlier (da_trait_default_tail.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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions