Binary session types for ψ-calculi
APLAS 2016
Hanoi, Vietnam,November 2016
Hans Huttel
Department of Computer ScienceAalborg University
Selma Lagerlofs Vej 300Denmark
23 November 2016
1 / 45
What are binary session types?
A type discipline for communicating processes with channels due toHonda, Kubo and Vasconcelos.
I The type of a channel describes the values that can betransmitted along it. Different kinds of values can betransmitted on the same channel at different times.
I A channel has two endpoints.
I The type of a channel describes the protocol followed by theendpoints.
Hans Huttel
Binary session types for ψ-calculi 2
What are binary session types?
(νc : S)(ac.c(x).cx = 3︸ ︷︷ ︸P1
| a(y).y17.y(x).P(x)︸ ︷︷ ︸P2
)
The channel c has two endpoints, c+ and c−. In P1 c+ follows theprotocol T :
c+ :?Int.!Bool.end
In P2 c− follows the dual protocol T
c− :!Int.?Bool.end
c has type S = (T ,T ). The endpoint types are dual; we say thatc is balanced.
Hans Huttel
Binary session types for ψ-calculi 3
What are binary session types?
Honda, Kubo and Vasconcelos added the notions of branching andselection to the π-calculus.
a / lk .Q︸ ︷︷ ︸selection
| a . {l1 : P1, . . . , lk : Pk , . . . ln : Pn}︸ ︷︷ ︸branching
→ Q | Pk
I The type of an endpoint used for selection:⊗{l1,T1, . . . , ln : Tn}
I The type of an endpoint used for branching:&{l1,T1, . . . , ln : Tn}
The type of a branching/selection name a is (T ,T ).
Hans Huttel
Binary session types for ψ-calculi 4
Adding types and type environments
We define addition of types by
(T1,T2) = T1 + T2.
This corresponds to joining/separating endpoints.
A type environment Γ is a function Γ : Names→ Types. Wedefine
(Γ1 + Γ2)(x) =
T1 + T2 if Γ1(x) = T1, Γ2(x) = T2
T1 if Γ1(x) = T1, Γ2(x) undefined
T2 if Γ2(x) = T2, Γ1(x) undefined
Hans Huttel
Binary session types for ψ-calculi 5
Typing parallel composition by environment splitting
The ruleΓ1 ` P1 Γ2 ` P2
Γ1 + Γ2 ` P1 | P2
separates the end points of each channel.
Hans Huttel
Binary session types for ψ-calculi 6
A type rule for output
Γ, c : T2 ` P Γ ` x : T1
Γ, c :!T1.T2 ` cx .P
Hans Huttel
Binary session types for ψ-calculi 7
Usual properties of binary session type systems
Theorem (Fidelity)
If Γ ` P, if all types in Γ and P are balanced and Pτ−→ P ′ then
I Γ′ ` P ′ where all types in Γ′ and P ′ are balanced and
I If c was used in the τ -step, then if Γ(c) = T , then Γ′(c) = T ′
where T ′ is the “remains” of T
Hans Huttel
Binary session types for ψ-calculi 8
A plethora of binary session type systems
I Type systems for progress (Vieira and Vasconcelos)
I Type systems for refinement types (Baltazar, Mostrous andVasconcelos)
I Type systems with subtyping (Gay and Hole)
I . . .
Hans Huttel
Binary session types for ψ-calculi 9
A generic type system
The goal of this work is to present a generic type system such that
I Known binary session type systems can be represented asinstances of the generic system
I A general fidelity theorem holds such that fidelity holds forevery instance of the generic system
So whenever we see a new type system in the future, all we needto do is to show that it is an instance of the generic system.
Hans Huttel
Binary session types for ψ-calculi 10
A generic process calculus framework: ψ-calculi
Bengtson, Johansson, Parrow and Victor introduce ψ-calculi as acommon generalization of many π-like process calculi.
In a psi-calculus, any term can be used as a channel. Here is aψ-calculus with numbers.
5〈83〉.84(x).84〈x = 3〉 | 5(y).y + 1〈17〉.y(x).P(x)
Hans Huttel
Binary session types for ψ-calculi 11
Terms, assertions and conditions
Processes use a syntax similar to that of π-calculus and also makeuse of
T data terms M,N
C conditions ϕ
A assertions Ψ
These are different for each instance.
Hans Huttel
Binary session types for ψ-calculi 12
The role of assertions
Assertions can be used to represent e.g.
Active substitutions(νx)(P | [x := M])
Name fusionsP | [a = b]
Assertions are composed using an operator called ⊗ and comparedusing the equivalence relation '.
Hans Huttel
Binary session types for ψ-calculi 13
Processes in ψ-calculi
Every process calculus that is a ψ-calculus has the same syntax.
P ::=
M(λx)N.P input with pattern (λx)N
MN.P output
P1 | P2 parallel composition
(νx : T )P restriction
∗ P replication
case ϕ1 : P1, . . . , ϕk : Pk conditional
M / l .P1 selection
M . {l1 : P1, . . . , lk : Pk} branching
(|Ψ|) assertionHans Huttel
Binary session types for ψ-calculi 14
ψ-calculi: Semantics
Bengtson et al. give a labelled semantics of ψ-calculi. Transitionsare of the form
Ψ B Pα−→ P ′
Ψ is a global assertion. Think of it as the knowledge external tothe process P.
Hans Huttel
Binary session types for ψ-calculi 15
Session channels in the generic system
In a psi-calculus, any term can be used as a channel.
5〈83〉.84(x).84〈x = 3〉 | 5(y).y + 1〈17〉.y + 3(x).P(x)
How can we set up new session channels?
We introduce names that are session constructors. Applying asession constructor to a term gives us a session channel.
(5@c〈d , 83〉.d@84(x).d@84〈x = 3〉 |c@5(s, y).s@(y + 1)〈17〉.s@(y + 3)(x).P(x))
Hans Huttel
Binary session types for ψ-calculi 16
Types in the generic type system
I Types have an addition operator defined.
I Types have transitions that describe the protocol stepsfollowed by a channel:
T1!T2−−→ T3 T4
?T5−−→ T6
T1`BT2−−−→ T3 T4
`CT5−−−→ T6
Hans Huttel
Binary session types for ψ-calculi 17
How to define an instance of the type system
Define the types
I The set of typesI Define how to add types T1 + T2
I Define transitions for types
Define the missing type rules
I Type rules for terms: Γ,Ψ ` M : TI Type rules for assertions: Γ,Ψ ` ΨI Type rules for conditions: Γ,Ψ ` ϕ
Hans Huttel
Binary session types for ψ-calculi 18
Typing processes
Typings can depend on
I The types of names; these are recorded in Γ
I Global knowledge (e.g. identities on names); this is recordedin an assertion Ψ
The type judgements for processes have the form
Γ,Ψ ` P
Hans Huttel
Binary session types for ψ-calculi 19
An example rule from the generic system
(Out)
Γ1,Ψ1 `min M : T1@c T1!,T2−−→ T3
Γ2,Ψ2 `min N : T2 Γ3 + c : T3,Ψ3 ` P
Γ1 + Γ2 + Γ3,Ψ1 � Ψ2 � Ψ3 ` MN.P
Hans Huttel
Binary session types for ψ-calculi 20
Fidelity, generalized
DefinitionWe write Γ,Ψ `bal P if all types in Γ and in P are balanced.
DefinitionLet α be an action. We let Γ ↑ α denote the type environmentwhere the session type for the names used in α have progressed.
Hans Huttel
Binary session types for ψ-calculi 21
Fidelity, generalized
TheoremSuppose we have Ψ0 I P
τ−→ P ′, that Γ,Ψ `bal P and Ψ ≤ Ψ0.Then for some Ψ′ ≤ Ψ we have Γ ↑ τ,Ψ′ `bal P ′.
Hans Huttel
Binary session types for ψ-calculi 22
Progress
A type system due to Vieira and Vasconcelos that guaranteesprogress in the π-calculus. Type judgments are of the form
Γ,≺` P
where ≺ is a well-founded order on names. The key insight is torepresent these as assertions.Here, the representation of the type system makes use ofpsi-assertions to play the part of well-founded orders.
Hans Huttel
Binary session types for ψ-calculi 23
Other type systems that are instances of our genericsystem
I A type system for refinement types (Baltazar, Mostrous andVasconcelos)
I A type system with subtyping (Gay and Hole)
I . . .
Hans Huttel
Binary session types for ψ-calculi 24
Conclusions
I A generic type system for binary session types in thepsi-calculus setting.
I A general fidelity result
I Known type systems can be represented as instances of thegeneric system.
Hans Huttel
Binary session types for ψ-calculi 25
Further work
I There is no general theorem that tells us what it means totype-safe for instances. Can we find a way to improve on this?Our generic type system can capture both liveness and safetyproperties!
I Can we handle notions of duality other than the standardone? (Cf. Bernardi et al.)
Hans Huttel
Binary session types for ψ-calculi 26
Top Related