Framed backends: frames, products over one memory, and allocation #
A backend that implements a framed refinement (Memory.Framed) inherits its frame. A native
operation leaves its method's final memory (Backend.exec_memoryState), so it writes only the
refinement's region, its footprint and the room reserved above the frontier
(Backend.modifies). An assertion on other cells survives it (Backend.frame_heap), and so
does every framed structure kept apart from it (Backend.frame). Backends of two framed
refinements run their product over one memory (Implements.prod_framed). The product is framed
again by the union of the footprints and the sum of the rooms, so products iterate, and
Memory.Framed.amortized_prod adds their costs for Backend.amortized.
Allocation. An allocator (Memory.Allocator) sets a structure up in memory with a program
that returns a handle, such as a layout of named fields. A Backend.Allocation names the tag
whose body runs that program, and reads the handle off the body's result. After uncharged
argument installation, the body runs from bounded data with the allocator's precondition and
room within the certified bound. It returns the handle, writes only the room it takes above the
frontier, and leaves data that the handle's backend represents at the allocator's initial state
(Allocation.exec). The bound is the allocator's memory cost and the body's local work. When
allocation reserves memory without clearing it (Memory.allocDirty), as the array stack does,
both are constant.
Base-relative layouts. A family F : A.Handle → Backend D C uses one fixed finite
certificate family C, whose bodies, register layout and exchange factor precede the runtime
handle. The handle supplies arguments to those bodies. The selected tag (F h).tag o may depend
on h. If the tag is handle-independent for each operation, that operation uses the same body
across layouts. The general guarantee is a fixed finite code family; uniform local-work bounds
must also hold across handles.
The frame is that of the memory-level refinement (Memory.Framed.region).
Main definitions #
Backend.Allocation: the tag, argument and handle of a realized allocation.
Main results #
Backend.clientRun_exec: a native operation runs its method between the memories it holds.Backend.modifies: a native operation writes only its structure's region.Backend.frame_heap,Backend.frame: disjoint assertions, and structures kept apart, survive.Backend.Implements.prod_framed: backends of framed refinements run their product over one memory.Backend.modifies_inl,Backend.modifies_inr: each operation of a product writes only its own structure's region.Backend.Allocation.exec: allocation from arbitrary memory, within the allocator's cost.
The frame of a native operation #
A native operation runs its method from the memory it holds to the memory it leaves.
The frame of a native operation. An operation of a backend that implements a framed
refinement writes only the refinement's region: its footprint, and the room reserved above the
frontier. Without room (Memory.Framed.region_eq_footprint) it writes only the footprint.
A native operation keeps every assertion on cells outside its structure's region.
A native operation keeps a structure apart from its own: the other structure's abstraction and invariant are unchanged, and the two stay apart, with disjoint footprints and room for both.
Products over one memory #
Products over one memory. Backends of two framed refinements run their product
(Memory.Framed.prod), whose frame is the union of the footprints and the sum of the rooms.
Each side keeps its own frame. An operation of the left structure of a product writes only that structure's region.
An operation of the right structure of a product writes only that structure's region.
Allocation #
A realized allocation for the allocator A: the body of tag tag, on arguments arg,
runs the allocation program, and handle reads the allocated handle off its result. From memory
the allocator can allocate from, the arguments fit words and the tag's domain holds.
- tag : ι
The tag whose body allocates.
Its arguments, such as a capacity.
The handle, read off the body's result.
- run (s : (DataStructure.Memory.spec w).State) : (DataStructure.Memory.spec w).runClient s A.alloc = Prod.map self.handle id ((DataStructure.Memory.spec w).runClient s ((C self.tag).prog self.arg))
The tag's program is the allocation, with the handle read off its result.
- entry {s : DataStructure.Memory.State} : DataStructure.Memory.WellFormed w s → A.Pre s → Fits w (s.frontier + A.room) → (∀ (j : Fin (C self.tag).k), Fits w ((C self.tag).input self.arg j)) ∧ (C self.tag).safe w self.arg s
From memory the allocator can allocate from, the arguments fit words and the tag's domain holds.
Allocation from arbitrary memory. From bounded data whose memory the allocator can
allocate from, with its room fitting a word, the allocation body runs within
factor C * (A.cost + work + 1) instructions, where work is its local work. It returns the
allocated handle in its result registers, writes only the room it takes above the frontier, and
leaves data that the handle's backend represents at the allocator's initial state.
Execution starts after the uncharged install has supplied the argument registers. A raw-data
initializer must separately pay native argument installation and any allocation-cursor setup.