Developing programs by Splitting atoms (rely/guarantee conditions, - - PowerPoint PPT Presentation

developing programs by splitting atoms rely guarantee
SMART_READER_LITE
LIVE PREVIEW

Developing programs by Splitting atoms (rely/guarantee conditions, - - PowerPoint PPT Presentation

Developing programs by Splitting atoms (rely/guarantee conditions, data reification, . . . ) Cliff B Jones Computing Science Newcastle University FMCO 2008-10-22 Cliff B Jones (Newcastle) Developing programs by Splitting atoms


slide-1
SLIDE 1

Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . )

Cliff B Jones

Computing Science Newcastle University

FMCO 2008-10-22

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 1 / 36

slide-2
SLIDE 2

Contents

1

Design as abstraction layers

2

ACMs Where to start – a specification Splitting atoms (gently) in abstract state Retaining less history The four-slot representation

3

Conclusions

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 2 / 36

slide-3
SLIDE 3

Key abstractions

Pre/post-conditions (as in VDM/B/. . . )

◮ design by sequential“operation decomposition rules” ◮ Floyd/Hoare-like rules (coping with relational post-conditions)

Rely/Guarantee “thinking”

◮ not (just) a specific set of rules ◮ show importance of “frames” (cf. Separation Logic) ◮ using “auxiliary variables”

Abstract objects

◮ choice of abstract data objects key for specifications ◮ data “reification” (classic-VDM / Nipkow’s rule) ◮ link with R/G development

“fiction of atomicity”

◮ “splitting (software) atoms safely” [Jon07] ◮ cf. database transactions [JLRW05], . . . Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 3 / 36

slide-4
SLIDE 4

While (operation decomposition) rule

While-I S sat (P ∧ b, P ∧ W) P ⇒ δl(b) mk-While(b, S) sat (P, P ∧ ¬ b ∧ W ∗)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 4 / 36

slide-5
SLIDE 5

An R/G picture

P

Program Environment

Q

G R R R R G G

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 5 / 36

slide-6
SLIDE 6

One R/G rule

  • cf. [CJ07]

Par-I {P, R ∨ Gr} ⊢ sl sat (Gl, Ql) {P, R ∨ Gl} ⊢ sr sat (Gr, Qr) Gl ∨ Gr ⇒ G ↼ − P ∧ Ql ∧ Qr ∧ (R ∨ Gl ∨ Gr)∗ ⇒ Q {P, R} ⊢ mk-Par(sl, sr) sat (G, Q)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 6 / 36

slide-7
SLIDE 7

Subtle link between R/G and data reification

  • cf. [Jon07]

in FINDP

◮ we have t ← min(t, local) in n parallel processes ◮ assuming we don’t want to “lock” t ◮ need a representation that helps us to preserve R/G conditions ◮ (simple to) represent as t as min(et, ot)

SIEVE

◮ we have to remove an element from a set s ◮ assuming we don’t want to “lock” s (big!) ◮ need a representation that helps preserve R/G conditions s ⊆ ↼

− s

◮ (less obvious) represent s as a bit vector

Simpson

◮ extremely interesting ◮ my claim: this is the essence of Simpson’s contribution Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 7 / 36

slide-8
SLIDE 8

Contents

1

Design as abstraction layers

2

ACMs Where to start – a specification Splitting atoms (gently) in abstract state Retaining less history The four-slot representation

3

Conclusions

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 8 / 36

slide-9
SLIDE 9

ACMs: topic of [JP08]

Communication (Atomic?) Write(42)
 x
:=
Read()


Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 9 / 36

slide-10
SLIDE 10

ACMs

Atomic and (trying for) Asynchronous Write
 Read()


Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 10 / 36

slide-11
SLIDE 11

Simpson’s algorithm

Simpson’s algorithm

◮ ingenious algorithm ◮ difficult to prove correct ◮ actually, all proofs make assumptions ◮ different verification methods give different insights ◮ but, even then, lack of explanation

several other folk still working on this

◮ come back to at end

run through our “rational reconstruction”

◮ “explanation” via layers of abstraction

essential to get the big steps right before detailed proof apologies for so much argument about eight lines of code . . .

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 11 / 36

slide-12
SLIDE 12

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 12 / 36

slide-13
SLIDE 13

Specification

Σa :: data-w: Value∗ fresh-w: N hold-r: N inv (mk-Σa(data-w, fresh-w, hold-r)) △ fresh-w, hold-r ∈ {1..len data-w} ∧ hold-r ≤ fresh-w σa

0 = mk-Σa([x], 1, 1)

while true do start-Write(v: Value): data-w ← data-w [v]; commit-Write(): fresh-w ← len data-w

  • d

while true do start-Read(): hold-r ← fresh-w; end-Read()r: Value: r ← data-w(i) for some i ∈ {hold-r..fresh-w}

  • d

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 13 / 36

slide-14
SLIDE 14

Examples 1, 2

start-Write(y) .. mk-Σa([x, y], 1, 1) commit-Write() .. mk-Σa([x, y], 2, 1) start-Read() .. mk-Σa([x, y], 2, 2) end-Read() .. r = y start-Write(y) .. mk-Σa([x, y], 1, 1) start-Read() .. mk-Σa([x, y], 1, 1) end-Read() .. r = x commit-Write() .. mk-Σa([x, y], 2, 1)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 14 / 36

slide-15
SLIDE 15

Example 3

start-Read() .. mk-Σa([x], 1, 1) start-Write(y) .. mk-Σa([x, y], 1, 1) commit-Write() .. mk-Σa([x, y], 2, 1) start-Write(z) .. mk-Σa([x, y, z], 2, 1) commit-Write() .. mk-Σa([x, y, z], 3, 1) end-Read() .. r ∈ {x, y, z} start-Read() .. mk-Σa([x, y, z], 3, 3) end-Read() .. r = z

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 15 / 36

slide-16
SLIDE 16

Specification in terms of four sub-operations (Write)

Atomic operations — therefore pure pre/post specification

while true do start-Write(v: Value): data-w ← data-w [v]; commit-Write(): fresh-w ← len data-w

  • d

|| . . . Write(v: Value) start-Write(v: Value) wr data-w post data-w = ↼ − − − − data-w [v] commit-Write(v: Value) rd data-w wr fresh-w pre data-w(len data-w) = v post fresh-w = len data-w Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 16 / 36

slide-17
SLIDE 17

Specification in terms of four sub-operations (Read)

. . . || while true do start-Read(): hold-r ← fresh-w; end-Read()r: Value: r ← data-w(i) for some i ∈ {hold-r..fresh-w}

  • d

Read()r: Value local hold-r: N start-Read() wr hold-r rd fresh-w post hold-r = fresh-w end-Read()r: Value rd data-w, fresh-w post ∃i ∈ {hold-r..fresh-w} · r = data-w(i) Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 17 / 36

slide-18
SLIDE 18

General messages

note “algorithmic” specification “fiction of atomicity”

◮ but single “atomic” variable does not cover all behaviour

“frames” (for rd/wr access)

◮ plus “local”

data abstraction

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 18 / 36

slide-19
SLIDE 19

Splitting atoms in Σa (Write)

Accept overlap (only read/write) — therefore rely/guarantee

Write(v: Value) start-Write(v: Value) rd fresh-w wr data-w rely fresh-w = ↼ − − − − fresh-w ∧ data-w = ↼ − − − − data-w guar {1..fresh-w} ✁ data-w = {1..fresh-w} ✁ ↼ − − − − data-w post data-w = ↼ − − − − data-w [v] commit-Write(v: Value) rd data-w wr fresh-w pre data-w(len data-w) = v rely fresh-w = ↼ − − − − fresh-w ∧ data-w = ↼ − − − − data-w post fresh-w = len data-w

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 19 / 36

slide-20
SLIDE 20

Splitting atoms in Σa (Read)

Read()r: Value start-Read() rd fresh-w wr hold-r rely hold-r = ↼ − − − hold-r post hold-r ∈ {↼ − − − − fresh-w, fresh-w} end-Read()r: Value rd data-w, fresh-w, hold-r rely hold-r = ↼ − − − hold-r∧∀i ∈ {hold-r..↼ − − − − fresh-w}·data-w(i) = ↼ − − − − data-w(i) post ∃i ∈ {hold-r..↼ − − − − fresh-w} · r = ↼ − − − − data-w(i)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 20 / 36

slide-21
SLIDE 21

General messages

phasing

◮ makes clear start-Write cannot interfere with commit-Write ◮ avoids implications in rely conditions

frames plus phasing significantly simplify R/G assertions

  • cf. rely-start-Write on Σa above

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 21 / 36

slide-22
SLIDE 22

Retaining less history

A data reification exercise — still very general

Σi :: data-w: X

m

− → Value fresh-w: X hold-r: X hold-w: X inv (mk-Σi(data, fresh, hold-r, hold-w)) △ {fresh, hold-r, hold-w} ⊆ dom data σi

0 = mk-Σi({α → x}, α, α, α)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 22 / 36

slide-23
SLIDE 23

Relating Σi to Σa

Using Nipkow’s rule

r(σa

1 , σi 1) ∧ posti(σi 1, σi 2) ⇒ ∃σa 2 ∈ Σa · posta(σa 1 , σa 2 ) ∧ r(σa 2 , σi 2)

r : Σa × Σi → B r(mk-Σa(data-wa, fresh-wa, hold-ra), mk-Σi(data-wi, fresh-wi, hold-ri, hold-wi))

rng data-wi ⊆ elems data-wa ∧ data-wa(fresh-wa) = data-wi(fresh-wi) ∧ data-wa(hold-ra) = data-wi(hold-ri)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 23 / 36

slide-24
SLIDE 24

Specifications of the sub-operations on Σi

Still overlapped — still rely/guarantee

Write(v: Value) local hold-w: X start-Write(v: Value) rd hold-r, fresh-w wr data-w, hold-w rely fresh-w = ↼ − − − − fresh-w ∧ data-w = ↼ − − − − data-w guar {↼ − − − hold-r, hold-r} ✁ data-w = {↼ − − − hold-r, hold-r} ✁ ↼ − − − − data-w post hold-w ∈ (X − {fresh-w, ↼ − − − hold-r, hold-r}) ∧ data-w = ↼ − − − − data-w † {hold-w → v} end-Write(v: Value) rd data-w, hold-w wr fresh-w pre data-w(hold-w) = v rely fresh-w = ↼ − − − − fresh-w ∧ data-w = ↼ − − − − data-w post fresh-w = hold-w Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 24 / 36

slide-25
SLIDE 25

Specifications of the sub-operations on Σi

Read()r: Value start-Read() rd fresh-w wr hold-r rely hold-r = ↼ − − − hold-r post hold-r ∈ {↼ − − − − fresh-w, fresh-w} end-Read()r: Value rd hold-r, data-w rely hold-r = ↼ − − − hold-r ∧ data-w(hold-r) = ↼ − − − − data-w(hold-r) post r = data-w(hold-r) Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 25 / 36

slide-26
SLIDE 26

General messages

simpler R/G because of read/write frames data reification

◮ (potentially) reducing non-determinism ◮ use of VDM’s other reification rule

still have “bold” atomicity assumptions

◮ couldn’t update data-w atomically on any reasonable machine

still work to be done role of data reification in achieving rely conditions Simpson’s representation crucial

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 26 / 36

slide-27
SLIDE 27

The four-slot representation

Focus on Simpson’s inspiration

Σr :: data-w: P × S

m

− → Value pair-w: P pair-r: P slot-w: P

m

− → S wp-w: P ws-w: S rs-r: S where (key assumptions about granularity (ρ)): P, S = Token-set P = S card P = 2 ρ(i) = i

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 27 / 36

slide-28
SLIDE 28

Connection Σr with Σi

Σi represented in Σr by data-wi data-wr fresh-wi (pair-wr, slot-wr(pair-wr)) hold-ri (pair-rr, slot-wr(pair-rr)) hold-wi (wp-wr, wp-sr)

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 28 / 36

slide-29
SLIDE 29

Specifications of the sub-operations on Σr

Write(v: Value) local wp-w: P local ws-w: S start-Write(v: Value) rd pair-r, slot-w wr data-w rely slot-w = ↼ − − − slot-w ∧ data-w = ↼ − − − − data-w guar {(↼ − − − pair-r, slot-w(↼ − − − pair-r)), (pair-r, slot-w(pair-r))} ✁ data-w = {(↼ − − − pair-r, slot-w(↼ − − − pair-r)), (pair-r, slot-w(pair-r))} ✁ ↼ − − − − data-w post wp-w = ρ(↼ − − − pair-r) ∧ ws-w = ρ(slot-w(wp-w)) ∧ data-w(wp-w, ws-w) = v end-Write() wr pair-w, slot-w rely pair-w = ↼ − − − − pair-w ∧ slot-w = ↼ − − − slot-w guar slot-w(pair-r) = ↼ − − − slot-w(pair-r) post slot-w(wp-w) = ws-w ∧ pair-w = wp-w Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 29 / 36

slide-30
SLIDE 30

Specifications of the sub-operations on Σr

Read()r: Value local rs-r: S start-Read() rd pair-w, slot-w wr pair-r rely slot-w(pair-r) = ↼ − − − slot-w(pair-r) ∧ pair-r = ↼ − − − pair-r post pair-r = ↼ − − − − pair-w ∧ rs-r = ↼ − − − slot-w(pair-r) end-Read()r: Value rd pair-r, data-w rely pair-r = ↼ − − − pair-r ∧ data-w(pair-r, rs-r) = ↼ − − − − data-w(pair-r, rs-r) post r = data-w(pair-r, rs-r) Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 30 / 36

slide-31
SLIDE 31

Satisfies guarantee conditions (as well as post)

Write(v: Value) local wp-w: P local ws-w: S wp-w ← ρ(pair-r); ws-w ← ρ(slot-w(wp-w)); data-w(wp-w, ws-w) ← v; slot-w(wp-w) ← ws-w; pair-w ← wp-w Read()r: Value local rs-r: S pair-r ← pair-w; rs-r ← slot-w(pair-r); r ← data-w(pair-r, rs-r) Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 31 / 36

slide-32
SLIDE 32

Contents

1

Design as abstraction layers

2

ACMs Where to start – a specification Splitting atoms (gently) in abstract state Retaining less history The four-slot representation

3

Conclusions

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 32 / 36

slide-33
SLIDE 33

Comparisons

Henderson’s thesis (JSF/CBJ supervision)

◮ use “shrinking sequence” in specification ◮ different approaches (including CSP/FDR) highlight facets ◮ up to, including “meta-stability” of control bits

event refinement (Abrial)

◮ f /g to “avoid” algorithmic specification ◮ we were working on proof — in communication ◮ non-deterministic order of events, virtual “instruction counter” ◮ refine one event to many: all but one “refines skip”

Separation Logic (Bornat, Parkinson, Vafeiadis, O’Hearn)

◮ “frame” defined by alphabet of assertions ◮ notation certainly more compact ◮ expected it to be much better on 4-slot because of “ownership” ◮ in fact, doesn’t offer intuition Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 33 / 36

slide-34
SLIDE 34

Conclusions

all at FMCO probably accept “refinement from abstractions” “splitting atoms” – a new/old formal addition subsidiary points

◮ rely/guarantee “thinking” ◮ remember frame descriptions ◮ combination with data reification ◮ link with “phasing” ◮ “auxiliary variables” + Nipkow’s rule ◮ . . . ◮ tool support (ASE*2)

  • ne further technical issue

◮ expressiveness of R/G (thanks to Viktor Vafeiadis) Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 34 / 36

slide-35
SLIDE 35

References

  • J. W. Coleman and C. B. Jones.

A structural proof of the soundness of rely/guarantee rules. Journal of Logic and Computation, 17(4):807–841, 2007.

  • C. B. Jones, D. Lomet, A. Romanovsky, and G. Weikum.

The atomicity manifesto. Journal of Universal Computer Science, 11(5):636–650, 2005.

  • C. B. Jones.

Splitting atoms safely. Theoretical Computer Science, 357:109–119, 2007. Cliff B. Jones and Ken G. Pierce. Splitting atoms with rely/guarantee conditions coupled with data reification. In ABZ2008, volume LNCS 5238, pages 360–377, 2008.

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 35 / 36

slide-36
SLIDE 36

Cliff B Jones (Newcastle) Developing programs by “Splitting atoms” (rely/guarantee conditions, data reification, . . . ) FMCO 2008-10-22 36 / 36