Contracts for Mobile Processes Giuseppe Castagna Luca Padovani - - PowerPoint PPT Presentation

contracts for mobile processes
SMART_READER_LITE
LIVE PREVIEW

Contracts for Mobile Processes Giuseppe Castagna Luca Padovani - - PowerPoint PPT Presentation

Contracts for Mobile Processes Giuseppe Castagna Luca Padovani Laboratoire PPS, CNRS, Universit e Paris Diderot Istituto di Scienze e Tecnologie dellInformazione, Universit` a di Urbino CONCUR 2009 [ slides by L.Padovani ] Contracts for


slide-1
SLIDE 1

Contracts for Mobile Processes

Giuseppe Castagna Luca Padovani

Laboratoire PPS, CNRS, Universit´ e Paris Diderot Istituto di Scienze e Tecnologie dell’Informazione, Universit` a di Urbino

CONCUR 2009

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 1 / 24

slide-2
SLIDE 2

Outline

1 Motivation

Protocols and processes Contracts and mobile systems

2 Contracts

Syntax Semantics

3 Results 4 Concluding remarks

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 2 / 24

slide-3
SLIDE 3

Protocols and processes

Session types

  • prescriptions on the use of channels

u : σ, v : τ, · · · ⊢ P Contracts

  • overall process behavior

u : Ch, v : Ch, · · · ⊢ P : T Summary

  • both are behavioral types
  • σ = projection of T on u

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 3 / 24

slide-4
SLIDE 4

What session types and contracts are for

Characterizing well-formed systems

  • the system eventually terminates
  • the system never deadlocks

Characterizing well-typed processes

  • sent messages have the correct/expected type
  • messages sent/delivered in the right order

Reasoning about processes by means of their type

  • refactoring processes
  • searching for services

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 4 / 24

slide-5
SLIDE 5

A problem of abstraction

Session types Contracts ?Int.?Int.(!Real ⊕ !Error) a.a.(b ⊕ c) ?(!Bool.!Bool) a ? A natural candidate Contracts without channel passing ⇒ ccs Contracts with channel passing ⇒ π-calculus

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 5 / 24

slide-6
SLIDE 6

A problem of abstraction

Session types Contracts ?Int.?Int.(!Real ⊕ !Error) a.a.(b ⊕ c) ?(!Bool.!Bool) a ? A natural candidate Contracts without channel passing ⇒ ccs Contracts with channel passing ⇒ π-calculus

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 5 / 24

slide-7
SLIDE 7

An example

process store?(x).x?(y : Item). if y is in stock then bank!x else x!available(y) ⇓ contract store?(x).x?Item.(bank!x.1⊕x!Date.1)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 6 / 24

slide-8
SLIDE 8

An example

process store?(x).x?(y : Item). if y is in stock then bank!x else x!available(y) ⇓ contract store?(x).x?Item.(bank!x.1⊕x!Date.1)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 6 / 24

slide-9
SLIDE 9

An example

process store?(x).x?(y : Item). if y is in stock then bank!x else x!available(y) ⇓ contract store?(x).x?Item.(bank!x.1⊕x!Date.1)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 6 / 24

slide-10
SLIDE 10

An example

process store?(x).x?(y : Item). if y is in stock then bank!x else x!available(y) ⇓ contract store?(x).x?Item.(bank!x.1⊕x!Date.1)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 6 / 24

slide-11
SLIDE 11

Some typing rules

v-send

Γ ⊢ e : t Γ ⊢ P : T Γ ⊢ α!e.P : α!t.T

v-recv

Γ, x : t ⊢ P : T Γ ⊢ α?(x : t).P : α?t.T

c-send

Γ ⊢ P : T Γ ⊢ α!β.P : α!β.T

c-recv

Γ, x : Ch ⊢ P : T Γ ⊢ α?x.P : α?(x).T

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 7 / 24

slide-12
SLIDE 12

Some typing rules

v-send

Γ ⊢ e : t Γ ⊢ P : T Γ ⊢ α!e.P : α!t.T

v-recv

