DEVELOPMENT EDITION · 769442725406
Language Reference
On this page

Verada and standard Ada

This chapter is for programmers who know Ada. It says how Verada relates to the Ada standard, which Ada features Verada leaves out and what to write instead, where a form that Ada also has means something different in Verada, and what Verada adds.

An Ada-like language, every program proved

Verada is a modern language in Ada's family. Its Vada syntax is Ada's syntax, and an ordinary Vada declaration, statement, type or contract means what it means in Ada. Verada is not an Ada implementation, and it does not aim to conform to the Ada standard. It takes a selection of Ada's features that can be proved, and it adds forms of its own where they make programs cleaner. Where an Ada form helps Ada programmers feel at home, Verada keeps it. Where a newer form does the job better, Verada uses that form.

Every program Verada builds is proved. Each run-time check (overflow, range, index, division, null, discriminant, length, predicate and contract) must be shown never to fail, and a construct Verada cannot prove is not in the language. Development modes may run a program with unproved checks kept as run-time checks, but a build proves them all. This is the main difference from writing Ada. Verada also requires things that Ada leaves to the programmer:

A program that GNAT accepts may therefore be rejected by Verada, or fail to prove. A proved Vada program is normally Ada that GNAT also compiles, except where it uses Verada's extensions (below). The same language has two other syntaxes, Varc (C-family) and Vibe (typed Python), and the compatibility chapter describes them.

Ada features Verada leaves out

Most of the features below are left out because a proof of a program that uses them would depend on code the proof cannot see: through hidden control flow, hidden aliasing, or reasoning about every task and caller at once. The rest, such as goto and the obsolescent forms, have a cleaner replacement. Each one is reported as not in Verada, and the diagnostic names the replacement.

