On this page
Subprograms, calls, dispatch, and callbacks
A subprogram declares a profile and an operation. The profile specifies parameters, their modes and subtypes, and an optional function result. Contracts state what callers must establish and what they may assume after the operation. A separately verified body must meet that interface for every permitted input, independently of calls in main. Supported contract-free nested helpers can instead be inlined and checked at call sites; that does not give them an independently proved all-input interface contract. One that nothing calls is proved on its own, for every input, so that what it would do wrong is still reported.
Functions and procedures
A function produces a value. A procedure performs statements and can communicate results through writable parameters. Vada spells these differently; Varc uses a function-like declaration whose result and modes determine the operation; Vibe infers supported procedure forms from component mutation and adapts selected final outputs through result assignments.
Functions obey restrictions on writable state and termination, unless declared with Side_Effects: such a function may write globals and out or in out parameters, raise exceptions and need not terminate, like a procedure, and is called only as the whole value of an assignment or of an object declaration (B2029); Verada compiles and proves it as a procedure whose last out parameter is the result. Reading permitted globals requires the appropriate effects; volatile function inputs have additional rules.
A procedure (or a function with Side_Effects) that may end the whole program says so with Program_Exit => Condition; GNAT.OS_Lib.OS_Exit is the one predefined subprogram that does. Verada proves that a call that may exit is made only where the caller may exit too, and that the caller's condition holds there (B5120); a main program that exits needs the aspect as well. Exit_Cases => (Guard => Normal_Return | Exception_Raised | (Exception_Raised => E) | Program_Exit, ..., others => ...) says how the subprogram ends for each guard on entry; the guards must not overlap, and every return, propagated exception and exit is proved to be one its case allows (B5121). Functions cannot declare propagated Exceptional_Cases. A supported Vibe method that mutates an object and returns a value becomes a procedure with an additional result output, not a general exception to the function model.
A plain declaration requires its conforming body unless it is abstract, imported, or another accepted bodyless form. An expression function defines its result using one expression. A null procedure has an empty implementation and still must establish its contract. Declaration/body profiles must conform; an accidental overload does not complete another operation's missing body.
Parameter modes
| Mode | Incoming requirement | What the operation can do | Normal-return obligation |
|---|---|---|---|
in |
A valid initialized value | Read through its permitted view | Cannot move away storage still owned by the caller |
out |
A writable actual with applicable shape/type information | Establish the output | Required output parts and constraints hold |
in out |
A valid initialized writable actual | Read and update | Required output constraints and ownership are restored |
The default mode is in. Only in parameters can have default expressions. A mode is a language-level dataflow contract, not merely the native calling convention. Arrays and records can use pointer-shaped native arguments even when the semantic operation must preserve by-copy behavior on exceptional return.
Varc requires &actual where the declared mode is out or inout, and rejects the mark on an ordinary input. The mark makes caller-visible mutation explicit. Vibe cannot change a caller's scalar by rebinding a Python parameter: a Vibe function returns its scalar results, and an update to a list or record component makes the parameter in out. The Vibe reference shows how Vibe calls Vada and Varc procedures with scalar out and in out parameters.
Actual and formal subtypes need not be textually identical when the language permits the association. Checks constrain incoming values and outgoing copyback to the actual's subtype. Array arguments carry or adapt their bounds, with dimensional length obligations. An out mode does not erase the information needed to describe an array's shape.
Argument association and defaults
Positional arguments bind in parameter order. Named arguments identify a formal explicitly. Positional arguments cannot follow named arguments. Supplying the same formal twice, omitting a required argument, or supplying an unknown name is an error. A default is used only where the profile permits it; it does not infer a missing type or bypass a precondition.
The compiler resolves overloaded candidates using argument association, types, expected result type, and visible declarations. It reports ambiguity when more than one valid candidate remains. Use a selected name, type qualification, or explicit conversion to express the intended candidate. A successful parse of a call-like form might instead resolve to indexing or conversion in a frontend that shares that notation.
Vibe keyword calls, defaults, method calls, and generic calls form a supported subset. Method keyword arguments and some default/inference patterns are rejected. The ordinary Python calling protocol, arbitrary decorators, variadic arguments, and runtime introspection are not automatically available.
Interference and aliasing
Two writable actuals must not interfere in a way forbidden by the mode/alias rules. The same object cannot generally be supplied twice as outputs or as a writable actual and an aliasing non-copy view. A writable actual also cannot hide interference with a global the callee uses. B3010 identifies statically known argument interference; other overlap obligations can generate checks.
Passing an input by copy can permit some combinations that two shared writable references cannot. Do not infer permission merely because the native ABI happens to use pointers. Make independent values explicit when a call needs a stable snapshot, and account for ownership moves when a snapshot cannot legally copy an owning value.
Contracts at a call
Before a call, the caller establishes the declared precondition, input subtype conditions, nonnull requirements, and applicable private-type invariants. During proof of the body, those entry conditions are assumptions. After a normal call, the caller may use the postcondition and permitted effect/dependency information.
A function returning Natural promises a result in that subtype, but a stronger functional relationship needs a contract. If a body computes exactly X + 1 without saying so in its visible postcondition, a modular caller cannot assume every implementation detail. Conversely, an unproved or trusted contract remains an assumption boundary rather than evidence that the implementation body has been verified.
The implementation may inline supported expression-function reasoning, but users should specify public relationships that clients need. Inlined reasoning is not a substitute for a stable abstraction boundary or a means to circumvent proof of the function itself.
Nested operations and recursion
Vada/Varc support nested subprograms in the accepted declarative contexts. They may refer to permitted enclosing objects, with captures included in effects/initialization analysis. This is static lexical access, not an unrestricted first-class closure mechanism. Eligible contract-free nested helpers are proved by inlining at calls rather than by a separate all-input body obligation; add an appropriate interface when modular verification is needed.
Recursive functions require a Subprogram_Variant and proof of progress. A terminating operation's loops and called procedures must satisfy the relevant termination policy. Ordinary procedures need not terminate unless marked, but that does not make a nonterminating procedure acceptable when called from a context that must terminate.
Primitive operations and dispatch
Operations associated with a tagged type can be inherited or overridden. A conforming overriding declaration matches the inherited profile. Abstract primitives require a concrete implementation before use on a concrete type. A prefixed view such as Object.Op is a supported way to supply the controlling object, not arbitrary member-function lookup on every record.
A dispatching call chooses the implementation using the dynamic tag of its controlling value. The relevant specific and class-wide contracts determine legal calls and promised results. Class-wide preconditions provide the supported alternatives in the hierarchy; inherited class-wide postconditions remain requirements of overriding implementations. Use the contract hierarchy rather than assuming an override can strengthen a caller's required class-wide conditions arbitrarily.
Vibe's class hierarchies and protocols map to these rules as described in the Vibe reference.
Access-to-subprogram types
A callback type declares an operation profile together with its supported contracts. It can designate compatible library operations, be null unless excluded, and be stored in supported composites. A call through it must establish the access type's precondition and receives the guarantees of that type's postcondition.
This is a declaration fragment from the callback model:
type Unary is access function (X : Integer) return Integer
with Pre => X in -1000 .. 1000,
Post => Unary'Result in -2000 .. 2000;A designated function must be valid over the callback's accepted inputs and establish the callback's promised outputs. Assigning Double'Access therefore creates substitutability obligations, not just a machine-signature comparison. Nullable indirect calls require proof that the access value is not null. not null puts that obligation at construction or the call boundary instead.
A callback type's Global states what the subprograms it designates may read and write; a call through it reads and writes those objects, as a call of a subprogram with that Global would:
type Action is access procedure (Step : Natural)
with Global => (In_Out => Count),
Post => Count >= Count'Old;Bump'Access is an Action only when Bump uses nothing beyond the type's Global (B3003), and writes on every path what it gives mode Output (B3004). A callback type without Global designates only subprograms that use no globals. A function called through an access value is a function of its arguments and of the value: two values may designate different functions.
Nested subprograms cannot be designated: declare a subprogram that is designated in a package (B0501). Generic formal subprograms and consumed pipeline lambdas offer supported alternatives when a named higher-order operation is needed without a runtime closure.
A parameter can also name its profile directly, without a named type:
function Apply (F : not null access function (X : Integer) return Integer;
V : Integer) return Integer is (F (V));Varc writes it F: not null *fn(X: Integer) -> Integer. The actual is 'Access of a subprogram declared in a package or of a library subprogram, such as Apply (Ops.Half'Access, 42); a nested subprogram is B0501. An anonymous profile has no contract, so a designated subprogram's precondition must hold for every argument the profile allows (B5101 otherwise), and the designated subprogram may not read or write globals (B3003). A body that repeats the parameter's profile conforms to its specification.
See the maintained callback specification and application for complete context. Vada and Varc declare callback types directly; Vibe has no callback-type declaration.
Foreign calls and abnormal return
Imported operations require accurate profiles, representations, effects, and contracts. Calls into C trust their stated behavior; compiler proof does not inspect arbitrary C. Exported operations can be called by code that has not proved their preconditions, so the foreign boundary needs its own enforcement and integration design.
Normal output copyback and exceptional effects are different. Tagged, class-wide, and limited types are semantically by reference; by-copy outputs can remain unchanged in the caller when an exception propagates. See exceptions and the Toolchain foreign-interface chapter for precise integration and runtime behavior.