Documentation

Complexity.Computability.Ram.Compiler.Local.Exact.Frame

Older saved frames at every compiled execution prefix #

The write-region simulation excludes every address in the interval from the source heap boundary to entry SP. Monotonicity of the actual cumulative write set then preserves those words at every execution prefix. In particular, an older frame retains its return address and all saved locals while an arbitrary nested statement executes, including calls and loops.

The saved frame may have any local count and any base in the protected interval. Its location, contents and return word are fixed at entry; no ownership claim is made about the source heap or the newer stack region.

theorem Ram.LocalCompiler.SimulationWrites.not_mem_heapWrites_of_older {w control locals heapLimit depth steps : ℕ} {code : Code} {localsTable entries : ℕ → ℕ} {stmt : Stmt} {s s' : Source.State w} (simulation : SimulationWrites control locals heapLimit code localsTable entries depth stmt steps s s') (hlocals : locals ≤ control) {start : State w} (matched : Source.State.Matches heapLimit locals s start) (lower : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp control))) (fits : Compiler.StackFits control depth start) (atStmt : CodeAt code start.pc (compileStmt control localsTable entries stmt start.pc)) {address : Word w} (aboveHeap : heapLimit ≤ BitVec.toNat address) (belowStack : BitVec.toNat address < BitVec.toNat (start.regs (ABI.sp control))) :
address ∉ heapWrites code steps start

No actual transition in the entire simulated statement writes an older stack word, even if that transition would store the word's existing value.

theorem Ram.LocalCompiler.SimulationWrites.prefix_mem_eq_of_older {w control locals heapLimit depth steps : ℕ} {code : Code} {localsTable entries : ℕ → ℕ} {stmt : Stmt} {s s' : Source.State w} (simulation : SimulationWrites control locals heapLimit code localsTable entries depth stmt steps s s') (hlocals : locals ≤ control) {start : State w} (matched : Source.State.Matches heapLimit locals s start) (lower : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp control))) (fits : Compiler.StackFits control depth start) (atStmt : CodeAt code start.pc (compileStmt control localsTable entries stmt start.pc)) {k : ℕ} {current : State w} (hk : k ≤ steps) (execution : Exec code k start current) {address : Word w} (aboveHeap : heapLimit ≤ BitVec.toNat address) (belowStack : BitVec.toNat address < BitVec.toNat (start.regs (ABI.sp control))) :
current.mem address = start.mem address

Every real prefix preserves an older word, including both endpoints.

theorem Ram.LocalCompiler.SimulationWrites.frameSlots_disjoint_heapWrites {w control locals heapLimit depth steps : ℕ} {code : Code} {localsTable entries : ℕ → ℕ} {stmt : Stmt} {s s' : Source.State w} (simulation : SimulationWrites control locals heapLimit code localsTable entries depth stmt steps s s') (hlocals : locals ≤ control) {start : State w} (matched : Source.State.Matches heapLimit locals s start) (lower : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp control))) (fits : Compiler.StackFits control depth start) (atStmt : CodeAt code start.pc (compileStmt control localsTable entries stmt start.pc)) {base : Word w} {savedLocals : ℕ} (baseLower : heapLimit ≤ BitVec.toNat base) (frameUpper : BitVec.toNat base + ABI.frameSize savedLocals ≤ BitVec.toNat (start.regs (ABI.sp control))) :
Disjoint (ABI.frameSlots base savedLocals) (heapWrites code steps start)

An older frame's complete concrete slot set is disjoint from all writes of the simulated statement. Its fit follows from its location below entry SP.

theorem Ram.LocalCompiler.SimulationWrites.prefix_frameSlots_mem_eq {w control locals heapLimit depth steps : ℕ} {code : Code} {localsTable entries : ℕ → ℕ} {stmt : Stmt} {s s' : Source.State w} (simulation : SimulationWrites control locals heapLimit code localsTable entries depth stmt steps s s') (hlocals : locals ≤ control) {start : State w} (matched : Source.State.Matches heapLimit locals s start) (lower : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp control))) (fits : Compiler.StackFits control depth start) (atStmt : CodeAt code start.pc (compileStmt control localsTable entries stmt start.pc)) {base : Word w} {savedLocals k : ℕ} {current : State w} (baseLower : heapLimit ≤ BitVec.toNat base) (frameUpper : BitVec.toNat base + ABI.frameSize savedLocals ≤ BitVec.toNat (start.regs (ABI.sp control))) (hk : k ≤ steps) (execution : Exec code k start current) (address : Word w) :
address ∈ ABI.frameSlots base savedLocals → current.mem address = start.mem address

All words of a fixed older frame retain their entry values throughout every actual prefix, without requiring a separately supplied no-wrap premise.

theorem Ram.LocalCompiler.SimulationWrites.prefix_savedFrame {w control locals heapLimit depth steps : ℕ} {code : Code} {localsTable entries : ℕ → ℕ} {stmt : Stmt} {s s' : Source.State w} (simulation : SimulationWrites control locals heapLimit code localsTable entries depth stmt steps s s') (hlocals : locals ≤ control) {start : State w} (matched : Source.State.Matches heapLimit locals s start) (lower : heapLimit ≤ BitVec.toNat (start.regs (ABI.sp control))) (fits : Compiler.StackFits control depth start) (atStmt : CodeAt code start.pc (compileStmt control localsTable entries stmt start.pc)) {base returnWord : Word w} {savedLocals k : ℕ} {savedRegs : Reg → Word w} {current : State w} (baseLower : heapLimit ≤ BitVec.toNat base) (frameUpper : BitVec.toNat base + ABI.frameSize savedLocals ≤ BitVec.toNat (start.regs (ABI.sp control))) (saved : ABI.FrameSaved savedLocals base savedRegs start.mem) (header : start.mem base = returnWord) (hk : k ≤ steps) (execution : Exec code k start current) :
current.mem base = returnWord ∧ ABI.FrameSaved savedLocals base savedRegs current.mem

A previously established saved frame and its return address survive together at every real prefix of a nested statement. The register values are the original saved values, not the nested statement's current registers.