Borrow validation runs after HIR generation. It writes analysis facts beside HIR without changing it. Lifetime topology is a separate later analysis.
Checked proof-budget research records an open proposal for opt-in deeper analysis. It does not change the current safety contract or make ordinary code less checked.
Borrow validation runs after HIR generation. It reads coherent, validated HIR, enforces source-language access safety and optional affine-transfer safety, and publishes solver-independent facts beside HIR.
It doesn't rewrite HIR, choose the final memory strategy, perform backend lowering or decide lifetime topology. Borrow validation supplies facts. Lifetime analysis and memory planning own the later decisions. Lifetime owners, retained edges, escapes and cycles belong to Lifetime regions and escape validation.
Last-use analysis is central to the memory model. Its facts let later stages transfer affine cleanup responsibility, prove candidate cleanup frontiers and select physical representations without treating ordinary aliases as counted obligations. The later stages make those decisions after validating the complete topology.
Recoverable numeric, cast and fallible-operation paths are already explicit HIR branches, locals and exits before borrow validation.
HIR also owns local definition versus update and the incoming value's place/rvalue classification. A definition captures its incoming value, retires the prior dynamic binding state and establishes the new binding relationship. This applies on every loop re-entry. An update preserves ordinary slot/alias semantics, including mutable alias write-through. A produced rvalue can retain shared allocation provenance while creating a separate slot. Solver modes describe possible states and never select the source operation. Operation results and CFG edge destinations preserve the same contract.
AST validates the source markers for existing-place writes, mutable arguments and mutable receivers before HIR. Each existing multi-bind target requires its own marker. An existing mutable argument uses ~place, including in a named call, while a fresh value or copy place uses no marker. A mutable alias declaration uses writer ~= source without marking its source. Borrow validation consumes the resolved operations and access modes rather than reconstructing these forms. Neither a marker nor hidden-local materialisation proves an inferred transfer.
A direct place self-update of one unprojected binding performs the ordinary read and write checks while preserving its role and provenance. It introduces no new alias relationship. Projected writes and updates from a different binding retain their ordinary transition rules.
Every borrow solver must publish the same semantic handoff even when its internal representation and algorithm differ. The stable downstream facts are:
These are semantic facts rather than a required lattice, root table or solver storage format. A different solver can compute them differently without changing source semantics. The handoff never selects REC, constructs a physical memory plan or emits runtime instructions.
src/compiler_frontend/analysis/borrow_checker/mod.rssrc/compiler_frontend/analysis/borrow_checker/engine.rssrc/compiler_frontend/analysis/borrow_checker/state.rssrc/compiler_frontend/analysis/borrow_checker/transfer.rssrc/compiler_frontend/analysis/borrow_checker/transfer/src/compiler_frontend/analysis/borrow_checker/types.rssrc/compiler_frontend/analysis/borrow_checker/diagnostics.rsHirModule.Borrow validation doesn't reparse source syntax, solve generics or traits, or see AST-only generic or trait state.
Native call results have explicit success positions and a separate error channel. Borrow facts are keyed to their HIR owner and those positions. Distinct positions are not proof of independent storage: preliminary provenance may alias parameters or other results. Success values are usable only on their successful CFG edge, and the error value only on its error edge.
Invoke evaluates its operation inputs once before choosing a successor. Borrow transfer retires both success and error destination sets, then defines only the selected edge's locals. Re-entry through a loop cannot reuse a value from the other outcome. Ordered results retain conservative allocation-root unions where a per-slot alias fact isn't available.
Every analysed place is normalised to a semantic place with explicit projections and an overlap relation. The overlap facts state which places may designate the same storage. A solver may report overlap conservatively when it cannot prove disjointness, but downstream consumers don't depend on a particular root-set representation.
Value origins and preliminary provenance identify where a value came from and which place or result may be observed. Alias bindings carry those facts rather than creating independent copies. Root tracking is analysis metadata, not source-visible reference identity.
These are analysis lattice states. They are not Moth source types and do not directly prescribe one backend runtime representation.
Every analysed place resolves to one or more storage roots. A solver may conservatively use a base root for fields or indexes. Alias bindings can carry root sets and merged control flow can union them. Shared and mutable conflicts are checked against overlapping storage when a solver uses this approximation.
The concrete production overlap algorithm and its current difference from feature-gated Boracle are documented in docs/roadmap/plans/production-borrow-checker.md.
Alias activity is path-sensitive and control-flow-sensitive. Shared aliases, and exclusive aliases that have a reachable holder use, use non-lexical activity. Whether an issued but never-used exclusive capability may be elided remains an explicit experimental question; the reference baseline keeps that capability conservative until canonical semantics adopt the stronger rule.
get() results don't become Retained Edge Counting obligations.These points are locked accepted design and are independent of the solver used to derive them.
Cleanup responsibility is affine: it may move or be discharged, but it never duplicates. Borrow validation supplies candidates and proofs. It doesn't make the final physical affine decision.
Borrow validation supplies facts. Lifetime analysis and memory planning own the later decisions.
Fact | Consumer |
|---|---|
a shared or exclusive access may still be used | borrow conflict validation |
no later source use exists on every relevant path | optional affine transfer |
no capable source alias survives | cleanup-frontier proof |
a final-use persistent store commits | affine root to persistent edge reclassification |
a stored value is detached into an owned result | persistent edge to affine root reclassification |
a final loop iteration is statically known | final-iteration responsibility transfer |
no observer or recreating source survives an epoch | inferred-region epoch completion |
edge sets are mutually exclusive across paths or epochs | avoid a false cycle coexistence result |
The table describes data flow, not a transfer of ownership. Borrow validation supplies the facts. Lifetime topology validates retained-edge and cycle legality, and the memory planner decides physical reclassification and cleanup plans.
Future-use analysis answers whether a semantic place or value is required again after the current program point. It is a sufficient basis for optional transfer eligibility, not a source-visible lifetime system.
Semantic classification:
An optional transfer candidate is valid only with the relevant path-sensitive proof. It must also preserve any dependent temporary borrow and must not leave a capable source alias that could recreate a retained edge beyond a candidate cleanup frontier.
Inferred transfer is optional. When safe transfer isn't proven on every relevant path, the operation remains a borrow. Failure to prove an ownership optimisation must not make an otherwise valid source program invalid.
Transfer proof failure isn't a source diagnostic. Path-dependent optional transfer always backs off to borrowing in the accepted design.
Current source syntax has no mandatory-consuming ordinary-value operation. There is no move keyword, consuming parameter spelling or owned signature variant.
A user-facing use-after-consumption diagnostic is reserved for a future accepted mandatory-consuming surface. It isn't valid for ordinary optional transfer.
Internal inconsistent-analysis or impossible metadata uses InfrastructureFailure.
Borrow validation consumes and produces:
Borrow validation doesn't produce final result provenance, retained-parameter constraints, retention cardinality, detached stored-result effects, whole-domain kills, outcome-sensitive retention effects, frontier-enabling effects or outlives summaries. It may provide candidate-frontier capability-death proof as a stable fact, but retained-edge analysis owns the final frontier-enabling decision and those retained-edge effects.
All runtime value parameters, immutable or mutable, may be eligible for inferred responsibility transfer. Parameter access mode remains separate from optional ownership effect. An immutable parameter receiving ownership remains read-only. A mutable parameter receiving ownership may mutate according to the source contract.
Closed external boundary profiles override this general rule. WIT value-only calls are non-consuming. Restricted host-value crossings are non-consuming, and mutable opaque-handle access doesn't transfer Moth storage through the ordinary Moth ownership ABI.
MayConsume, NeverConsumes and AlwaysConsumes are analysis/lowering categories, not source-visible signature categories.
A MayConsume summary means the call path can receive responsibility when the caller proves a safe transfer. It doesn't let a callee unpredictably invalidate a borrowed argument.
AlwaysConsumes may describe a specialised already-proven call path. It must not turn a source function into a mandatory-consuming API.
Call transfer uses resolved metadata, not source dependencies or runtime names.
The read-only side-table handoff carries every fact listed under Stable downstream fact contract, plus the function, block and statement context needed to key those facts to HIR identity.
These facts are read-only outputs keyed by HIR identity. They don't become a second semantic IR and must not mutate HIR. A solver may use additional internal state or tooling statistics, but consumers depend on the semantic facts rather than that storage.
The alpha side table may emit advisory DropIfOwned drop candidates. DropIfOwned names the current Wasm scaffolding instruction and its migration debt only. These candidates aren't stable handoff facts, lifetime topology, exact release permission or final cleanup decisions.
The permanent conceptual conditional operation is discharge_if_owned. The memory planner owns final transfer, discharge, destroy and bulk-reclaim plans.
Wire and Route parameter contracts use ordinary access and lifetime rules. Reading a Wire reads the binding's current value, while forwarding it preserves binding identity. That identity grants no mutation authority, creates no subscription and extends no lifetime. A static compiler expression ID is not the runtime binding instance.
Route captures evaluate when the route forms. Their reads, effects and aliases participate in the ordinary access facts. Lifetime analysis owns any retained-edge and outlives constraints. Borrow validation does not turn a capture into an implicit copy or an independent allocation.
Automatic observation, subscriptions and event delivery are not part of this handoff. Any future observation or event lifecycle needs a separate accepted contract. Builder-owned lifecycle roots remain distinct inputs to lifetime topology.
Borrow validation supplies the next analysis with:
Lifetime-region and escape validation then decides one lifetime owner, retained-edge legality, escapes, cycles, edge coexistence and outlives constraints. It reasons about committed retained-edge states rather than treating every analysis fact as a physical decision. See Lifetime regions and escape validation.
Retained-edge liveness is part of lifetime topology, not a separate runtime ownership system. Borrow validation supplies the alias-liveness substrate it depends on:
Retained-edge analysis owns the semantic facts about direct persistent edges, their cardinality, outcome-specific commit effects, whole-domain kills, detached stored-result provenance and final frontier-enabling effects. The compiler-owned memory planner decides REC selection, concrete obligation transitions, root-to-edge or edge-to-root reclassification, cleanup and destruction. Backend lowering encodes that plan only.
That last guarantee allows Retained Edge Counting to ignore temporary aliases entirely rather than adding a second safety mechanism. Borrow validation never decides which allocation families are counted. Ordinary aliases, parameters, temporary projections and get() results never contribute REC obligations.
Borrow validation may be conservative. Stronger field-, projection-, region- or path-level production solvers may accept more programs or unlock more optimisation, but they must not change the stable handoff or the semantics of already-valid programs.
Boracle is a permanent reference solver and experiment facility. It may improve precision and test alternative algorithms without changing the stable handoff or source semantics. The memory model doesn't depend on Boracle running during normal compilation, and a production solver need not reuse Boracle's storage or algorithm.
Missing optional transfer proof falls back to borrowing. Missing mandatory topology proof remains a topology diagnostic rather than a physical-strategy fallback.
The source, verified implementation inventory, known alpha precision limits, performance evidence and ongoing work are maintained in docs/roadmap/plans/production-borrow-checker.md. The stable contract above governs any replacement algorithm. This reference does not duplicate the changing implementation description.
DiagnosticDraft values.InfrastructureFailure.