DEVELOPMENT EDITION · 769442725406
Programmer Guide
On this page

Tasks, devices and foreign code

Take these paths once you can design and prove an ordinary package. Start with the smallest interface that isolates the concurrent or external behavior: each of these features brings in facts that a proof of sequential code cannot establish on its own.

Choose synchronization before adding tasks

A task runs on its own. Verada follows Ada's Jorvik profile: tasks are declared at library level, live as long as the program, and share state only through protected objects.

Put mutable state that several tasks use behind a protected object. A protected procedure changes the state under the object's lock; a protected function reads it; an entry adds a barrier, a condition that must be true before a caller may proceed. Choose by what the operation does, not by which looks familiar.

The compiler's tasking project is a complete task and protected-object program, and its Vibe counterpart shows the same with Vibe's @task functions and Protected classes.

A good first exercise is to list every piece of state each task reads or writes, including output, which is shared too. Proving that each task's addition stays in range does not make two tasks writing one counter safe; the protected object does.

What Verada checks for tasks

Race analysis rejects unprotected shared access. Nonblocking analysis keeps delays and blocking calls out of protected actions. Ceiling analysis checks that each protected object's priority is high enough for its callers.

These checks do not prove that the program is free of deadlock, that scheduling is fair, that deadlines are met or that a barrier eventually opens. Review the protocol yourself: what makes each barrier true, and could every task that would make it true be waiting itself?

The platform's scheduler decides how priorities behave. When the main program returns, the runtime waits for the library tasks; stop them through Verada's task API. The concurrency chapter has the rules.

Read external values once

A volatile object can change at any moment, because hardware or another program writes it; two reads can differ. When a calculation needs a stable value, read the object once into a local variable and reason about that copy.

The aspects Async_Writers, Async_Readers, Effective_Reads and Effective_Writes say how an external object behaves and what the prover may assume about it. A function that reads such an object must be marked Volatile_Function; it is not pure.

An object at a fixed address must be declared in a package and be volatile or atomic, and its address must be a constant expression. Mapping an address does not prove that the hardware is there or that it behaves as declared. See tasks, protected objects and external devices.

Put C behind a narrow contract

An import declares a C function's name, parameter and result types, calling convention, effects and pre- and postconditions. Verada proves the callers against that contract and trusts that the C code meets it; it does not read or prove the C.

Start with a small operation on plain values. Confirm the integer widths, how arrays and strings are passed (length, termination), who owns any memory, and how long callbacks may be kept. The C integration chapter builds complete projects with C sources, imports, exports and callbacks, and veradic trust lists every imported contract that a proof relies on.

Exports need caller discipline

C code can call an exported Verada operation without proving its precondition. The proof of the Verada body assumes the precondition, so decide at the boundary whether to check the inputs at run time, and document the errors and the ownership of anything passed across.

A callback needs a profile, a contract and a lifetime. An access-to-subprogram value is not a closure: it designates a subprogram declared in a package or a library subprogram, never one nested in another subprogram (B1019), even when it is passed as an anonymous access-to-subprogram parameter. Pass what a callback needs as its parameters.

Debug at the right layer

A missing symbol or a calling-convention mismatch is not a missing loop invariant, and a proof that trusts a false C postcondition does not make the binary honor it. Use the tool that answers the question: veradic emit for LLVM IR, assembly or Verada Core, --show-flow for inferred effects, --dump-vcs for the prover's queries, and -g with a debugger for the native program. Debugging shows each.

Keep a small program that exercises the boundary, and run it the way you deploy it: as a native executable on the target platform, checking output, errors and cleanup.

Choose the next abstraction

For shared graph structure, use an arena with handles, or a proof enclave that keeps a pointer-based representation behind a value-like API. For storage that grows, use the library's unbounded containers. Measure performance before reaching for target options such as --target-cpu.