Top Banner
Tracking Heaps that Hop with Heap-Hop Jules Villard 1,3 Étienne Lozes 2,3 Cristiano Calcagno 4,5 1 Queen Mary, University of London 2 RWTH Aachen, Germany 3 LSV, ENS Cachan, CNRS 4 Monoidics, Inc. 5 Imperial College, London
82

Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Jul 23, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Tracking Heaps that Hop with Heap-Hop

Jules Villard1,3 Étienne Lozes2,3 Cristiano Calcagno4,5

1Queen Mary, University of London

2RWTH Aachen, Germany

3LSV, ENS Cachan, CNRS

4Monoidics, Inc.

5Imperial College, London

Page 2: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Message Passing in Multicore Systems

● Hard to write sequential programs that are both correctand efficient

● Hard to write concurrent programs that are both/eithercorrect and/or efficient

● Paradigm: message passing over a shared memory● Leads to efficient, copyless message passing● May be more error-prone (than message passing with

copies)

Introduction ● Concurrency /

Page 3: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Message Passing in Multicore Systems

● Hard to write sequential programs that are both correctand efficient

● Hard to write concurrent programs that are both/eithercorrect and/or efficient

● Paradigm: message passing over a shared memory● Leads to efficient, copyless message passing● May be more error-prone (than message passing with

copies)

Introduction ● Concurrency /

Page 4: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Message Passing in Multicore Systems

● Hard to write sequential programs that are both correctand efficient

● Hard to write concurrent programs that are both/eithercorrect and/or efficient

● Paradigm: message passing over a shared memory● Leads to efficient, copyless message passing● May be more error-prone (than message passing with

copies)

Introduction ● Concurrency /

Page 5: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

● (e,f): channel● data points to a big struct● struct: type of message

Copyless

send(pointer,e,data);

data

d = receive(pointer,f);

d

Introduction ● Concurrency /

Page 6: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

● (e,f): channel● data points to a big struct● struct: type of message

Copyless

send(pointer,e,data);

data

d = receive(pointer,f);

d

Introduction ● Concurrency /

Page 7: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

Copyless

send(pointer,e,data);

data

d = receive(pointer,f);

d

Introduction ● Concurrency /

Page 8: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

Copyless

send(pointer,e,data);

data

d = receive(pointer,f);

d

Introduction ● Concurrency /

Page 9: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

Copyless Race!

send(pointer,e,data);dispose(data);

data

d = receive(pointer,f);dispose(d);

d

Introduction ● Concurrency /

Page 10: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

Copyless Race!

send(pointer,e,data);dispose(data);

data

d = receive(pointer,f);dispose(d);

d

Introduction ● Concurrency /

Page 11: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

To Copy or not to Copy?

Copyful

send(struct,e,data);

data

d = receive(struct,f);

d

Copyless No race

send(pointer,e,data);

data

d = receive(pointer,f);dispose(d);

d

Introduction ● Concurrency /

Page 12: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Singularity OS

Singularity: a research project and an operating system.

● No hardware memory protection● Sing♯ language● Isolation is verified at compile time● Invariant: each memory cell is owned

by at most one thread● No shared resources● Copyless message passing

p1

p2 p3

memory

Introduction ● Concurrency /

Page 13: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Singularity OS

Singularity: a research project and an operating system.

● No hardware memory protection● Sing♯ language● Isolation is verified at compile time● Invariant: each memory cell is owned

by at most one thread● No shared resources● Copyless message passing

p1

p2 p3

memory

Introduction ● Concurrency /

Page 14: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Singularity Channels [Fähndrich et al. ’06]

● Channels are bidirectional and asynchronouschannel = pair of FIFO queues

● Channels are made of two endpointssimilar to the socket model

● Endpoints can be allocated, disposed of, andcommunicated through channels

similar to the π-calculus● Communications are ruled by user-defined contracts

similar to session types⊖ No formalisation

How to ensure the absence of bugs?

Introduction ● Concurrency /

Page 15: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Analysis [V., Lozes & Calcagno APLAS’09,V. PhD’11]

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

Model Prove Specify

Introduction ● Formal Verification /

Page 16: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

● message passingprimitives

Page 17: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Message Passing Primitives

● (e,f) = open() Creates a bidirectional channel betweenendpoints e and f

