Records of named cells over the memory oracle #
A data structure with a fixed shape, such as a struct of arrays, stores its words in named cells:
key v, par v, a counter. Record.spec ok w is the interface to such a record. Its state gives
each cell of a type ι a value; an operation reads or writes one cell. The predicate ok says
which cells exist (for instance v < n for an array of length n), and admissibility asks that
an accessed cell exist and that a written value fit a w-bit word.
A data structure is then a program over its record (Record.Prog), and its proofs see named
cells rather than addresses. Record.wp is the weakest precondition of such a program under a
postcondition on its answer, its final record and its number of operations. It evaluates by
simp one operation at a time (wp_read_bind, wp_write_bind), composes (wp_bind), and
determines admissibility, answer, final state and cost of the run (wp_iff).
A Record.Layout places the cells in memory: an address for each cell, injective on the cells
that exist. Record.refinement implements the record over Memory.spec w by one memory operation
per record operation (Record.amortized). Record.framed packages it as a framed structure over
memory, whose footprint holds the cells' addresses, and Record.allocator allocates a record in
zeroed cells at the frontier. A structure written over a record then joins products of
structures over one memory through Memory.Framed.comp and Memory.Allocator.comp. Address
arithmetic, allocation and word-fit of addresses are therefore proved once here, for every
record.
Main definitions #
Record.Op,Record.step,Record.valid,Record.spec: the record interface.Record.Prog,Record.read,Record.write: programs over a record.Record.wp: weakest precondition of a program, with the number of its operations.Record.Layout,Record.Layout.abs,Record.Layout.Inv: a placement in memory.Record.refinement: the record over the memory oracle.Record.framed,Record.allocator: the record as a framed structure, and its allocation.
Main results #
Record.wp_iff: the weakest precondition is admissibility of the run together with the postcondition on its answer, final state and length.Record.wp_bind,Record.wp_mono: sequencing and consequence.Record.amortized,Record.amortized_allocator: each record operation costs one memory unit.
A read returns the cell's value.
The transition of each record operation.
The record interface with cells ok at word size w.
Programs over a record with cells indexed by ι.
Read a cell.
Weakest preconditions #
The weakest precondition of p under Q: every operation of the run from g is admissible,
and Q holds of the answer, the final record and the number of operations.
The weakest precondition holds exactly when the run is admissible and Q holds of its answer,
final record and number of operations.
Placement in memory #
A placement of the record's cells in memory: an address for each cell, injective on the cells that exist.
- addr : ι → ℕ
The address of each cell.
Distinct existing cells have distinct addresses.
The record operations as memory operations at the cells' addresses.
The record stored in memory; cells that do not exist read as 0.
Every existing cell is allocated.
Writing an existing cell writes its address.
The record over the memory oracle: each operation is the memory operation at the cell's address.
Each record operation costs one memory unit; no potential is needed.
Records as framed structures #
A record in memory as a framed structure. Its footprint fp holds the addresses of its
cells, and is allocated once they are. Each record operation reads or writes the address of one
cell and keeps the frontier.
Allocating a record: size zeroed cells at the frontier, laid out by L from their base,
where the last of them is a cell. It costs size + 1 memory units, and the record holds 0 in
every cell.
Every operation on an allocated record costs one memory unit, with no potential.