Documentation

Complexity.Computability.Ram.Compiler.Language.Arena.Basic

Shared-object representation in a monotone arena #

The opt-in arena convention reserves address zero for a shared allocation cursor. Every represented word's address is positive and below that cursor, including storage for immutable-node payloads, tags and tail addresses. Holes and empty objects are allowed. The fixed heapLimit separates heap and stack. Existing HeapRep clients acquire no new restriction.

Reservation retains the old source heap until the fresh region is initialized. These memory-frame rules assert neither a completed allocation nor its cost.

theorem Ram.LanguageCompiler.HeapRep.of_mem_eq_on {w : ℕ} {placement : ℕ → Word w} {heapLimit : ℕ} {heap : Complexity.Language.Heap} {entry finish : Source.State w} (represented : HeapRep placement heapLimit heap entry) (same : ∀ {id : ℕ} {object : Complexity.Language.HeapObject}, heap.objects[id]? = some object → ∀ index < (heapObjectWords placement object).size, finish.mem (arrayAddr (placement id) index) = entry.mem (arrayAddr (placement id) index)) :
HeapRep placement heapLimit heap finish

Transport heap representation using equality only on actual object words. Unrepresented memory, registers and input/output may differ.

structure Ram.LanguageCompiler.ArenaRep {w : ℕ} (placement : ℕ → Word w) (next heapLimit : ℕ) (heap : Complexity.Language.Heap) (target : Source.State w) :

Complete objects below a shared bump cursor. This measures reserved extent, not compact storage, reclaimable space or reachable live data.

Instances For
    theorem Ram.LanguageCompiler.ArenaRep.reserved {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {τ : Complexity.Language.CellTy} {object : ℕ} {values : Array (Complexity.Language.CellValue τ)} (found : heap.object? τ object = some values) (index : ℕ) (bound : index < values.size) :
    0 < BitVec.toNat (arrayAddr (placement object) index) ∧ BitVec.toNat (arrayAddr (placement object) index) < next

    The original scalar-array reservation rule follows from reservation of every word in both object kinds.

    theorem Ram.LanguageCompiler.ArenaRep.cursor_toNat {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) :
    BitVec.toNat (entry.mem 0) = next

    The cursor is observed exactly, without modular reduction.

    theorem Ram.LanguageCompiler.ArenaRep.stored_address_ne_zero {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {id : ℕ} {object : Complexity.Language.HeapObject} (found : heap.objects[id]? = some object) {index : ℕ} (bound : index < (heapObjectWords placement object).size) :
    arrayAddr (placement id) index ≠ 0

    No represented word, including a node field, occupies the metadata cell.

    theorem Ram.LanguageCompiler.ArenaRep.stored_address_ne_fresh {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {id : ℕ} {object : Complexity.Language.HeapObject} (found : heap.objects[id]? = some object) {index : ℕ} (bound : index < (heapObjectWords placement object).size) {address : Word w} (fresh : next ≤ BitVec.toNat address) :
    arrayAddr (placement id) index ≠ address

    Fresh arena addresses are disjoint from every old object word.

    theorem Ram.LanguageCompiler.ArenaRep.address_ne_zero {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {τ : Complexity.Language.CellTy} {object : ℕ} {values : Array (Complexity.Language.CellValue τ)} (found : heap.object? τ object = some values) {index : ℕ} (bound : index < values.size) :
    arrayAddr (placement object) index ≠ 0

    Existing object cells never denote the metadata cell.

    theorem Ram.LanguageCompiler.ArenaRep.address_ne_fresh {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {τ : Complexity.Language.CellTy} {object : ℕ} {values : Array (Complexity.Language.CellValue τ)} (found : heap.object? τ object = some values) {index : ℕ} (bound : index < values.size) {address : Word w} (fresh : next ≤ BitVec.toNat address) :
    arrayAddr (placement object) index ≠ address

    Addresses at or above the old cursor cannot alias any old object cell.

    theorem Ram.LanguageCompiler.ArenaRep.of_mem_eq_on {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry finish : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {next' : ℕ} (grows : next ≤ next') (capacity : next' ≤ heapLimit) (cursor : finish.mem 0 = BitVec.ofNat w next') (same : ∀ (address : Word w), 0 < BitVec.toNat address → BitVec.toNat address < next → finish.mem address = entry.mem address) :
    ArenaRep placement next' heapLimit heap finish

    A frame on the positive reserved prefix transports all old objects. The new cursor and its capacity remain explicit and independent of that frame.

    theorem Ram.LanguageCompiler.ArenaRep.reserve {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) {next' : ℕ} (grows : next ≤ next') (capacity : next' ≤ heapLimit) :
    ArenaRep placement next' heapLimit heap (entry.setMem 0 (BitVec.ofNat w next'))

    Updating metadata reserves space but does not pretend to initialize it.

    theorem Ram.LanguageCompiler.ArenaRep.heapRep_setMem_fresh {w next heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {entry : Source.State w} (arena : ArenaRep placement next heapLimit heap entry) (address value : Word w) (fresh : next ≤ BitVec.toNat address) :
    HeapRep placement heapLimit heap (entry.setMem address value)

    An initialization store at a fresh address preserves every old object.