● close(e,f) Closes the channel (e,f)● send(a,e,x) Sends message starting with value x on

endpoint e. The message has type/tag a

● x = receive(a,e) Receives message of type a onendpoint e and stores its value in x

1 set_to_ten(x) {2 local e,f;3 (e,f) = open ();4 send(integer ,e ,10);5 x = receive(integer ,f);6 close(e,f);7 }

Copyless Message Passing ● Language Model /

Page 18: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Switch Receive

● switch receive selects a receive branch depending onavailability of messages

if( x ) {send(cell ,e,x);

} else {send(integer ,e,0);

}

switch receive {y = receive(cell ,f): {dispose(y);}z = receive(integer ,f): {}

}

Copyless Message Passing ● Language Model /

Page 19: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

● Race freedom

● Reception fault freedom

● Leak freedom

Page 20: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

At each point in the execution, the state can be partitioned intowhat is owned by each program and each message in transit.

● Programs accessonly what they own

● Prevents races● Linear usage of

channels

memory

Invalid receptions freedom

Leak freedom

Copyless Message Passing ● Properties of Interest /

Page 21: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

At each point in the execution, the state can be partitioned intowhat is owned by each program and each message in transit.

● Programs accessonly what they own

● Prevents races● Linear usage of

channels

m1

m2

m3

p1 p2

memory

Invalid receptions freedom

Leak freedom

Copyless Message Passing ● Properties of Interest /

Page 22: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

At each point in the execution, the state can be partitioned intowhat is owned by each program and each message in transit.

● Programs accessonly what they own

● Prevents races● Linear usage of

channels

m1

m2

m3

p1 p2

cell

memory

Invalid receptions freedom

Leak freedom

Copyless Message Passing ● Properties of Interest /

Page 23: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

At each point in the execution, the state can be partitioned intowhat is owned by each program and each message in transit.

● Programs accessonly what they own

● Prevents races● Linear usage of

channels

m1

m2

m3

p1 p2

memory

Invalid receptions freedom

Leak freedom

Copyless Message Passing ● Properties of Interest /

Page 24: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

Invalid receptions freedom

switch receive are exhaustive.

...switch receive {

y = receive(a,f): { ... }z = receive(b,f): { ... }

}...

...send(c,e,x);...

Leak freedom

Copyless Message Passing ● Properties of Interest /

Page 25: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Safety Properties

Separation property

Invalid receptions freedom

Leak freedom

The program does not leak memory.

1 main() {2 local x,e,f;3

4 x = new ();5 (e,f) = open ();6 send(cell ,e,x);7 close(e,f);8 }

Copyless Message Passing ● Properties of Interest /

Page 26: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.● Communicating automata

Page 27: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

● Sending transitions: !a● Receiving transitions: ?a● Two buffers: one in each direction● Configuration: ⟨q,q′,w ,w ′⟩

Channel Contracts ● Communicating Automata /

Page 28: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q0, ε, ε⟩

Channel Contracts ● Communicating Automata /

Page 29: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q1,a, ε⟩

Channel Contracts ● Communicating Automata /

Page 30: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q2,ab, ε⟩

Channel Contracts ● Communicating Automata /

Page 31: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨qa,q2,b, ε⟩

Channel Contracts ● Communicating Automata /

Page 32: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q2,b,a⟩

Channel Contracts ● Communicating Automata /

Page 33: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q3,b, ε⟩

Channel Contracts ● Communicating Automata /

Page 34: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨qb,q3, ε, ε⟩

Channel Contracts ● Communicating Automata /

Page 35: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q3, ε,b⟩

Channel Contracts ● Communicating Automata /

Page 36: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

A Dialogue System

qqa qb

?a ?b

!a !b

q0 q1 q2 q3 q4!a !b ?a ?b

⟨q,q4, ε, ε⟩

Channel Contracts ● Communicating Automata /

Page 37: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contracts

Describe dual communicating finite state machines

C init end!pointer

init end?pointer ˜C

C′ q

q′

end

!cell ?ack

!finq

q′

end

?cell !ack

?fin ˜C

Channel Contracts ● Communicating Automata /

Page 38: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contracts

Describe dual communicating finite state machines

C init end!pointer

init end?pointer ˜C

C′ q

q′

end

!cell ?ack

!finq

