rfc: investigate explicit invariant updates and stable observations

This commit is contained in:
dev committed 2026-10-09 09:29:00 +03:00
1 parent d041c07ad2
commit 9a3e135f43
4 files changed
+85

No files matched your search

@@ -110,6 +110,8 @@ Bindings identify function parameters, the prior snapshot, or the post-only plac
Post installation reads no resource and takes no loan. At each `ret`, the verifier checks the bindings as a virtual ordinary predicate call in the final body state, before return transfer. A still-available owner being returned may be observed without consuming it. A consumed owner remains unavailable (the current owner case gives E3001); a moved binding remains unavailable under E2001. An owner moved through another call can be observed through `result`, without reviving its old parameter binding. An input lent to a returned exclusive view cannot also be read through its parent; ordinary alias checks reject that observation. Temporary views end after each predicate call and before result transfer. Existing leak/return rules still apply; diagnostic ordering between new predicate access errors and return/leak errors needs an explicit stage rule and regression cases. Source typing must specify explicit read-only places and clause-root elaboration; no implicit dereference of owned parameters is adopted here.
Explicit `ref` bindings of Copy SSA parameters/results need the instruction-internal temporary-place mechanism described in the [invariant research](../design/contract-invariant-boundaries.md): ordinary `borrow.ref` cannot address such a scalar or struct (both current probes reject E1001). Materialize a complete value only for the evaluation, end every observation view before resuming, and prohibit borrow escape through bool/Data results. Existing owner/borrow-root shapes and alias restrictions remain distinct; materializing a Copy observation cannot bypass them or make ordinary body/source SSA values addressable. Account these bounded activation slots with the snapshot/frame budget before implementation.
The snapshot cannot appear in body expressions, copies, branch arguments or a return; its only use is a post binding, and a snapshot used by no post is rejected. Multiple source `old` expressions lower to fields of one Data record. Its accounted size is bounded by `max_value_size`; the proposed combined snapshot plus `local.alloc` budget is `max_local_frame`, with checked arithmetic. These limits apply only to new contracted functions and need exact diagnostics. Prefix size and helper argument counts use existing instruction/call limits. Counted tests must cover member-edge visits, function removals/call-edge visits and the eventual diagnostic-witness length, including shared type diamonds and recursive helper components.
All three operations have empty declared effects, transfer no caller ownership, and perform no synchronization or capability use. `pre` and `old` read permitted observations; `old` additionally writes its bounded activation snapshot. `post` installation stores clause metadata, and its return-time evaluation reads only currently legal observations. Pure helper frame writes are local. No implicit heap allocation or opaque library hook is introduced. The prefix and implicit return obligations are semantic coverage constructs, not abbreviations for optional asserts. Source/package/generic lowering must supply the same verifiable operations; AIR verification cannot trust frontend coverage claims.
@@ -147,8 +149,12 @@ Eager enforcement requires root/projection tracking for every complete construct
Both models must cover AIR `local.zero`, nested aggregates, buffers/graphs, `value.swap`, outcome payloads and ownership transfer; a narrower source constructor policy is insufficient. Source/AIR zeroability wording is a separate question (Q-056). Invariant metadata and its AIR representation remain unresolved: the function prefix does not by itself provide a type/module declaration mechanism.
The [invariant-boundary research](../design/contract-invariant-boundaries.md) develops a third, leading candidate: a new checked representation type with explicit make/shared-view/extraction/update operations. Ordinary representation R has no invariant claim during a scoped callback update; validation precedes publication of the checked value/result. An extraction-only version is insufficient for borrowed linear state, so explicit in-place update is required. Stable observations, not merely observational purity, are a soundness premise. Five new current-language probes confirm projected scalar mutation, a library-wrapper bypass, independent-root drift and E0001 versus E0004 metadata spellings. The research preserves the unresolved full type/module gate and supplies no implementation authorization.
Module invariants need a definition of their roots and observation boundaries. Source 0.1 has no module-state declarations or visibility modifiers; neither nonexistent globals nor arbitrary private-state semantics may be inferred from spec 13's example. Loop invariants, if included by P6-6, need an explicit initiation/preservation/exit rule. Implementing function contracts alone leaves these requirements and P6-6 open.
The candidate distinguishes a persistent checked state root owning correlated values from a named boundary relation over separately owned roots and an explicit function set. Their audit scopes and coverage claims must differ. Source module declarations, root mappings and any hidden-state abstraction still require a decision; ordinary pre/post reuse alone must not silently redefine module invariants.
Remaining decisions: shared observation coverage (Q-057) and invariant-evaluation interactions; source clause elaboration and complete AIR binding grammar; purity/snapshot diagnostics and ordering; proof and assumption modes; invariant boundaries and metadata representation; traps/report schema and tested pending-return dispatch. The RFC stays Draft until these have concrete rules and counterexamples.
## Compatibility and integration