Ada feature Use instead
Task entries and rendezvous (accept, select on entries) A protected object with entries and barriers, served by library-level tasks; suspension objects for a simple signal
abort A protected flag the task checks, or Verada.Tasking.Stop to end every task
Asynchronous select ... then abort A computation that checks a deadline or a protected flag at safe points
requeue Two entry calls, or one entry with a wider barrier
Dynamic tasks: a task in a subprogram, an allocated task, a pool of tasks made at run time (an array of tasks of static bounds in a library package is a fixed set, and in Verada), a task or protected object as a record component A fixed set of tasks declared in library packages, each serving a queue
Synchronized, task and protected interfaces Plain and limited interfaces
Parallel loops and blocks Pipelines and library-level tasks
goto and statement labels exit (with a loop name where needed), return, and named loops and blocks
'Unchecked_Access, 'Unrestricted_Access, access discriminants Owning access types with borrowers and observers, general access types, or Verada.Containers.Arenas
'Access of a subprogram nested in another subprogram Declare the subprogram in a package, so that it is at library level
Storage pools and subpools (System.Storage_Pools, Storage_Pool) Ownership, which frees owned objects, and arenas
Controlled types (Ada.Finalization) Reclaimed types, declared with Finalizable
Stream attributes ('Read, 'Write, 'Input, 'Output) and Ada.Streams Encode and decode procedures written for the type
Handlers for Constraint_Error, Program_Error and Storage_Error Prove the check; where a value comes from outside, test it first or state it in a precondition
Ada.Calendar Ada.Real_Time for clocks and delays
Ada.Tags Dispatching calls and class membership tests (X in T'Class)
Ada.Execution_Time Intervals measured with Ada.Real_Time.Clock
Ada.Task_Identification The library-level task's own name; tasks are fixed when the program is written
Ada.Synchronous_Barriers A protected entry whose barrier counts arrivals
Ada.Sequential_IO and Ada.Direct_IO Ada.Text_IO files, each record written and read as a line by encode and decode procedures written for the type
Ada.Text_IO.File_Access, and the overloads of Standard_Input, Current_Output and the other file functions that return one Pass the File_Type as an in out parameter
Ada.Directories.Modification_Time Ada.Directories.Modification_Seconds, the time in seconds since the epoch
Ada.Containers.Vectors, Ada.Containers.Doubly_Linked_Lists, Ada.Containers.Hashed_Maps, Ada.Containers.Ordered_Maps, Ada.Containers.Hashed_Sets, Ada.Containers.Ordered_Sets, their Indefinite_ forms, Ada.Containers.Multiway_Trees, Ada.Containers.Indefinite_Multiway_Trees and Ada.Containers.Indefinite_Holders Verada.Containers.Unbounded.Vectors, Maps, Ordered_Sets and Dictionaries, limited and reclaimed, with contracts over functional models
Ada.Containers.Bounded_Multiway_Trees and Ada.Containers.Bounded_Indefinite_Holders Verada.Containers.Graphs for a tree; a record holding the value, or Verada.Optionals, for a holder
Ada.Storage_IO Encode and decode procedures written for the type, into a String or an array of System.Storage_Elements.Storage_Element
Ada.Locales Values the program is given, through Ada.Command_Line
Interfaces.C.Strings Interfaces.C.char_array, with To_C and To_Ada
SPARK.Pointers.Pointers_With_Aliasing Owning access types under the ownership rules, or Verada.Containers.Arenas for shared nodes
SPARK.Cut_Operations Successive pragma Asserts: each is proved, then known to those after it
SPARK.Lemmas.Mod32_Arithmetic Verada.Lemmas.Arithmetic, applied to the operands' values as integers
The 'Has_Same_Storage and 'Overlaps_Storage attributes Ownership, which keeps an object that is written from being reached through another name; compare access values (X = Y) where two observers may designate one object
GNAT's 'Descriptor_Size attribute 'First, 'Last and 'Length for the bounds, and 'Size for the components
GNAT's 'Type_Class attribute A generic whose formal type states the class it takes (range <>, mod <>, digits <>)
Ada.Exceptions.Reraise_Occurrence of an occurrence other than its handler's own raise; in the handler that names the occurrence, or a raise of the exception by name (raise E with Exception_Message (X))
Ada.Iterator_Interfaces, and the Default_Iterator and Iterator_Element aspects The Iterable aspect, which names the type's First, Next, Has_Element and Element operations
User-defined indexing and references: the Constant_Indexing, Variable_Indexing and Implicit_Dereference aspects The type's own Element function and update procedures, called by name
The Predicate_Failure aspect Nothing: a predicate check is proved, so it never fails
The Unchecked_Union aspect A discriminated record, or Unchecked_Conversion of scalars
The Small aspect, and for T'Small use A delta that is a power of two; Verada chooses the small from the delta
Bit-packed arrays: a Component_Size that stores components in fewer bits than their natural storage (Pack, which is advice, is accepted and leaves the natural layout) A modular type whose bits are the flags (and, or and shifts on it), or a record representation clause
A type's convention other than Ada's and C's (Convention => Fortran, Cobol) Ada's layout, the column-major order written as the index order (A (J, I)), or Convention => C to share a type with C
A record representation clause on a tagged type An untagged record with the clause, as a component of the tagged one
Unchecked_Conversion of a tagged type Convert the record's untagged components, or write and read the value through encode and decode procedures written for the type
Unchecked_Conversion to or from an access type Handles of Verada.Containers.Arenas, which are values: store, convert and compare them as numbers
'Image of an access value The image of what it designates (P.all'Image), or of a handle of Verada.Containers.Arenas
Obsolescent forms (Annex J) The modern form, which the diagnostic offers as a fix-it

Concurrency and ownership describe the replacements for tasking and pointers in full.

Differences in meaning

Functions have no side effects

An ordinary function may not write a global, directly or through a procedure it calls, and may not have out or in out parameters (B3006). Ada allows both. Expressions, contracts and assertions are then free of hidden changes of state. A function that must change state is declared with Side_Effects, and is called only as the whole value of an assignment or an object declaration (B2029). See subprograms.

Real-time arithmetic saturates

Ada.Real_Time's Time + Time_Span and Time - Time_Span stop at Time_Last and Time_First instead of raising Constraint_Error. A periodic task that adds its period to the next release time forever is then proved, where no precondition could be. Time is a count of nanoseconds in 64 bits, and the clock counts from about when the machine started, so Time_Last is more than 160 years beyond any reading and the saturation never happens in a running program. The other Real_Time operations have preconditions that keep them in range. See time and tasking.