q′

end

?cell !ack

?fin ˜C

Channel Contracts ● Communicating Automata /

Page 39: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contracts

Describe dual communicating finite state machines

C init end!pointer

init end?pointer ˜C

C′ q

q′

end

!cell ?ack

!finq

q′

end

?cell !ack

?fin ˜C

Channel Contracts ● Communicating Automata /

Page 40: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contracts as Protocol Specifications

● (e,f) = open(C): initialise endpoints in the initial state ofthe contract

● send(a,e,x): becomes a !a transition● y = receive(a,f): becomes a ?a transition● close(e,f) only when both endpoints are in the same

final state.

Channel Contracts ● Communicating Automata /

Page 41: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

● Reception faults

● Leaks

Page 42: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Reception Errors

Definition Reception fault

⟨q1,q2,a ⋅w1,w2⟩ is a reception fault if

● q1?bÐ→ q for some b and q and

● ∀b,q.q1?bÐ→ q implies b ≠ a

q

q1

q′1

q2

!a

?b

?a

!b

q

q1

q′1

q2

?a

!b

!a

?b

⟨q,q, ε, ε⟩

?bÐ→2 error

Channel Contracts ● Contract Verification /

Page 43: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Reception Errors

Definition Reception fault

⟨q1,q2,a ⋅w1,w2⟩ is a reception fault if

● q1?bÐ→ q for some b and q and

● ∀b,q.q1?bÐ→ q implies b ≠ a

q

q1

q′1

q2

!a

?b

?a

!b

q

q1

q′1

q2

?a

!b

!a

?b

⟨q1,q,a, ε⟩

?bÐ→2 error

Channel Contracts ● Contract Verification /

Page 44: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Reception Errors

Definition Reception fault

⟨q1,q2,a ⋅w1,w2⟩ is a reception fault if

● q1?bÐ→ q for some b and q and

● ∀b,q.q1?bÐ→ q implies b ≠ a

q

q1

q′1

q2

!a

?b

?a

!b

q

q1

q′1

q2

?a

!b

!a

?b

⟨q1,q′1,a,b⟩

?bÐ→2 error

Channel Contracts ● Contract Verification /

Page 45: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Reception Errors

Definition Reception fault

⟨q1,q2,a ⋅w1,w2⟩ is a reception fault if

● q1?bÐ→ q for some b and q and

● ∀b,q.q1?bÐ→ q implies b ≠ a

q

q1

q′1

q2

!a

?b

?a

!b

q

q1

q′1

q2

?a

!b

!a

?b

⟨q1,q′1,a,b⟩?bÐ→2 error

Channel Contracts ● Contract Verification /

Page 46: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Reception Errors

Definition Reception fault

⟨q1,q2,a ⋅w1,w2⟩ is a reception fault if

● q1?bÐ→ q for some b and q and

● ∀b,q.q1?bÐ→ q implies b ≠ a

● A contract is reception fault-free if it cannot reach areception fault.

Channel Contracts ● Contract Verification /

Page 47: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

q q1 q2!a

!a

!aq q1 q2

?a

?a

?a

⟨q,q,

a

ε, ε⟩

Channel Contracts ● Contract Verification /

Page 48: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

q q1 q2!a

!a

!aq q1 q2

?a

?a

?a

⟨q1,q,

a

a, ε⟩

Channel Contracts ● Contract Verification /

Page 49: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

q q1 q2!a

!a

!aq q1 q2

?a

?a

?a

⟨q2,q,aa, ε⟩

Channel Contracts ● Contract Verification /

Page 50: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

q q1 q2!a

!a

!aq q1 q2

?a

?a

?a

⟨q2,q2,a, ε⟩

Channel Contracts ● Contract Verification /

Page 51: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

q q1 q2!a

!a

!aq q1 q2

?a

?a

?a

⟨q2,q2,a, ε⟩

Channel Contracts ● Contract Verification /

Page 52: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Undelivered Messages

Definition Leak

⟨qf ,qf ,w1,w2⟩ is a leak if w1 ⋅w2 ≠ ε and qf is final.

● A contract is leak free if it cannot reach a leak.● A contract is safe if it is reception fault free and leak free.

Channel Contracts ● Contract Verification /

Page 53: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contract Verification

