Documentation

CslibFrontier.Computability.PointerMachine.Basic

Pointer-machine invariants #

Validity, pointer provenance, allocation freshness, determinism and the space bound. The model itself is defined in Defs.

Main results #

No records, null pointer registers and undefined data registers.

The empty state is valid.

theorem Cslib.PointerMachine.State.deref_eq_some {M : Model} {L : Layout} {x : State M L} {r : Fin L.ptrRegs} {n : Record M L} :
x.deref r = some n ↔ ∃ (a : ℕ), x.ptr r = some a ∧ x.heap[a]? = some n

A register specifies a record exactly when it holds the position of that record.

theorem Cslib.PointerMachine.State.mem_heap_modify {M : Model} {L : Layout} {x : State M L} {r : Fin L.ptrRegs} {g : Record M L → Record M L} {n : Record M L} (h : n ∈ (x.modify r g).heap) :
n ∈ x.heap ∨ ∃ m ∈ x.heap, n = g m

A record of a modified heap is an old record or the image of one.

@[simp]
theorem Cslib.PointerMachine.State.length_heap_modify {M : Model} {L : Layout} {x : State M L} {r : Fin L.ptrRegs} {g : Record M L → Record M L} :

Modifying a record keeps the number of records.

@[simp]
theorem Cslib.PointerMachine.State.ptr_modify {M : Model} {L : Layout} {x : State M L} {r : Fin L.ptrRegs} {g : Record M L → Record M L} :
(x.modify r g).ptr = x.ptr

Modifying a record keeps the pointer registers.

@[simp]
theorem Cslib.PointerMachine.State.data_modify {M : Model} {L : Layout} {x : State M L} {r : Fin L.ptrRegs} {g : Record M L → Record M L} :
(x.modify r g).data = x.data

Modifying a record keeps the data registers.

theorem Cslib.PointerMachine.Instr.effect_valid {M : Model} {L : Layout} {i : Instr M L} {x : State M L} (hx : x.Valid) :

Instructions preserve validity.

An instruction creates at most one record and removes none.

theorem Cslib.PointerMachine.Instr.effect_provenance {M : Model} {L : Layout} {i : Instr M L} {x : State M L} {r : Fin L.ptrRegs} {a : ℕ} (ha : (effect x i).ptr r = some a) :
(∃ (r' : Fin L.ptrRegs), x.ptr r' = some a) ∨ (∃ (base : Fin L.ptrRegs) (n : Record M L) (f : Fin L.ptrFields), x.deref base = some n ∧ n.ptr f = some a) ∨ a = x.heap.length ∧ (effect x i).heap.length = x.heap.length + 1

A pointer in a register after an instruction was in a register before it, or in a field of a record specified by a register, or specifies the record just created.

theorem Cslib.PointerMachine.Instr.effect_heap_provenance {M : Model} {L : Layout} {i : Instr M L} {x : State M L} {n : Record M L} (hn : n ∈ (effect x i).heap) {f : Fin L.ptrFields} {a : ℕ} (ha : n.ptr f = some a) :
(∃ (r : Fin L.ptrRegs), x.ptr r = some a) ∨ ∃ m ∈ x.heap, ∃ (g : Fin L.ptrFields), m.ptr g = some a

Every nonnull pointer stored in a record after an instruction was previously in a register or a record. Allocation itself only puts null pointers in the new record.

theorem Cslib.PointerMachine.Instr.create_fresh {M : Model} {L : Layout} {x : State M L} (hx : x.Valid) {r : Fin L.ptrRegs} :
(effect x (create r)).ptr r = some x.heap.length ∧ (∀ (r' : Fin L.ptrRegs), x.ptr r' ≠ some x.heap.length) ∧ ∀ n ∈ x.heap, ∀ (f : Fin L.ptrFields), n.ptr f ≠ some x.heap.length

In a valid state, create returns a pointer that no register or record held.

theorem Cslib.PointerMachine.step_eq_some_iff {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} :
step code x = some y ↔ ∃ (i : Instr M L), code[x.pc]? = some i ∧ i ≠ Instr.halt ∧ y = have __src := Instr.effect x i; { pc := Instr.next x i, ptr := __src.ptr, data := __src.data, heap := __src.heap }

A step executes the current instruction, which is not a halt.

theorem Cslib.PointerMachine.step_valid {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} (hx : x.Valid) (h : step code x = some y) :

Program steps preserve validity.

theorem Cslib.PointerMachine.step_length {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} (h : step code x = some y) :

A program step creates at most one record and removes none.

theorem Cslib.PointerMachine.Runs.valid {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} {n : ℕ} (h : Runs code x y n) (hx : x.Valid) :

Every state of a run from a valid state is valid.

theorem Cslib.PointerMachine.Runs.length_le {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} {n : ℕ} (h : Runs code x y n) :

Space is at most the initial number of records plus the number of instructions executed.

theorem Cslib.PointerMachine.step_deterministic {M : Model} {L : Layout} {code : List (Instr M L)} {x y z : State M L} (hy : step code x = some y) (hz : step code x = some z) :
y = z

Execution is deterministic.

theorem Cslib.PointerMachine.Executes.valid {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} {time : ℕ} (h : Executes code x y time) (hx : x.Valid) :

Successful execution preserves validity.

theorem Cslib.PointerMachine.Executes.length_le {M : Model} {L : Layout} {code : List (Instr M L)} {x y : State M L} {time : ℕ} (h : Executes code x y time) :
y.heap.length ≤ x.heap.length + (time - 1)

Space is bounded by the initial heap plus nonhalting instructions.

theorem Cslib.PointerMachine.Runs.deterministic {M : Model} {L : Layout} {code : List (Instr M L)} {x y z : State M L} {n : ℕ} (h : Runs code x y n) (h' : Runs code x z n) :
y = z

Runs with the same initial state and number of steps have the same final state.

theorem Cslib.PointerMachine.Executes.unique {M : Model} {L : Layout} {code : List (Instr M L)} {x y z : State M L} {t u : ℕ} (h : Executes code x y t) (h' : Executes code x z u) :
y = z ∧ t = u

Successful execution determines both the final state and the instruction count.