Memory management / Borrow validation
Borrow validation runs after HIR generation. It writes analysis facts beside HIR without changing it. Lifetime topology is a separate later analysis.
Borrow validation runs after HIR generation. It reads coherent, validated HIR, enforces source-language access safety and optional transfer safety, and writes analysis facts beside HIR.
Recoverable numeric, cast and fallible-operation paths are already explicit HIR branches, locals and exits before borrow validation.
It doesn't rewrite HIR, choose the final allocation strategy, perform backend ownership lowering, or decide lifetime topology. Lifetime owners, retained edges, escapes and cycles belong to Lifetime regions and escape validation.
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.
Accepted abstract states:
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. Fields and indexes currently resolve conservatively through their base roots. Alias bindings carry root sets. Merged control flow can union root sets. Shared and mutable conflicts are checked against overlapping roots.
Root tracking is analysis metadata, not source-visible reference identity.
Shared and exclusive aliases use non-lexical, control-flow-sensitive activity.
Future-use analysis answers whether a root 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:
Inferred transfer is optional. When safe transfer is not 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 is not a source diagnostic. Path-dependent optional transfer always backs off to borrowing in the accepted design.
The current checker precomputes per-block may/must future-use facts and runs a forward fixed-point transfer over reachable HIR blocks. Current path-dependent rejection behaviour is implementation drift tracked for a later compiler plan.
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 is not valid for ordinary optional transfer.
Internal inconsistent-analysis or impossible metadata uses CompilerError.
Borrow validation consumes and produces:
Lifetime constraints are produced and validated by the separate lifetime-region analysis.
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 does not 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 does not 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 imports or runtime names.
These facts are read-only outputs keyed by HIR identity. They don't become a second semantic IR and must not mutate HIR.
Advisory drop candidates are not lifetime topology and not exact release permission.
Reactivity V1 precision:
Reactive invalidation facts are distinct from builder-owned page/mount lifetime roots.
Borrow validation supplies the next analysis with:
Lifetime-region and escape validation then decides one lifetime owner, retained-edge legality, escapes, cycles and outlives constraints. See Lifetime regions and escape validation.
Borrow validation may be conservative. Stronger field-, projection-, region- or path-level analysis may accept more programs or unlock more optimisation, but it must not change the semantics of already-valid programs.
The accepted design permits conservative analysis. The current analysis shape includes:
These are precision choices, not permanent source-language restrictions.
CompilerDiagnostic values.CompilerError.May future use is always safe to consume.