DEVELOPMENT EDITION · 769442725406
Language Reference
On this page

Contracts, flow specifications, and proof declarations

Contracts state properties at well-defined program points. Their expressions must be well-typed and safe under the applicable assumptions. A contract is neither documentation that the compiler ignores nor an unconditional proof of the requirements an application actually intended.

Preconditions and postconditions

A precondition is required before a call. The operation's body may assume it on entry. A postcondition must hold on normal return and is available to callers after the call. Ordinary parameter/result subtype conditions and applicable type invariants add obligations even when explicit Pre and Post are absent.

Purpose Vada Varc Vibe
Require an input bound Pre => X < Natural'Last requires x < Natural::Last requires(x < Natural.last)
Describe a result Post => F'Result = X + 1 ensures result == x + 1 ensures(result == x + 1)
Compare entry state Count'Old old(count) old(count)
Assert at a point pragma Assert (P); assert p; assert p

These are fragments; the complete syntax references define placement and binding rules. The bounded increment is a maintained three-syntax example. Strengthening its precondition changes the caller's obligation and can change the API's requirements; proof success alone does not justify excluding required inputs.

Old values and results

Old evaluates its prefix on entry to the operation. It is allowed in a postcondition or the accepted exceptional post-state context. Its prefix cannot depend on a result, post-state quantified variable, or nested old value that exists only at return. In a conditionally evaluated part of a postcondition, an arbitrary old expression must meet the entry-known guard rules; otherwise use a permitted object snapshot or restructure the specification. B2015 identifies conditional-old misuse.

Copying an owning value to form an old snapshot can create forbidden aliases. A nonfresh owning prefix is rejected with B6007; fresh function results and suitable mathematical models provide supported alternatives. A model of a container is often a better snapshot than copying its executable ownership structure.

Result denotes the current function's result in the permitted postcondition context. It is not a mutable ordinary local or a result of any arbitrarily named operation. Array results can be indexed through their supported result form. Procedures express ordinary outputs through parameters, or through the Vibe result mapping of an extracted procedure.

Contract cases

Contract_Cases partitions the entry situations into guarded outcomes. A consequence is required if its guard held on entry. Without others, exactly one case must apply; with others, the listed explicit guards must remain disjoint and the remaining situation uses that consequence. Guards are entry-state predicates; consequences are postconditions.

Case completeness/disjointness is itself proved, with B5106 for a failed obligation. Overlapping cases do not mean that all matching consequences are silently conjoined. Use guards that express a true partition of the API domain. Vibe's ordinary requires, ensures, and raises mappings do not establish a direct spelling for every case aspect.

Refined_Post on a body states a further postcondition in terms of what the body sees, such as hidden state; it is proved together with the declaration's Post. Callers in other units use only the visible Post.

Global effects

Global states which nonlocal variable/state values an operation may use:

Mode Meaning
Input Read the incoming state
Output Establish state without requiring its incoming value
In_Out Read and update state
Proof_In Use state for proof-only reasoning
null No listed global state is used

The body is checked against its declared effects. If no contract is given for an ordinary body, supported effects are inferred through calls. Imported operations must state their effects; their bodies are not available to justify an inference. Functions cannot write state. Calling an operation that writes a global still counts as a write by its caller.

--show-flow prints inferred contracts. That output helps construct or review an interface; it does not add a behavioral relationship between input and result. A Global => null contract on foreign code is a trusted assertion, not a mechanism that makes effects disappear.

Dependencies and abstract state

Depends states permitted data dependencies of outputs on inputs and prior state. For example, an accumulator result can depend on its incoming value and a new input. The + self-dependency shorthand includes the old output where the accepted syntax allows it. The flow checker reports missing or unused dependencies and effects.

An abstract state gives a public name to hidden package state. Refined_State relates it to implementation constituents; Part_Of associates a constituent with state. Operations can expose public abstract effects while their bodies use the corresponding refinement. Refined_Global and Refined_Depends describe supported body-level effect refinements. They do not give a body permission to access state absent from the abstract contract.

Initializes lists package state established during elaboration and is checked against actual initialization. Initial_Condition on a package states what holds when its elaboration ends; it is proved there (B5110 when it might not hold), and the main program may assume it. External abstract state is linked to the volatile/asynchronous rules in the device chapter.

Assertions and assumptions

An assertion requires its condition where execution reaches it. Proof must establish the condition using the current path facts; an assertion can then make a useful local fact explicit. Its own expression must be safe.

An assumption introduces a trusted hypothesis without proving it. Verada reports explicit assumptions with B8002. Subsequent proof depends on their truth. A contradictory assumption can make a proof vacuous; it is not evidence that real inputs are safe. Prefer an assertion when the intended fact can be established, or an accurate imported contract when the boundary is genuinely external.