⊖ Safety of communicating systems is undecidable in generalChannel’s buffer ≈ Turing machine’s tape

● Contracts are restricted (dual systems)⊖ Contracts can encode Turing machines as well

Theorem

Safety is undecidable for contracts.

● We give sufficient conditions for safety.

Channel Contracts ● Contract Verification /

Page 54: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contract Verification

⊖ Safety of communicating systems is undecidable in generalChannel’s buffer ≈ Turing machine’s tape

⊕ Contracts are restricted (dual systems)

⊖ Contracts can encode Turing machines as well

Theorem

Safety is undecidable for contracts.

● We give sufficient conditions for safety.

Channel Contracts ● Contract Verification /

Page 55: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contract Verification

⊖ Safety of communicating systems is undecidable in generalChannel’s buffer ≈ Turing machine’s tape

● Contracts are restricted (dual systems)⊖ Contracts can encode Turing machines as well

Theorem

Safety is undecidable for contracts.

● We give sufficient conditions for safety.

Channel Contracts ● Contract Verification /

Page 56: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contract Verification

⊖ Safety of communicating systems is undecidable in generalChannel’s buffer ≈ Turing machine’s tape

● Contracts are restricted (dual systems)⊖ Contracts can encode Turing machines as well

Theorem

Safety is undecidable for contracts.

● We give sufficient conditions for safety.

Channel Contracts ● Contract Verification /

Page 57: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Sufficient Conditions for Reception Safety

Definition Deterministic contract

Two distinct edges in a contract must be labelled by differentmessages.

qq1

q2

!a

!aq

q1

q2

!a

!bq

q1

q2

!a

?a

Definition Positional contracts

Channel Contracts ● Singularity Contracts /

Page 58: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Sufficient Conditions for Reception Safety

Definition Deterministic contract

Definition Positional contracts

All outgoing edges from a same state in a contract must beeither all sends or all receives.

qq1

q2

!a1

?a2

qq1

q2

!a1

!a2

Channel Contracts ● Singularity Contracts /

Page 59: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Sufficient Conditions for Reception Safety

Definition Deterministic contract

Definition Positional contracts

Theorem [Stengel & Bultan’09] ● [V., Lozes & Calcagno ’09]

Deterministic positional contracts are reception fault free.

Channel Contracts ● Singularity Contracts /

Page 60: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Another Source of Leaks

q

!a

q

?a

⟨q,q, ε, ε⟩

Channel Contracts ● Singularity Contracts /

Page 61: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Another Source of Leaks

q

!a

q

?a

⟨q,q, ε, ε⟩

Channel Contracts ● Singularity Contracts /

Page 62: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Another Source of Leaks

q

!a

q

?a

⟨q,q,a, ε⟩

Channel Contracts ● Singularity Contracts /

Page 63: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Another Source of Leaks

q

!a

q

?a

⟨q,q,aa, ε⟩

Channel Contracts ● Singularity Contracts /

Page 64: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Another Source of Leaks

q

!a

q

?a

⟨q,q,aaa, ε⟩

Channel Contracts ● Singularity Contracts /

Page 65: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Synchronising Contracts

Definition Synchronising state

A state s is synchronising if every cycle that goes through itcontains at least one send and one receive.

q q′

!a

!b

q q′

!a

?b

Definition Synchronising contract

A contract is synchronising if all its final states are.

Theorem [V., Lozes & Calcagno ’09]

Deterministic, positional and synchronising contracts are safe(fault and leak free).

Channel Contracts ● Singularity Contracts /

Page 66: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Synchronising Contracts

Definition Synchronising state

A state s is synchronising if every cycle that goes through itcontains at least one send and one receive.

Definition Synchronising contract

A contract is synchronising if all its final states are.

Theorem [V., Lozes & Calcagno ’09]

Deterministic, positional and synchronising contracts are safe(fault and leak free).

Channel Contracts ● Singularity Contracts /

Page 67: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Synchronising Contracts

Definition Synchronising state

A state s is synchronising if every cycle that goes through itcontains at least one send and one receive.

Definition Synchronising contract

A contract is synchronising if all its final states are.

Theorem [V., Lozes & Calcagno ’09]

Deterministic, positional and synchronising contracts are safe(fault and leak free).

Channel Contracts ● Singularity Contracts /

Page 68: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Singularity Contracts