Index and pattern errors of the string packages are preconditions

Where Ada.Strings.Unbounded, Fixed and Bounded raise Index_Error or Pattern_Error (a position outside the string, an empty pattern), Verada's operations have a precondition that rules the case out, so a proved program never raises them. Ada.Strings.Unbounded's String_Access is a pool-specific access type (access String, not access all String), so that Free releases only what an allocator made. See strings.

Ada's bounded containers

Ada.Containers.Bounded_Vectors, Bounded_Doubly_Linked_Lists, Bounded_Hashed_Maps, Bounded_Ordered_Maps, Bounded_Hashed_Sets and Bounded_Ordered_Sets take Ada's generic formals and capacity discriminants, and follow the design of Verada.Containers.Formal: each operation's contract states what it does at every place, over a ghost functional model. Elements are reached by index, key, value or place; only the list has cursors, and an operation that reads through one takes the list too, as GNAT's formal containers do. Where Ada raises Constraint_Error or Capacity_Error, a precondition rules the case out. A map or set looks its keys up one entry after another, so Hash and the modulus are taken and not needed. GNAT's formal containers (SPARK.Containers.Formal.Vectors and the others, and the older Ada.Containers.Formal_Vectors names) are reported with a fix-it to these units (B0903). See bounded containers.

Package state behind its abstraction

A package that declares Abstract_State keeps its hidden variables (in its private part, its body or a private child) as constituents of that state, each named by Part_Of or in the body's Refined_State (B3017). Clients' Global and Depends contracts name the state, not the variables. A package's Initializes lists exactly the variables its elaboration gives a value (B3012). See dependencies and abstract state.

Integer is 64 bits

Integer is −2⁶³ through 2⁶³ − 1, and so are Natural and Positive above their lower bounds. Every length, count, index and position in the language and library follows from this: String indices, Text_IO.Count, and the lengths of containers and texts. Long_Integer and Long_Long_Integer have the same range as Integer but are distinct types, and Long_Long_Long_Integer is 128 bits. For an exact width, use Interfaces.Integer_32 and its siblings, and for C's int use Interfaces.C.int. Strings, texts and unbounded containers are limited only by memory. See integer ranges.

Text and Unicode

String and Character are Latin-1, as in Ada. Wide_String holds the Basic Multilingual Plane, and Wide_Wide_String holds every code point. A string literal takes its type from its context. Ada.Strings.UTF_Encoding.Wide_Wide_Strings converts to and from UTF-8. Its Decode reads a malformed byte sequence as U+FFFD, the replacement character, where Ada raises Encoding_Error.

Ada.Wide_Text_IO and Ada.Wide_Wide_Text_IO hold a file's characters as UTF-8, and read bytes that are not UTF-8 (and, in Wide_Text_IO, a character above 16#FFFF#) as U+FFFD. Their files are Text_IO's, and so are the current input, output and error, which the three units share: Set_Output in one sets it for all of them. See wide characters.

Ada.Wide_Wide_Characters.Handling classifies by Unicode 16.0.0's general categories and converts case by Unicode's simple mappings, as Ada's does; its Is_Basic and To_Basic are of letters only, as Ada.Characters.Handling's are, and To_Basic removes all of a letter's combining marks ('ǖ' to 'u'), not only the first level of its decomposition. Verada adds Category, a character's general category. Ada.Strings.Wide_Wide_Fixed has the operations Verada's Ada.Strings.Fixed has. See characters.

Verada adds Verada.Strings.Texts.Text, a copyable string value with no size to declare. It is the string type of Vibe and of Varc's string literals. See strings and copyable text.

Exceptions and failed checks

A failed check is not an exception a program handles. In a proved program checks do not fail, so a handler for Constraint_Error, Program_Error or Storage_Error is rejected (B1018), and when others does not take a failed check (B8006 says so). In a development build that keeps unproved checks, a failed check stops the program with a report.