Γ, x : t ⊢ P : T Γ ⊢ α?(x : t).P : α?t.T

c-send

Γ ⊢ P : T Γ ⊢ α!β.P : α!β.T

c-recv

Γ, x : Ch ⊢ P : T Γ ⊢ α?x.P : α?(x).T undecidable → decidable

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 7 / 24

slide-13
SLIDE 13

Outline

1 Motivation

Protocols and processes Contracts and mobile systems

2 Contracts

Syntax Semantics

3 Results 4 Concluding remarks

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 8 / 24

slide-14
SLIDE 14

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X) failure, success

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-15
SLIDE 15

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X) dynamic operators

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-16
SLIDE 16

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X) systems

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-17
SLIDE 17

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X) prefixes

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-18
SLIDE 18

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X) patterns = sets of values and names + binders

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-19
SLIDE 19

Syntax

T ::= 0 | 1 π.T | T + T | T ⊕ T T|T | (νa)T π ::= α?f | α!f | α!(a) f ::= x | (x) | a | Int | Bool | · · · Infinite behaviors = infinite terms

  • regularity

X = c?Int.X

  • boundedness

X = a?(x).(c!x.1 | X)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 9 / 24

slide-20
SLIDE 20

Labeled operational semantics

1

→ 1 m ∈ f σ c?f .T

c?m

− → Tσ m ∈ f c!f .T − → c!m.T c!m.T

c!m

− → T Example c!Int.1 | c?Real.1 − → c!20.1 | c?Real.1 − → 1 | 1

→ 20 ∈ Int 20 ∈ Real ∅

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 10 / 24

slide-21
SLIDE 21

Contracts as behavioral types

Systems S

def

= T1 | T2 | · · · | Tn

1 when is a system well-formed? 2 when is a process well-typed? 3 when are two types equal?

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 11 / 24

slide-22
SLIDE 22

Participant satisfaction

Definition

T ⊳ S if T | S = ⇒ T ′ | S′ and T ′ − → implies

  • T ′

µ1

− → and S′

µ2

= ⇒

  • µ1 # µ2