SPARK_Mode => Off does not exempt a region from Verada analysis; its aspect and declaration forms are reported with B8004, while a statement pragma is ignored. --no-assume makes every assumption an error (B8002): a pragma Assume, an import from C, a trusted enclave body. Use it for release builds. Neither recognized Ada suppression controls nor a spelling borrowed from another verifier changes the documented proof policy.

Loop invariants and snapshots

A loop invariant must hold when its statement is first reached and be preserved on the next visit. The formula describes that placement, not necessarily the beginning of every iteration. At a loop cut, modified values are represented by what the invariant and iteration conditions establish. Explicitly state relationships needed after the loop.

Loop_Entry snapshots a value at entry to a named or innermost enclosing loop in its accepted context. It differs from subprogram Old, whose snapshot is taken at operation entry. A loop snapshot does not grant permission to copy arbitrary owning values or to refer to an out-of-scope loop. B5103/B5104 distinguish initialization and preservation failures; a replayed countermodel can reveal a weak invariant rather than a real failing input.

Termination variants

Loop variants and Subprogram_Variant give supported increasing/decreasing progress measures, including lexicographic lists. Recursive calls must progress relative to the entry variant in a context required to terminate. A variant's arithmetic, bounds, and progress are proof obligations; merely writing a formula is insufficient.

Functions, procedures with effective Always_Terminates, and implicit finalizers/adjusters must satisfy the applicable termination policy. A procedure called from such a context must itself provably terminate; Verada proves that where the procedure is declared. B5107/B5109 concern variant progress; B5108/B5112 identify missing termination evidence for functions/procedures.

Predicates and type conditions

Static/dynamic predicate forms constrain supported subtypes. They are checked at the corresponding use boundaries, not treated as arbitrary comments on an alias. A predicate refers to the current instance of the type/subtype through its permitted name. Predicate expressions and calls must obey the ordinary contract/purity rules.

Type_Invariant for a private abstraction goes on its full view in the private part. Placing it on the partial public view is B2016. Supported public-operation boundaries assume valid inputs and require valid outputs; internal intermediate states can temporarily violate the invariant. An internal call to an operation that assumes the invariant must reestablish it at that call. Functions used to define the invariant cannot circularly assume their own conclusion.

Default_Initial_Condition states what default initialization establishes for the supported private type. A default-initialized object must meet it. This is distinct from arbitrary initialized construction and from a package's Initial_Condition.

Ghost code and mathematical models

Ghost entities exist for specification and proof. Executable non-ghost state cannot depend on a ghost value, and ghost statements cannot alter ordinary program results. These restrictions preserve meaning when ghost code is erased. A ghost package can supply model sequences, maps, or lemma procedures without making them ordinary runtime containers.

Strict and proof-disabled compilation normally erase ghost code. Advisory compilation retains it for applicable runtime checks, but some contracts still cannot be executed. A runtime check of a finite scalar assertion does not establish that every ghost or quantified specification can be enforced dynamically. B8007 reports contracts that are not checked in the relevant mode.

Assertion levels group ghost entities and assertions so that a GNAT build can enable or disable them together. A configuration pragma before a unit declares one, pragma Assertion_Level (Gold, Depends => Silver);, and Runtime and Static always exist. Ghost => Gold puts a ghost entity at a level; a contract or an assertion gives each of its parts one, Pre => (Silver => Is_Small (X), Gold => Is_Tiny (X)), pragma Assert (Gold => Is_Tiny (X)). Verada proves every part at every level, and its proved builds erase all ghost code, so levels change no proof and no compiled behaviour. What they change is what is legal: a ghost entity of a level is referenced only from an assertion or a ghost entity whose level depends on it (or that has no level, or depends on Static, which is never enabled), so that disabling a level never leaves a reference to what it removed (B2030).

Exceptional and class-wide contracts

Exceptional_Cases defines permitted propagated user exceptions and their exceptional post-state consequences. It applies to procedures, not functions, and has by-copy output restrictions. Normal postconditions apply on normal return; exceptional consequences apply on the corresponding propagation. See exceptions.

Only Pre'Class and Post'Class are supported class-wide aspects. Their inherited substitutability rules differ from simply replacing one specific contract with another. Other class-wide aspect spellings are rejected.

For each concrete aspect/pragma name, consult the complete catalog. For interpretation of solver proof, replayed failures, unknown results, trust, and evidence, use the worked verification diagnosis and Toolchain proof operations rather than inferring a stronger assurance level from syntax alone.