Repository navigation
Research: Wa wire IR / ARC lowering for explicit ownership events in OwnIR #441
Description
Context
Wa is a Go-like language primarily targeting WebAssembly. Its compiler currently exposes two potentially relevant layers:
internal/ssa: a Go-derived, source-oriented SSA representation.internal/wire: a newer, higher-level IR with explicit allocations, locations, references,Retained()expression metadata andReleaseoperations.
The new IR has ARC-related lowering in internal/wire/function.go (EndBody, arc_block, arc_expr) and internal/backends/wire2wat/wire2wat.go (calls to runtime.Block.Retain / runtime.Block.Release). See also ins_alloc_imv_extract_discard_release.go and ins_set_assign_store.go.
Maturity caveat: as inspected on 2026-10-24, the normal wa build path in appbuild.go still goes through compiler_wat and SSA; the newer wire2wat backend is not integrated there. The new code also contains TODO/panic branches. Do not treat this as a production-proven ownership verifier or soundness reference.
Research question
Can Own.NET benefit from retaining explicit ownership-relevant semantic events in OwnIR rather than reconstructing them later from generic lower-level operations?
Compare Wa's representation and transformations with our existing Roslyn → OwnIR lowering and ownership/borrow diagnostics, especially:
Alloc/ heap-vs-register placement;Get,Load,Set,Assign,Store,Discard,Release.Retained()semantics and what is explicitly preserved or lost about value ownership vs. reference-counting conventions.- How
EndBody/arc_block/arc_exprhandle copies, overwrites, branches, loops, calls, return values, and cleanup. - Whether any minimal event vocabulary (e.g. acquire, alias, transfer, invalidate, release, escape) would actually improve a frequent/high-severity Own.NET diagnostic, including explanation and evidence quality.
- Cases where mapping Wa's ARC semantics to C# would be incorrect (GC-managed objects,
IDisposable, aliasing,ref/out, borrowing, async, exceptional exits). ARC retain/release is not equivalent to Rust-style borrow checking or .NET disposal obligations.
Proposed bounded investigation
- Pin the exact upstream Wa commit being studied; trace the real path from source AST/type information to
wire, and separately confirm which paths are currently exercised bywa build. - Produce a compact mapping table: Wa IR operation → OwnIR construct/event → semantics preserved/missing → potential diagnostic affected.
- Walk through at least 3 concrete snippets (overwrite + alias, branching/early return, exceptional/cleanup case where representable). Record both the Wa lowering behavior and the closest relevant C# case; mark unsupported Wa constructs as unsupported, not as passing.
- Identify one existing Own.NET diagnostic with a documented precision or soundness gap that explicit ownership events might address. Compare with a simpler improvement to current Roslyn lowering.
- State a falsifiable recommendation: ADOPT SMALL IDEA, DEFER, or REJECT, backed by concrete code and expected costs.
- If recommending adoption, propose a separate, tiny prototype issue with testable invariants and regression fixtures. No large IR rewrite in this research issue.
Non-goals / stop rules
- No language/compiler port, WebAssembly backend, or reuse of Wa's runtime.
- No assumption that inserting
Retain/Releaseproves memory safety, prevents use-after-free, or establishes soundness. - No broad redesign based on architectural resemblance alone.
- Stop with DEFER/REJECT if there is no plausible gain over current OwnIR for an actual high-value diagnostic.
Upstream references
- https://github.com/wa-lang/wa
- https://github.com/wa-lang/wa/tree/master/internal/wire
- https://github.com/wa-lang/wa/blob/master/internal/wire/function.go
- https://github.com/wa-lang/wa/blob/master/internal/backends/wire2wat/wire2wat.go
- https://github.com/wa-lang/wa/blob/master/internal/app/appbuild/appbuild.go
Activity