extending trace models tony hoare ian wehrman. traces trace: set of events + dependency relation –...

32
Extending Trace Models Tony Hoare Ian Wehrman

Upload: marsha-jones

Post on 01-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Extending Trace Models

Tony HoareIan Wehrman

Page 2: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Traces

• Trace: set of events + dependency relation– an execution of a program

tr

Page 3: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Trace Separation

• Weak separation (*)• tp * tq = tp U tq when tp tq =

• Sequential separation (;)– tp ; tq = tp * tq when not tp ← tp

Page 4: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Trace Semantics

• Trace algebra:– Traces + separators

• Complex trace algebra– Sets of traces + separators lifted point-wise• P * Q = { tp * tq | tp P, tq Q }

• Meaning of P: the set of traces that result from execution of P

Page 5: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Reasoning About Traces

• Theorem: (P ; Q) ; R = P ; (Q ; R)1. Show (tp ; tq) ; tr = tp ; (tq ; tr) for traces tp,tq,tr

(tp ; tq) ; tr= { def of (;) }

(tp ; tq) U tr if not (tp ; tq) ← tr= { def of (;) }

tp U tq U tr if not tp ← tq, tp ← tr, tq ← tr= { symmetric }

tp ; (tq ; tr)

2. Lift from traces to trace sets

Page 6: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Limitations of Traces

• Trace reasoning requires program implementation

• Too detailed for design phase• More abstract model needed

Page 7: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Interfaces

• Execution of P represented by its interface• An interface ip is two sets of arrows:– in(ip): what the execution requires– out(ip): what the execution provides

• Define (later) analogous interface operations– weak interface separation (*’)– sequential interface separation (;’)

Page 8: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Interface Semantics

• Interface algebra: – interfaces + separators

• Complex interface algebra: – sets of interfaces + pointwise-lifted separators• P *’ Q = { ip *’ iq | ip P, iq Q }

• Meaning of P: the set of interfaces that result from execution of P

Page 9: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

From Traces to Interfaces

αin(tr) αout(tr)

tr

• Models related by abstraction function– α = <αin, αout>

Page 10: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

From Traces to Interfaces

– αin(tr) = { a | a’ tr & ¬(a0 tr) }

– αout(tr) = { a | a0 tr & ¬(a’ tr) }

αin(tr) αout(tr)

tr

Page 11: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Interface Separation

ip

iq

ip *’ iq

Page 12: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Interface Separation

• Def. of interface separation (pair of sets):– in(ip *’ iq) = in(ip)\out(iq) U in(iq)\out(iq)

– if in(ip) in(iq) =

– out(ip *’ iq) = out(ip)\in(iq) U out(iq)\in(ip)– if out(ip) out(iq) =

Page 13: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Relating the Models

• Abstraction function α is a homomorphism:– trace alg. → interface alg.– α(tp * tq) = α(tp) *’ α(tq)

• Lifted function Pα is a homomorphism:– complex trace alg. → complex interface alg.– Pα(P * Q) = Pα(P) *’ Pα(Q)

Page 14: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Lifting Lemma

• Write F,G,H for pointwise-lifted funs f,g,h• Lemma:

H(F(A,B))= { def of H }

{ h(x) | x F(A,B) }= { def of F }

{ h(f(a,b)) | a A, B B }= { homomorphism assumption: h(f(a,b)) = g(h(a),h(b)) }

{ g(h(a),h(b)) | a A, B B }= { def of H }

{ g(x,y) | x H(A), y H(B)}= { def of G }

G(H(A),H(B))

Page 15: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Consequences

• Interfaces are a more abstract program model• Homomorphism from traces shows previous

identities still hold• Program features handled modularly– No induction on program structure

Page 16: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Next step: Dataflow

• Dependencies indicate data transfer– Variables: x := 3; y := x– Channels: x<3>.P | x(y).Q

• New model: arrows (at interface) carry values

x := 3 y := x3

Page 17: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Valuations

• A valuation vp is two partial functions: – in(vp): values the execution requires– out(vp): values the execution provides

• Consistency requirement:– in(vp), out(vp) , for some total : AR → VAL

• Define (later) valuation operations– weak valuation separation (*”)– sequential valuation separation (;”)

Page 18: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Valuation Semantics

• Valuation algebra: – interfaces + separators

• Complex valuation algebra: – sets of valuations + pointwise-lifted separators• P *” Q = { vp *” vq | vp P, vq Q }

• Meaning of P: the set of valuations that consistent with execution of P

Page 19: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Valuation Separation

vp

vq

vp *” vq

3

1 9

8

5

4

Page 20: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

From Interfaces to Valuations

• Models are related by the global valuation function : AR → VAL

in(ip) out(ip)

ip3

4 8

↑ in(ip) ↑ out(ip)

↑ ip

Page 21: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

From Interfaces to Valuations

• Models are related by the global valuation function : AR → VAL

• Restriction of gives a homomorphism: • interface alg → valuation alg.• ↑ (ip *’ iq) = ( ↑ ip) *” ( ↑ iq)

• Use lifting lemma again to show homomorphism:• complex interface alg.→complex valuation alg.

Page 22: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Consequences

• Valuations are more abstract, but carry information about dataflow– Homomorphism from interfaces (and traces)

shows previous identities still hold– Program features still handled modularly

• Repeat process to abstract or enrich model further

Page 23: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Next Steps

• Label arrows with location-value pairs– For modeling multiple-assignment vars, heaps– Healthiness conditions distinguish memory

models• Also want to model control dependencies– Current model can’t describe if-then-else

Page 24: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Questions?

Page 25: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr
Page 26: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr
Page 27: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Valuations

in(tr) out(tr)

tr

Page 28: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Trace Picture

Page 29: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Relating the Separators

• Abstraction preserves separation: – α(tp * tq) = α(tp) *’ α(tq)

ip

iq

Page 30: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Relating the Models

• Homomorphisms: – traces → interfaces– trace sets → interface sets

• Consequences:– reason about programs without implementation– trace algebra equations still true

Page 31: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Program Algebra

• Trace sets model program algebra– Operations defined on traces– Lifted pointwise to sets of traces

• Ex: weak separator (*)– tr = tp * tq iff tr = tp U tq and tp tq = – R = P * Q iff trR tp P, tqQ. tr = tp * tq

• Ex: sequential separator (;)– tr = tp ; tq iff tr = tp * tq and not tp ← tp

Page 32: Extending Trace Models Tony Hoare Ian Wehrman. Traces Trace: set of events + dependency relation – an execution of a program tr

Interface Picture

In Out