User exceptions are part of a procedure's contract. A procedure lists the exceptions it may propagate in Exceptional_Cases, and a raise that is neither handled nor listed must be proved unreachable. Ordinary functions do not propagate exceptions. When an exception leaves a procedure, its scalar out and in out parameters keep the values they had at the call. See exceptions.

Ownership instead of aliasing

An access value owns what it designates. Assigning it moves ownership, and the old name cannot be read again. A borrower or an observer gives temporary access, and the owner is unavailable or read-only while it lasts. Ada.Unchecked_Deallocation frees an owned object, and the prover shows that nothing is leaked or used after it is freed. A general access type (access all) takes the aliased object it designates for good. Two writable names for one object are not allowed at a call (B3010). See ownership.

Access values are compared only with null, and a type with access components has no predefined = (B2009). Compare the designated values, or the components you mean.

Numbers

See types.

Representation

Verada chooses the representation of every type. Representation aspects and clauses do not change it; the aspect and pragma catalog lists which are accepted. An address clause is the exception: it places a volatile object at an address. A record's layout is Verada's own, so pass foreign data through scalars and arrays.

Obsolescent forms

The forms of Ada's Annex J are not taken as written. This covers replacement characters, pragmas that have aspect forms, Ada 83 library unit names such as Text_IO, the wide-character conversions of Ada.Characters.Handling (J.14), for X use at and at mod clauses, and digits constraints on floating-point subtypes and delta constraints. Verada reports each one with a fix-it to the modern form, and reads an old unit name as the new unit.

Code written for Ada 83 or Ada 95 is brought to the modern forms by these fix-its. An editor offers each as a quick fix where it is reported; veradic --diagnostics json check lists every one with its replacement (the fixes of each diagnostic, Diagnostics as JSON), for a tool to apply. The forms change their spelling, not their meaning: Ada.Characters.Handling.To_Wide_String and Ada.Characters.Conversions.To_Wide_String are one function. Obsolescent pragmas are warnings, so a program that uses them still checks; the other forms are errors until they are rewritten.

Generics

A generic's specification and body are checked where they are declared, as Ada checks them, with each formal standing for any actual it may have: an error in a generic is reported at its own line, once, whether or not anything instantiates it. Each instance is checked again with its actuals, for the rules that depend on them (RM 12.3(11)); what that finds in the generic's text is reported at the instance, naming the generic's line it comes from. A generic is proved in its instances, with its formals bound to the actuals (a generic enclave whose formals are private types once, for every actual). An instance declared before its generic's body in the same unit, where Ada raises Program_Error when it is elaborated, is refused when the program is checked (B1021).

Tasking

Tasks and protected objects follow the Jorvik profile. Tasks are declared in library packages. They start together once library elaboration is over, and the program waits for them after the main subprogram returns. Flow analysis proves that no variable is shared between tasks outside a protected object. Priority is used to check the ceiling rules; the run time does not schedule tasks by priority. See concurrency.

Elaboration and annotations

Verada computes the elaboration order and checks initialization itself. Pure, Preelaborate, Inline, No_Return and similar names are accepted with no effect: the restrictions Ada attaches to Pure and Preelaborate (RM 10.2.1), and where those pragmas may stand, are not checked. SPARK_Mode => Off does not turn analysis off (B8004). The aspect and pragma catalog lists each such name.

Verada's extensions

Vada takes these forms after pragma Extensions_Allowed (On):

Together with Ada 2022's iterator filters and 'Reduce, they make pipelines, which compile to one loop and are proved like one. veradic translate --to vada --plain-ada writes them as plain Ada loops.

Three attributes are Verada additions, taken without the pragma: Small_Numerator and Small_Denominator, a fixed-point type's small as a fraction, and Valid_Value, whether Value would read a string, for every scalar type (GNAT has the first two, and Valid_Value for enumeration types). The attribute reference describes them.

Verada also has Finalizable reclaimed types, which are a GNAT extension (-gnatX), and Verada.Tasking.Stop, which ends every task. The Verada.* library units add containers, texts, arenas, functional models for proof, and numerics; the Library Reference lists them.