Lectures onType Theory
Finite heaps and local Hoare logic
appendix sectionrules

Finite heaps and local Hoare logic

Fix a countably infinite variable set V; each program and derivation uses only finitely many variables. Stores σ:VVal are total, and all syntax is well scoped over V. Heaps h are finite partial maps from non-null locations to values. Write h1#h2 for disjoint domains and h1h2 for their disjoint union. Assertions are P,Q::=truefalseE=FEFempEFPQPQPQPQx.P. Their load-bearing heap clauses are σ,hemph=,σ,hEFh={v},=[[E]]σ is a non-null location,v=[[F]]σ,σ,hPQh1,h2. h=h1h2σ,h1Pσ,h2Q. Separating implication is the extension condition σ,hPQr.(h#rσ,rP)σ,hrQ. Pure equality and the Boolean connectives have their ordinary clauses, and x.P ranges over values by store update. Separating conjunction has unit emp and is commutative and associative up to mutual entailment. If S is pure, then (PQ)S, (PS)Q, and P(QS) are mutually entailing.

Expressions are variables or literal values. Commands are c::=skipx:=Ex:=[E][E]:=Fx:=alloc(E)free(E)c1;c2if E=F then c1 else c2. The complete big-step semantics is

skip,σ,hσ,h
E-Skip
v=[[E]]σ
x:=E,σ,hσ[xv],h
E-Assign
=[[E]]σh()=v
x:=[E],σ,hσ[xv],h
E-Load
=[[E]]σdom(h)v=[[F]]σ
[E]:=F,σ,hσ,h[v]
E-Store
v=[[E]]σdom(h)null
x:=alloc(E),σ,hσ[x],h{v}
E-Alloc
=[[E]]σdom(h)
free(E),σ,hσ,h(dom(h){})
E-Free
c1,σ,hσ1,h1c2,σ1,h1σ2,h2
c1;c2,σ,hσ2,h2
E-Seq
[[E]]σ=[[F]]σc1,σ,hσ,h
if E=F then c1 else c2,σ,hσ,h
E-IfT
[[E]]σ[[F]]σc2,σ,hσ,h
if E=F then c1 else c2,σ,hσ,h
E-IfF

Safety is structural: skip, assignment, and allocation are safe; load, store, and free require the evaluated address in the heap domain; a sequence requires the first command safe and the second safe after every first result; a conditional requires its selected branch safe. The set mod(c) contains all store variables assigned by c. The set vars(c) contains every variable occurrence in c, including assignment, load, and allocation targets: vars(skip)=,vars(x:=E)={x}fv(E),vars(x:=[E])={x}fv(E),vars(x:=alloc(E))={x}fv(E),vars([E]:=F)=fv(E,F),vars(free(E))=fv(E),vars(c1;c2)=vars(c1)vars(c2),vars(if E=F then c1 else c2)=fv(E,F)vars(c1)vars(c2).

A semantic triple {P}c{Q} requires safety and Q for every result from every state satisfying P. The proof judgment is generated by

{P}skip{P}
H-Skip
{P[E/x]}x:=E{P}
H-Assign
{P}c1{R}{R}c2{Q}
{P}c1;c2{Q}
H-Seq
PP{P}c{Q}QQ
{P}c{Q}
H-Conseq
{P}c{Q}avars(c)fv(Q)
{a.P}c{Q}
H-Exists
xfv(E,F)
{EF}x:=[E]{EFx=F}
H-Load
{E}[E]:=F{EF}
H-Store
xfv(F)
{emp}x:=alloc(F){xF}
H-Alloc
{E}free(E){emp}
H-Free
{PE=F}c1{Q}{PEF}c2{Q}
{P}if E=F then c1 else c2{Q}
H-If
{P}c{Q}mod(c)fv(R)=
{PR}c{QR}
H-Frame

The exact-chain family used by the running program is defined for expressions: chain0(E)=empE=null,chainn+1(E)=a. Eachainn(a), where a is alpha-renamed away from the free variables and surrounding binders at every unfolding.

Assertion substitution is capture avoiding (lemma 44.14), and the fresh-variable coincidence lemma lemma 44.9 is the semantic premise behind H-Exists.

Search the book

Type to search the local edition.