The pointer facts of a block summary (Block.sound_ptrs)
Lean: MojoProof/Sym/Block.lean and MojoProof/Sym/Path.lean (the pointer facts) and
MojoProof/Sym/PtrMem.lean (the memory premises of a path from them). Tests: MojoProofTest/SymRun.lean (vadd21_ptrs,
vadd21_memNext_twin, store_pathMem).
Scope. Every program P, function fn, block lbl, entry position p0, condition list
ds and summary S that covers (or coversWith with an exit function meeting hex, or
coversTo with its edge premise) accepts, every context of P and every thread whose innermost
frame runs fn at block lbl's position p0, with any memory and caller frames, whenever the
conditions of ds hold at the entry valuation. Along a path: every path that
coversPathWith contract accepts, for either value of the flag, with its premises
(WalkWith contract). The memory premises: every labelling, payload set and path that
coversPathWith false and pathOk accept.
What this connects. Labels.MemOk (MojoProof/Sem/Labels.lean, through Labels.MemNext and
Labels.MemAt) constrains, at each statement a running thread reaches, the value of the
statement's pointer operand in the thread's scope, evalV (c.scope m f t.k) (.ptr a) p.
Valuation.LoadsOk and Valuation.StoresOk (MojoProof/Sym/Payload.lean) constrain the summary
term's pointer value p.eval V (vals V ns). SState.run_sound proves that the two agree
(through SState.op_eval) inside its induction. The pointer facts state it, and the theorems of
MojoProof/Sym/PtrMem.lean turn Labels.MemOk into the memory premises Valuation.PathMem of
every path the checkers accept.
Statement
Definitions (PtrIs, StoreVal, StoreAt and StmtPtrs in MojoProof/Sym/Rel.lean, the others in
MojoProof/Sym/Block.lean; Valuation.blocksWith in MojoProof/Sym/Path.lean).
PtrIs ld st s pv:stis aload(ld = true) or astore(ld = false) whose pointer operand(.ptr a) qhasevalV s (.ptr a) q = pv.StoreVal ns regs x w: the termxdescribes the stored operandwwith the node tablensand the register entriesregs. For a registerw = .loc r,x = .reg r(its value at the block's entry) or(r, x) ∈ regs; for a float constant.float lit,xis a node.node jwithns[j]? = some (.flit ft lit); for any other operand,xis an integer constant.int n i.StoreAt fn lbl pc ns regs x: statementpcof blocklbloffnis astorewhose stored operandwhasStoreVal ns regs x w.StmtPtrs V vs lbl pc σ σ' st s: the pointer facts of one statement, which takesσtoσ'. Aloadnode at indexj ≥ σ.nodes.lengthofσ'is atlblandpc, withPtrIs true st s (p.eval V (vals V (σ'.nodes.take j))), its pointer term on the nodes before it (the nodeσ.nodes.length, or the next one after the node of a global theloadreads directly,SNode.globalAt). AstoreeffectSEff.store l pc' v pinσ'.effs.drop σ.effs.lengthis atlblandpc, withPtrIs false st s (p.eval V vs), andstis.store vol (.mk t w) ptr alwithσ.op t w = some v.-
PtrAt c t m rest fn lbl pc ld pv: there aref,k,m',bandstwithSteps c t m ⟨f :: rest, k⟩ m';f.fn = fn,f.label = lblandf.pc = pc;fn.blocks.find? (·.label == lbl) = some bandb.stmts[pc]? = some st;PtrIs ld st (c.scope m' f k) pv.
This is the statement and scope at which
Labels.MemNextappliesLabels.MemAtto the thread⟨f :: rest, k⟩on memorym'. -
Ptrs c t m rest (V, lbl, S)holds when both of these do:- for each
S.nodes[j]? = some (.load l pc p),PtrAt c t m rest V.fn l pc true (p.eval V (vals V (S.nodes.take j))); - for each
SEff.store l pc v p ∈ S.effs,PtrAt c t m rest V.fn l pc false (p.eval V (vals V S.nodes))andStoreAt V.fn l pc S.nodes S.regs v.
These are the terms and values that
LoadsOkandStoresOkread. - for each
-
Valuation.blocksWith contract V l S ps: the blocks of the path, each with its entry valuation (Valuation.intoWith contractof the blocks before it).
Theorems (MojoProof/Sym/Block.lean; 6 in MojoProof/Sym/Path.lean).
SState.stmt_soundalso concludesStmtPtrs V vs lbl fi.pc σ σ' st (V.ctx.scope mi fi k). That scope is the oneexecruns the statement in.-
SState.run_ptrsconcludesSState.run_sound's conclusion together with two pointer facts:PtrAt V.ctx ⟨fi :: rest, kk⟩ mi rest V.fn l pc true (p.eval V (vals V (σf.nodes.take j)))for eachloadnodej ≥ σ.nodes.lengthofσf;PtrAt … false (p.eval V vs)andStoreAt V.fn l pc σf.nodes σf.regs vfor eachstoreeffectSEff.store l pc v pthat the run appends.
SState.run_soundis its first component. -
SState.stmt_monoandSState.run_mono: a statement in the fragment, and a run of statements, keep the obligations, extend the effects and the table, and put entries in front of the register entries (σf.regs = rs ++ σ.regsfor somers). Block.sound_withAtwithoutallocaandfmul contract(EndsAt.ends; withfmul contract,EndsWith truein place ofEnds; docs/proofs/contract.md) andBlock.sound_toconcludeEnds c t m f rest (Valuation.entry c t.k m f, lbl, S) ∧ Ptrs c t m rest (Valuation.entry c t.k m f, lbl, S).Block.sound_ptrshasBlock.sound's premises and the conclusionEnds … ∧ Ptrs ….Block.soundis its first component.Block.sound_pathWith_ptrs, for a path thatcoversPathWith contractaccepts with its premisesWalkWith contract, concludesEndsWith contract c t m f rest ((Valuation.entry c t.k m f).lastWith contract l S ps) ∧ ∀ q ∈ (Valuation.entry c t.k m f).blocksWith contract l S ps, Ptrs c t m rest q.
Theorems (MojoProof/Sym/PtrMem.lean). In all of them, lab is a labelling, pay a set of
payload blocks, c a context, t a thread, m a memory and rest a list of frames, and
hM : ∀ t' m', Steps c t m t' m' → lab.MemNext pay c m' t' says that every state the thread's
steps reach meets Labels.MemNext.
StoreVal.mentions. For every labelling, function, node tablens, register entriesregs, termxand operandwwithStoreVal ns regs x w, withpsthe roles ofns(roles lab fn ns): ifx.pay lab fn ps = trueand every entry(r, y) ∈ regswithy.pay lab fn ps = truehaslab.reg fn.name r = true, thenw.mentions (lab.reg fn.name) = true(a float constant's node is never payload).-
Ptrs.loadsOk. For every valuationV, labellbland summaryS:theorem Ptrs.loadsOk (hQ : Ptrs c t m rest (V, lbl, S)) (hM : ∀ t' m', Steps c t m t' m' → lab.MemNext pay c m' t') : V.LoadsOk lab pay S.nodes -
Ptrs.storesOk. For every valuationV, labellbland summarySwhose register entries agree withlab(Summary.agrees):theorem Ptrs.storesOk (hQ : Ptrs c t m rest (V, lbl, S)) (ha : S.agrees lab V.fn = true) (hM : ∀ t' m', Steps c t m t' m' → lab.MemNext pay c m' t') : V.StoresOk lab pay S -
Valuation.pathMem_of_ptrs. For every path(l, S) :: psand valuationV: ifpathOk lab V.fn l S ps = trueandPtrs c t m rest qfor everyq ∈ V.blocksWith false l S ps, thenV.PathMem lab pay l S ps(Valuation.LoadsOkandValuation.StoresOkat each block's entry valuation). Block.sound_pathMem. For every programP, functionfn, path(l, ds, S) :: pswithcoversPathWith false P fn p0 ((l, ds, S) :: ps) = trueandpathOk lab fn l S ps = true, every contextcwithc.prog = P, and every threadtwhose innermost framef(aboverest) runsfnat blockl's positionp0, on memorym, withWalkWith false (Valuation.entry c t.k m f) ((l, ds, S) :: ps):hMgives(Valuation.entry c t.k m f).PathMem lab pay l S ps. That is the premisehmofBlock.sound_ret_rel.Labels.MemOk.steps. For every launchL, contextsc, gridsg₀andgwithlab.MemOk pay L c g₀andgreachable fromg₀(Relation.ReflTransGen (Grid.Step L c)), every running threadg.threads[n]? = some (.run t)and everySteps (c n) t g.mem t' m':lab.MemNext pay (c n) m' t'. SohMholds for every running thread of every grid a launch reaches, andBlock.sound_pathMemapplies to it.
Proof
- In the
loadcase, the new node is.load lbl pc xwithx ← σ.op (.ptr as) p. Its index isσ.nodes.length(getElem?_snoc_ge).SState.op_evalgivesx.eval V (vals V σ.nodes) = evalV s (.ptr as) p, which is the value the proof already used. In thestorecase, the only new effect is.store lbl pc x y, withx ← σ.op t wfor the stored operand. Its pointer termyhas the sameSState.op_evalfact onvs, and a store appends no node. The other statements append a node that is not aloadand no effect (SState.def_ptrs, by itsautoParam). - The proof is by induction on the statement list, as for
SState.run_sound.- A
loadnode ofσfpastσ''s table comes from the induction hypothesis, moved back one step byPtrAt.pre. One inσ'comes from item 1 at the thread itself (Steps.refl). For it,σf.nodes.take jisσ.nodes, becauseσf's table extendsσ''s, which isσ.nodes ++ [nd]. - A
storeeffect is either in the statement's own effects (item 1) or in the rest of the run (the induction hypothesis andPtrAt.pre). For its own,σ.op t w = some vgivesStoreVal (σ.nodes ++ ns) (rs ++ σ.regs) v wfor everynsandrs(SState.op_storeVal), andσf's table isσ.nodeswith nodes after it and its register entries areσ.regswith entries in front (item 3).
- A
- Case analysis of
SState.stmt(SState.def_regsfor the statements that set a register), then induction on the statement list. - and 5. Apply
SState.run_ptrsfromSState.init, whose table and effects are empty. - The head block's pointer facts come from
Block.sound_atWithorBlock.sound_toWith. Each later block's facts come from the recursive call at the thread after the edge, moved back byPtrs.prealongSteps.trans_step hS₁ hst₁ (.refl _ _). - A register operand is
xitself, whose payload role is the hypothesis, or an entry ofregsset tox, which the entries hypothesis covers; a constant term has no payload role. PtrAtgives the thread's state⟨f :: rest, k⟩, memorym', blockband statementst, which meethM's premises.resReg V.fn l pcisst.res(fromhbandhst), soMemAt'sloadclause applies to the pointer value thatPtrIsequates with the term's.- As 9, with
MemAt'sstoreclause. Its premise, that the stored operand mentions a payload register, isStoreVal.mentionswithStoreAt'sStoreVal, the effect's payload term, andSummary.agrees, which says that each register entry ofSwith a payload term is of a payload register. - Induction on the path.
pathOkgivesSummary.agreesI, whose first part isSummary.agrees, at each block; items 9 and 10 apply at each block ofValuation.blocksWith false. The next block's entry valuation keeps the function (Valuation.into_k). Block.sound_pathWith_ptrsgives the pointer facts of every block of the path; then item 11.Steps.grid(MojoProof/Sym/Sched.lean) turns the thread's steps into grid steps fromg, to the grid with the reached state at indexn. That grid is reachable fromg₀, soLabels.MemOkgivesLabels.MemAllthere, at indexn.
Dependencies
SState.op_eval, SState.op_storeVal, SState.def_regs, SState.run_mono, SState.stmt_mono,
step_stmt, Steps.trans and Steps.trans_step, Ends.edgeWith; Labels.MemNext,
Labels.MemAt and Labels.MemOk (MojoProof/Sem/Labels.lean); Valuation.LoadsOk,
Valuation.StoresOk, Valuation.PathMem, Summary.agrees, pathOk and resReg
(MojoProof/Sym/Payload.lean); Steps.grid (MojoProof/Sym/Sched.lean).
Instances
With vector_addition's block %21 (Kernels.vadd.b1), the context ctx0, the memory mem0
and the frames frame0 i 3:
vadd21_qisBlock.sound_ptrsitself.vadd21_ptrsholds for everyi < 4. The thread's steps reach eachloadnode's statement, whose pointer operand evaluates to celliof block 1 or 2 (the inputs). They also reach thestore's statement, whose pointer is celliof block 3 (the output). The term values come fromvadd21_ptrval(decide +kernel, throughcellIs).- The negative twin is
vadd21_memNext_twin. UnderlabNone(no payload register) with block 1 payload,Ptrs.loadsOkandvadd21_load1show that for everyi < 4some state of threadi's run failsLabels.MemNext.
With the block of kernel #[store01] (MojoProofTest/Labels.lean), which stores register 0
through the pointer in register 1 and returns (summary st01):
store_pathMemholds for every launchL. Underlab0(register 0 payload) with block 1 payload,storeGridmeetsLabels.MemOk(store_ok), soLabels.MemOk.stepsandBlock.sound_pathMemgiveValuation.PathMemof the one-block path at its thread's entry valuation: itsstoreof the payload term.reg 0writes into block 1. The twin: with no payload block,Valuation.PathMemfails.
These instances cover two blocks of two programs. The theorems in items 1 to 13 cover every program, labelling and block or path the checkers accept.
Limits
atomicrmwis outside the fragment, so it has no pointer facts.Labels.MemAtconstrains it, andValuation.StoresOkdoes not read it.Block.sound_pathMemneedspathOkof the path's summaries; a path whose register entries do not agree with the labelling gets noStoresOk.