(c!m # c?m, # ) for some µ1 and µ2 Examples

  • c!Int.1 ⊳ c?Real.1
  • c!Real.1 ⊳ c?Int.1

c!Real.1 | c?Int.1 − → c! √ 2.1 | c?Int.1 stuck

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 12 / 24

slide-23
SLIDE 23

Well-formed systems

S

def

= T1 | T2 | · · · | Tn

Definition

S is well formed if Tk ⊳

  • i∈{1,...,n}\{k}

Ti for every 1 ≤ k ≤ n Examples

  • c!Int.1 | c?Real.1 is well formed
  • c!Real.1 | c?Int.1 is ill formed

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 13 / 24

slide-24
SLIDE 24

Well-typed participant

Definition

T is viable if T | S is well formed for some S Example T

def

= c?Int.1 + c?Bool.0 S

def

= c?Int.0 + c?Bool.1

  • T is viable
  • S is viable
  • T ⊕ S is not viable

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 14 / 24

slide-25
SLIDE 25

Example: global order on channels

P

def

= a?x.b?y.x!3.x?(z : Int).y!true.0 P′

def

= a?x.b?y.x!3.y!true.x?(z : Int).0 Q

def

= a!(c).b!(d).c?(z : Int).d?(z : Bool).c!5.0 Q′

def

= a!(c).b!(d).c?(z : Int).c!5.d?(z′ : Bool).0

  • deadlock because of cyclic dependency
  • TP | TQ ill-formed (not viable!)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 15 / 24

slide-26
SLIDE 26

Example: global order on channels

P

def

= a?x.b?y.x!3.x?(z : Int).y!true.0 P′

def

= a?x.b?y.x!3.y!true.x?(z : Int).0 Q

def

= a!(c).b!(d).c?(z : Int).d?(z : Bool).c!5.0 Q′

def

= a!(c).b!(d).c?(z : Int).c!5.d?(z′ : Bool).0

  • imposing global order
  • TP | TQ′ well-formed

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 15 / 24

slide-27
SLIDE 27

Example: global order on channels

P

def

= a?x.b?y.x!3.x?(z : Int).y!true.0 P′

def

= a?x.b?y.x!3.y!true.x?(z : Int).0 Q

def

= a!(c).b!(d).c?(z : Int).d?(z : Bool).c!5.0 Q′

def

= a!(c).b!(d).c?(z : Int).c!5.d?(z′ : Bool).0

  • global order is not necessary
  • TP′ | TQ well-formed

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 15 / 24

slide-28
SLIDE 28

Example: linearity

a?x.b?y.x!y.x?(z : Int).y!true.0 a!(c).b!(d).c?z.c!5.z?(z′ : Bool).0

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 16 / 24

slide-29
SLIDE 29

Subcontract

Definition

T S if T | R well formed implies S | R well formed for every R Examples

  • T ⊕ S T
  • π.T + π.S ≈ π.(T ⊕ S)

. . . very much like the must preorder . . .

  • 0 T

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 17 / 24

slide-30
SLIDE 30

is not a precongruence

0 T

Definition (strong subcontract)

Let ⊑ be the largest precongruence included in

Theorem

If T is viable, then T S iff T ⊑ S

  • T ⊑ 0 iff T is not viable
  • if 1 + T ⊑ T, then T is well formed
  • π.0 ⊑ π.T

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 18 / 24

slide-31
SLIDE 31

Outline

1 Motivation

Protocols and processes Contracts and mobile systems

2 Contracts

Syntax Semantics

3 Results 4 Concluding remarks

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 19 / 24

slide-32
SLIDE 32

On progress

Theorem

If ⊢ P : T and T w.f. and P

τ

= ⇒ Q

τ

− →, then Q has succeeded

  • success = “no pending actions”

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 20 / 24

slide-33
SLIDE 33

On decidability

Proposition

  • well-formedness
  • viability
  • subcontract

are decidable provided that c!f matches finitely many names If a name is sent:

  • either it is fresh

c!(a)

  • or it is a public name

c!a

  • or it was received earlier

c?(x) · · · d!x

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 21 / 24

slide-34
SLIDE 34

Outline

1 Motivation

Protocols and processes Contracts and mobile systems

2 Contracts

Syntax Semantics

3 Results 4 Concluding remarks

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 22 / 24

slide-35
SLIDE 35

Session types and contracts: a comparison

  • optimistic vs conservative
  • global vs compositional

Session types Contracts structuring ++ −− analysis −− ++

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 23 / 24

slide-36
SLIDE 36

Concluding remarks

Contributions

1 contracts for processes with channel mobility 2 straightforward solution to global progress

(of bounded systems) Our wish list

  • algorithms (almost done)
  • choreographic specifications
  • expressiveness

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 24 / 24

slide-37
SLIDE 37

Concluding remarks

Contributions

1 contracts for processes with channel mobility 2 straightforward solution to global progress

(of bounded systems) Our wish list

  • algorithms (almost done)
  • choreographic specifications
  • expressiveness

Thank you.

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 24 / 24

slide-38
SLIDE 38

Regular does not mean finite-state

  • unbounded participants
  • unbounded buffers
  • state encoded within processes

P(x : Int) = deposit?(y : Int).P(x + y) + withdraw?(y : Int).P(max{0, x − y}) P(0) P = c?(x : Int).(deposit?(y : Int).c!x + y.P + withdraw?(y : Int).c!max{0, x − y}.P) Q = c?(x : Int).c!x.Q (νc)(P | c!0.Q)

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 25 / 24

slide-39
SLIDE 39

Simulating asynchrony

input

Γ ⊢ α : Ch Γ, x : t ⊢ P : T Γ ⊢ α?(x : t).P : α?t.T + α?¬t.0

c-recv

Γ ⊢ α : Ch Γ, x : Ch ⊢ P : T Γ ⊢ α?x.P : α?(x).T + α?¬Ch.0

[slides by L.Padovani] Contracts for Mobile Processes (G.Castagna/L.Padovani) CONCUR 2009 26 / 24