On this page
Vibe sharing, copying, and ownership
Vibe reconciles Python-shaped object use with Verada value semantics and ownership checks. The rule is not simply “Python references” or “everything is copied.” A supported local binding can become a view; a stored value can be copied; an owning pointer moves. The compiler rejects patterns whose observable sharing behavior it cannot preserve.
Ordinary local values and views
A local introduced from a name/field path can become a view when later code changes that object through the local, calls its methods, or passes it to a potentially mutating call:
view = point
view.y = 4In the reference project this changes point.y. A supported path is a chain of names and fields, such as graph.first, rather than an arbitrary call expression. The view is represented as an object renaming and shares the original storage within its allowed scope. Mode inference can recognize a parameter changed through such a view.
A view cannot be rebound to another object. Nor can its source path, or a prefix such as graph in graph.first, be replaced while the view lives. Python would keep the old referenced object alive; this Vibe representation cannot. B0401 explains the conflicting binding. Use a new name, mutate the original directly, or explicitly request a value copy. These are static, conservative restrictions: the fact that a particular execution would not take a conflicting path does not automatically make the source accepted.
A binding that is only read may be a copy of the value. Vibe has no object identity to tell the two apart: is compares only with None.
Element views
The supported pattern item = items[index] followed by component mutation can become a local element view. The compiler obtains a copy, applies changes locally, then replaces the element when that statement-list scope ends. It also arranges supported return, break, and continue exits to put the value back. This can preserve the visible result of ordinary Python mutation when no intervening observation of the container occurs.
def update_first(points: list[Point]) -> None:
requires(len(points) > 0)
ensures(len(points) == old(len(points)))
p = points[0]
p.x = 7This excerpt is from the reference project's model.vb; it requires the defined Point and imported contract helpers. Its caller observes points[0].x == 7 after return. The postcondition also preserves length for subsequent client proofs.
Restrictions include:
- Do not rebind
pwhile it is a view. - Do not use the containing object/path again while the element view is live, except the specifically permitted length queries. An observation before replacement could see a stale element; the compiler rejects it.
- Do not explicitly
raisefrom the view's remaining scope. The implementation rejects that path because it would leave before the replacement. - The index is fixed when the view is created; expressions or subsequently changed index names may be captured in an internal temporary.
This is not unrestricted borrowing through every container operation or exceptional call. When a scope may propagate an exception or needs to use the container between updates, use copy(items[index]), change the copy, and store it back explicitly before the sensitive operation. The direct assignment items[index].field = value has its own supported copy/change/replace transformation; arbitrary nested receiver expressions do not thereby gain full Python mutation semantics.
Copies and mutation after storing
copy(value) explicitly requests/acknowledges a value copy for the supported value form. It is not a general recursive Python deepcopy, nor does it clone a unique owning pointer. new_list: list[T] = old_list.copy() is the separate limited-container Copy operation.
Storing a value in a field, indexed element, or supported append/insert/add call stores a copy. If the original is then mutated, Python sharing could make the stored object change too, while the copied Verada value would not. The frontend rejects recognized such patterns with B0401. Write container.append(copy(record)) when an independent stored value is intended, and mutate the original only under that explicit interpretation. Alternatively, finish changes before insertion or change the element through a supported view.
The detection follows specific source forms; an unrecognized aliasing route is not a permission to depend on a different Python result. Check cross-module/container identities and operation contracts. In particular, a generic “copy” helper does not bypass limited type assignment rules or ownership flow checks.
Owning heap objects
Owned[Node] annotates a unique owning access value to a supported module-declared class Node. Owned(Node(...)) allocates a designated object. move(pointer) makes transfer intent explicit; owning assignment transfers the value and makes the old owner unusable until restored. deref(pointer) explicitly names the designated value when needed; supported selected-component notation can dereference through an owner automatically.
from dataclasses import dataclass
from verada import Owned
@dataclass
class Node:
value: int
next: Owned[Node] | None = NoneThis declaration fragment is the linked-node pattern used by the ownership corpus. The class must be one the module declares, which gives it its owning access type and deallocator. Owned[Node] is never null, so reaching through it needs no test; assigning None to it fails its null check (B4109). Owned[Node] | None may be null: test p is not None, or require it, before reaching through it.
An operation may move an owning field into a new node or temporary, but it must restore required writable parameters/globals before returning. Reading a moved owner, losing a nonempty owner without release, or leaving a moved part across forbidden loop/return paths produces ownership/leak diagnostics. An owner can be compared with None under the supported null rules; that does not grant access to its moved designated contents.
Deallocation and lifetime
del node frees the object and leaves node null, so the owner it frees has a type that admits None (Owned[Node] | None). It is a checked deallocation, not Python's deletion of a binding; an owned object that is neither freed nor moved elsewhere is a leak (B6005). Move owning child fields out or free them as required so that the operation does not leak designated objects. The linked-stack corpus moves head into a temporary, restores the stack with the node's next, reads the value, and deletes the old node.
An owner is unique, so owners cannot form cycles; objects that refer to each other belong in a proof enclave, whose references may be shared. Local and element views are Vibe's borrows.
Unbounded containers and copyable texts have their supplied reclamation/finalization behavior. Their storage is released according to object lifetime and the shared resource rules, including supported exceptional exits. Text copies can share immutable characters internally without exposing mutable aliasing; that is distinct from general shared mutable objects. Running out of memory is outside proof.
Source evidence: sharing/view lowering, ownership analysis, and move/finalization lowering.