Definition Singularity contract

Singularity contracts are deterministic and all their states aresynchronising.

● This is missing the positional condition!● Does not guarantee reception fault freedom● In fact, we proved that safety is still undecidable for

deterministic or positional contracts.● Positional Singularity contracts are safe and bounded.

Channel Contracts ● Singularity Contracts /

Page 69: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

● Extension tomessage passing

Page 70: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Separation Logic [Reynolds 02, O’Hearn 01, . . . ]

● Local reasoning for heap-manipulating programs● Naturally describes ownership transfers● Numerous extensions, e.g. storable locks [Gotsman et al. 07]

New Now with message passing! [APLAS’09]

Proving Copyless Message Passing ● Assertions /

Page 71: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Separation Logic [Reynolds 02, O’Hearn 01, . . . ]

● Local reasoning for heap-manipulating programs● Naturally describes ownership transfers● Numerous extensions, e.g. storable locks [Gotsman et al. 07]

New Now with message passing! [APLAS’09]

Proving Copyless Message Passing ● Assertions /

Page 72: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Assertions

Syntax of SL

E ∶∶= x ∣ n ∈ {0,1,2, . . .} ∣ ⋯ expressionsφ ∶∶= E1 = E2 ∣ E1 ≠ E2 stack predicates

∣ emp ∣ E1 ↦ E2 heap predicates∣ ∃x . φ ∣ φ1 ∧ φ2 ∣ ¬φ ∣ φ1 ∗ φ2 formulas

Proving Copyless Message Passing ● Assertions /

Page 73: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Assertions (extension)

Syntax (continued)φ ∶∶= . . .

∣ E ↦ (C{q},E ′) endpoint predicate

Intuitively E ↦ (C{q},E ′) means:● E is an allocated endpoint● it is ruled by contract C● it is currently in the control state q of C● its peer is E ′

Proving Copyless Message Passing ● Assertions /

Page 74: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.● Extends Smallfoot

with messagepassing

● Written in OCaml

● Open source

Page 75: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

[V., Lozes & Calcagno TACAS’10]

Proving Copyless Message Passing ● Demo /

Page 76: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Heap-Hop

Program Proof SL+MP

+

Contracts Prop. Contracts

=

Program Prop.

● soundness

Page 77: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Validity and Leak Freedom

Definition Program validity

{φ} p {ψ} is valid if, for all σ ⊧ φ● p has no race or memory fault starting from σ

● p has no reception faults starting from σ

● if p, σ →∗ σ′ then σ′ ⊧ ψ

Definition Leak free programs

p is leak free if for all σ

p, σ →∗ σ′ implies that the heap and buffers of σ′ are empty

Proving Copyless Message Passing ● Soundness /

Page 78: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Properties of Proved Programs

Theorem Soundness

If {φ} p {ψ} is provable with reception fault free contractsthen {φ} p {ψ} is valid.

Theorem Leak freedom

If {φ} p {emp} is provable with leak free contracts then p isleak free.

Proving Copyless Message Passing ● Soundness /

Page 79: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Conclusion

Page 80: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Contributions

Contracts

● Formalisation of contracts● Automatic verification of contract properties

Program analysis

● Verification of heap-manipulating, message passingprograms with contracts

● Contracts and proofs collaborate to prove freedom fromreception errors and leaks

● Tool that integrates this analysis: Heap-Hop

Conclusion /

Page 81: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Perspectives

Contracts

● Prove progress for programs● Extend to the multiparty case● Enrich contracts (counters, non positional, . . . )

Today@5:15 More general property of contracts for decidability:half-duplex

Automatic program verification

● Discover specs and message footprints● Discover contracts● Fully automated tool

Conclusion /

Page 82: Tracking Heaps that Hop with Heap-Hopsimon/BehaviouralTypes/slides/Villard.pdf · Tracking Heaps that Hop with Heap-Hop Jules Villard1;3 Étienne Lozes2;3 Cristiano Calcagno4;5 1Queen

Tracking Heaps that Hop with Heap-Hop

Jules Villard1,3 Étienne Lozes2,3 Cristiano Calcagno4,5

1Queen Mary, University of London

2RWTH Aachen, Germany

3LSV, ENS Cachan, CNRS

4Monoidics, Inc.

5Imperial College, London