A ret to a caller frame (Block.sound_retWith, Block.sound_back)
Lean: MojoProof/Sym/Path.lean. Test: MojoProofTest/SymPhi.lean, the section "A ret to a caller
frame".
Scope. The results hold for every program P and function fn, and for every path
(l, ds, S) :: ps that coversPathWith contract P fn p0 accepts and whose last block returns
(ret void), for both values of the flag contract (with or without fmul contract; false
for Block.sound_back).
They hold for every context of P and every memory m, and for every thread whose innermost
frame f runs fn at block l's position p0 above any caller frames rest. For
Block.sound_back, the caller frame g is any frame whose block covers accepts from
g.pc + 1.
Why. A kernel's thread has one frame, whose ret step is .done; a callee's ret back into
its caller needs the case of a caller frame too, so item 1 is stated under any caller frames.
Statement
Block.sound_retWith. AssumecoversPathWith contract P fn p0 ((l, ds, S) :: ps) = true,t.frames = f :: rest,f.fn = fn,f.label = l,f.pc = p0,WalkWith contractof the path fromf's entry valuationV, thatV.lastWith contract l S ps = (W, l', S')and thatS'.exit = .ret. Then there arefeandmesuch that:Steps c t m ⟨fe :: rest, t.k + pathLen S ps⟩ me;- the last block's effects give
me(SEff.runatW); step c ⟨fe :: rest, t.k + pathLen S ps⟩ meis.okof the following, whereme'ismewithf'sallocablocks dead:.done me'ifrest = [];.next ⟨{ g.set f.dest none none with pc := g.pc + 1 } :: gs, t.k + pathLen S ps + 1⟩ me'ifrest = g :: gs.
Frame.set_none:g.set r none p = g, sinceret voidsets no register.Block.sound_back. Take item 1's premises atcontract := falsewitht.frames = f :: g :: rest, anddgandSgwithcovers P g.fn g.label (g.pc + 1) dg Sg = true. Suppose that every memorymethe last block's effects make satisfies everyd ∈ dgatWg, which is the entry valuation of{ g with pc := g.pc + 1 }at step countt.k + pathLen S ps + 1onmewithf'sallocablocks dead. Then for some suchme,Ends c t m { g with pc := g.pc + 1 } rest (Wg, g.label, Sg).
Proof
Block.sound_pathWith_ptrsgivesEndsWith contractof the last block, and with it the frame'sallocablocks and caller's register (hal,hde). Theret'sExit.nextisstep's result (hn,hst), and it is the match onrest.- By cases on
r:Frame.setwith no value is the identity. - Item 1 with
rest = g :: rest, simplified by item 2, gives the step to{ g with pc := g.pc + 1 } :: rest.Block.soundon the caller's block, from that thread and at its step count, givesEnds.Ends.preprepends item 1's steps and the return's step.
Dependencies
Block.sound_pathWith_ptrs, Block.sound, Ends.pre, Exit.next, step
(MojoProof/Sem/Thread.lean).
Instances
MojoProofTest/SymPhi.lean, edge_back. This is one program (edgeF), one context (ctxE), one
memory (mem0) and the two frames [frameE true, callerE].
- The callee's path
0 → 1returns tocallerE, which is block 1 ofedgeF, returning to position 1 with%4 = 7. - Block 1 then runs from position 1 to its
ret, whose step is.done. - The caller's conditions
edgeA.oblshold bydecide +kernelafter the return's memory is computed (caseson the effects' run). callerEis written for the test.step'sretsets only the caller's position, not the instruction there, so the theorem covers every caller frame.
Limits
retof a value (ret T %v) is outside the fragment, as before. It would set the caller'sdestregister, for whichFrame.set_nonedoes not apply.- A call into a module function (
exec's.callwith blocks) is not summarized. The caller's block is therefore covered from the position after the call, and the call's entry into the callee is the theorem's premise (t.frames = f :: g :: rest), not a checked step.