Documentation

Complexity.Computability.Ram.Compiler.Language.Heap

Representing shared source objects in RAM memory #

One fixed mathematical placement gives each source object a RAM base address. The complete current object is represented at that address: arrays contain their scalar cells, while immutable nodes contain a head, an option tag and the actual placement of their tail. Borrowed array views derive their base and length without copying contents or storing an object table. Views of the same object may overlap or coincide. Distinct objects have disjoint actual cells, with no condition on empty objects' unused addresses.

Natural cells must fit the target word and Boolean cells use their exact zero-or-one encoding. Object intervals retain the existing non-strict endpoint bound. A view's length needs its own word-range premise only when exposed as a two-word ArrayRef. No injectivity of source handle encoding is asserted.

The read and write theorems relate the existing source heap operations to the existing RAM memory update. They do not add an evaluator, allocation, a loader, statement syntax, instruction prices or a complete buffer-lowering theorem.

Exact mathematical scalar observation of a source object cell.

Equations
Instances For

    One actual word for a source cell; exactness is a separate range fact.

    Equations
    Instances For

      Encode the existing native array elementwise, without loading any memory.

      Equations
      Instances For

        Complete storage of either object kind. The optional link contains an actual address, not a numeric source identifier; none uses a separate zero tag.

        Equations
        Instances For

          Exact scalar payloads and node tags. Link addresses already have type Word.

          Equations
          Instances For
            theorem Ram.LanguageCompiler.heapObjectWords_size_eq {w : ℕ} (left right : ℕ → Word w) (object : Complexity.Language.HeapObject) :
            (heapObjectWords left object).size = (heapObjectWords right object).size

            Storage extent depends on the object, not its placement or referenced addresses.

            Two-word metadata for a view of a placed object. This is not a runtime conversion and does not recover the source object's identity from the fields.

            Equations
            Instances For

              A fitting cell is observed as its exact mathematical value, not a residue.

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

              Complete typed objects, their scalar ranges and separation of actual cells. The placement is fixed across heap updates and real function calls.

              Instances For
                theorem Ram.LanguageCompiler.HeapRep.objects {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {object : ℕ} {values : Array (Complexity.Language.CellValue τ)} (found : heap.object? τ object = some values) :
                Source.ArrayAt heapLimit (placement object) (objectWords w values).toList target

                Typed array observation is a projection of complete object representation.

                theorem Ram.LanguageCompiler.HeapRep.ranges {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {object : ℕ} {values : Array (Complexity.Language.CellValue τ)} (found : heap.object? τ object = some values) (index : ℕ) (bound : index < values.size) :
                cellToNat values[index] < 2 ^ w

                Every represented array cell retains the original exact scalar range interface.

                theorem Ram.LanguageCompiler.HeapRep.separated {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ σ : Complexity.Language.CellTy} {object other : ℕ} {values : Array (Complexity.Language.CellValue τ)} {otherValues : Array (Complexity.Language.CellValue σ)} (found : heap.object? τ object = some values) (otherFound : heap.object? σ other = some otherValues) (different : object ≠ other) (index : ℕ) (bound : index < values.size) (otherIndex : ℕ) (otherBound : otherIndex < otherValues.size) :
                arrayAddr (placement object) index ≠ arrayAddr (placement other) otherIndex

                The original array separation interface follows from separation of all objects.

                theorem Ram.LanguageCompiler.HeapRep.nodes {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {object : ℕ} {head : Complexity.Language.CellValue τ} {tail : Option (Complexity.Language.NodeRef τ)} (found : heap.node? τ object = some (head, tail)) :
                Source.ArrayAt heapLimit (placement object) (heapObjectWords placement (Complexity.Language.HeapObject.node τ head tail)).toList target

                A node lookup exposes all three real words, including its placed optional tail.

                theorem Ram.LanguageCompiler.HeapRep.tail_lt_size {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {object : ℕ} {head : Complexity.Language.CellValue τ} {tail : Complexity.Language.NodeRef τ} (found : heap.node? τ object = some (head, some tail)) :
                tail.object < heap.objects.size

                A stored backward link always names an existing object, without requiring the numeric source identifier to fit a RAM word.

                theorem Ram.LanguageCompiler.HeapRep.empty {w : ℕ} (placement : ℕ → Word w) (heapLimit : ℕ) (target : Source.State w) :
                HeapRep placement heapLimit { objects := #[] } target

                The empty source heap imposes no restriction on placement, capacity or RAM memory.

                theorem Ram.LanguageCompiler.HeapRep.enter {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) (args : List (Word w)) :
                HeapRep placement heapLimit heap (target.enter args)

                Parameter binding retains the same complete shared-heap representation.

                theorem Ram.LanguageCompiler.HeapRep.setRegs {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) (dsts : List Reg) (values : List (Word w)) :
                HeapRep placement heapLimit heap (target.setRegs dsts values)

                Receiving actual return fields changes no represented heap cell.

                theorem Ram.LanguageCompiler.HeapRep.setReg {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) (dst : Reg) (value : Word w) :
                HeapRep placement heapLimit heap (target.setReg dst value)

                Updating one local register changes no represented shared object.

                theorem Ram.LanguageCompiler.HeapRep.restore {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) (caller : Source.State w) :
                HeapRep placement heapLimit heap (caller.restore target)

                Caller restoration keeps the callee's final heap, not the caller's old heap.

                theorem Ram.LanguageCompiler.HeapRep.view_arrayAt {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {buffer : Complexity.Language.Buffer τ} {contents : Array (Complexity.Language.CellValue τ)} (observed : buffer.Contents heap contents) :
                Source.ArrayAt heapLimit (bufferRef placement buffer).base (objectWords w contents).toList target

                A view's current native contents use the existing contiguous-array assertion. Even an empty view at the allocation endpoint is admitted.

                theorem Ram.LanguageCompiler.HeapRep.view {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {buffer : Complexity.Language.Buffer τ} {contents : Array (Complexity.Language.CellValue τ)} (observed : buffer.Contents heap contents) (lengthFits : buffer.length < 2 ^ w) :
                (bufferRef placement buffer).Rep heapLimit (objectWords w contents).toList target

                A word-sized view is exactly the existing by-value ArrayRef together with its actual native contents. The descriptor allocates and copies nothing.

                theorem Ram.LanguageCompiler.HeapRep.read {w heapLimit : ℕ} {placement : ℕ → Word w} {heap : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {buffer : Complexity.Language.Buffer τ} {index : ℕ} {value : Complexity.Language.CellValue τ} (read : heap.read buffer index = Except.ok value) :
                target.mem (arrayAddr (bufferRef placement buffer).base index) = cellWord w value ∧ BitVec.toNat (arrayAddr (bufferRef placement buffer).base index) < heapLimit ∧ cellToNat value < 2 ^ w

                Every successful source read is the exact represented RAM cell, lies below the heap boundary and returns a source scalar fitting the target word.

                theorem Ram.LanguageCompiler.HeapRep.write {w heapLimit : ℕ} {placement : ℕ → Word w} {heap finish : Complexity.Language.Heap} {target : Source.State w} (represented : HeapRep placement heapLimit heap target) {τ : Complexity.Language.CellTy} {buffer : Complexity.Language.Buffer τ} {index : ℕ} {value : Complexity.Language.CellValue τ} (written : heap.write buffer index value = Except.ok finish) (valueFits : cellToNat value < 2 ^ w) :
                HeapRep placement heapLimit finish (target.setMem (arrayAddr (bufferRef placement buffer).base index) (cellWord w value))

                A successful source write is represented by the same single RAM memory update. Complete objects, scalar ranges and separation all survive; aliases are not assumed disjoint, and other objects retain their actual contents.