Documentation

Complexity.Computability.Ram.Compiler.Local.Call.Results

Returning multiple fields through a callee-sized frame #

Every return expression is evaluated in the original callee state before the saved caller locals are restored. The resulting words survive frame restoration in the return registers. Empty returns still restore the frame and jump to the saved return address, without evaluating or moving a dummy result.

The complete return executes the emitted prefix and its actual indirect jump; its transition count is the length of that instruction sequence.

theorem Ram.ABI.retreatLocals_resultReg {w : Nat} (control locals : Nat) (s : State w) (i : Nat) :
(execBlock (retreatLocals control locals) s).regs (resultReg control i) = s.regs (resultReg control i)

Retreating the stack pointer preserves every buffered return field.

theorem Ram.ABI.restoreLocals_resultReg {w control locals : Nat} (s : State w) (hlocals : locals ≤ control) (i : Nat) :
(execBlock (restoreLocals control locals) s).regs (resultReg control i) = s.regs (resultReg control i)

Restoring the caller's locals leaves the return-field bank unchanged.

structure Ram.ABI.ReturnResultsRestoredLocals {w : Nat} (control localBound : Nat) (results : List Expr) (sourceCallee : Source.State w) (savedRegs : Reg → Word w) (baseWord returnWord : Word w) (start finish : State w) :

State before the final indirect jump. The return fields contain their callee-local expression values; the caller's saved locals have been restored.

Instances For
    theorem Ram.ABI.returnPrefixResultsLocals_correct {w control locals heapLimit : Nat} {results : List Expr} {sourceCallee : Source.State w} {savedRegs : Reg → Word w} {baseWord returnWord : Word w} {start : State w} (hlocals : locals ≤ control) (hmatch : Source.State.Matches heapLimit locals sourceCallee start) (hfitResults : results.length - 1 ≤ control) (hbounded : ∀ (e : Expr), e ∈ results → e.Bounded locals) (hreads : ∀ (e : Expr), e ∈ results → Expr.ReadsBelow heapLimit sourceCallee.regs sourceCallee.mem e) (hfit : BitVec.toNat baseWord + frameSize locals < 2 ^ w) (hsp : BitVec.toNat (start.regs (sp control)) = BitVec.toNat baseWord + frameSize locals) (hframe : FrameSaved locals baseWord savedRegs start.mem) (hreturn : start.mem baseWord = returnWord) :
    ReturnResultsRestoredLocals control locals results sourceCallee savedRegs baseWord returnWord start (execBlock (returnPrefixResultsLocals control locals results) start)

    Evaluate every return field before restoring the saved locals. User registers outside the callee's frame survive the entire return prefix.

    theorem Ram.ABI.ReturnResultsRestoredLocals.jump_step {w : Nat} {code : Code} {control locals returnPC : Nat} {results : List Expr} {sourceCallee : Source.State w} {savedRegs : Reg → Word w} {baseWord returnWord : Word w} {start finish : State w} (h : ReturnResultsRestoredLocals control locals results sourceCallee savedRegs baseWord returnWord start finish) (hrun : start.status = Status.running) (hfetch : code[finish.pc]? = some (Instr.jumpReg (ra control))) (hreturnPC : BitVec.toNat returnWord = returnPC) :
    step code finish = some (finish.atPC returnPC)

    The restored address controls the same indirect-jump instruction for any return arity, including an empty result list.

    theorem Ram.ABI.returnCodeResultsLocals_exec {w : Nat} {code : Code} {control locals returnPC : Nat} {results : List Expr} {sourceCallee : Source.State w} {savedRegs : Reg → Word w} {baseWord returnWord : Word w} {start : State w} (h : ReturnResultsRestoredLocals control locals results sourceCallee savedRegs baseWord returnWord start (execBlock (returnPrefixResultsLocals control locals results) start)) (hcode : CodeAt code start.pc (returnCodeResultsLocals control locals results)) (hrun : start.status = Status.running) (hreturnPC : BitVec.toNat returnWord = returnPC) :
    Exec code (List.length (returnCodeResultsLocals control locals results)) start ((execBlock (returnPrefixResultsLocals control locals results) start).atPC returnPC)

    Execute the return prefix and its fetched indirect jump, charging exactly the actual emitted code length.