Binary session types for ψ-calculi
APLAS 2016
Hanoi, Vietnam,November 2016
Hans H¨uttel
Department of Computer Science
Aalborg University
Selma Lagerl¨ofs Vej 300
Denmark
23 November 2016
1 / 45
What are binary session types?
A type discipline for communicating processes with channels due to
Honda, Kubo and Vasconcelos.
The type of a channel describes the values that can be
transmitted along it. Different kinds of values can be
transmitted on the same channel at different times.
A channel has two endpoints.
The type of a channel describes the protocol followed by the
endpoints.
Hans H¨uttel
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 the
protocol 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 that
c is balanced.
Hans H¨uttel
Binary session types for ψ-calculi 3
What are binary session types?
Honda, Kubo and Vasconcelos added the notions of branching and
selection to the π-calculus.
a lk.Q
selection
| a {l1 : P1, . . . , lk : Pk, . . . ln : Pn}
branching
→ Q | Pk
The type of an endpoint used for selection:
{l1, T1, . . . , ln : Tn}
The type of an endpoint used for branching:
&{l1, T1, . . . , ln : Tn}
The type of a branching/selection name a is (T, T).
Hans H¨uttel
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. We
define
(Γ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 H¨uttel
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 H¨uttel
Binary session types for ψ-calculi 6
A type rule for output
Γ, c : T2 P Γ x : T1
Γ, c :!T1.T2 cx.P
Hans H¨uttel
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
Γ P where all types in Γ and P are balanced and
If c was used in the τ-step, then if Γ(c) = T, then Γ (c) = T
where T is the “remains” of T
Hans H¨uttel
Binary session types for ψ-calculi 8
A plethora of binary session type systems
Type systems for progress (Vieira and Vasconcelos)
Type systems for refinement types (Baltazar, Mostrous and
Vasconcelos)
Type systems with subtyping (Gay and Hole)
. . .
Hans H¨uttel
Binary session types for ψ-calculi 9
A generic type system
The goal of this work is to present a generic type system such that
Known binary session type systems can be represented as
instances of the generic system
A general fidelity theorem holds such that fidelity holds for
every instance of the generic system
So whenever we see a new type system in the future, all we need
to do is to show that it is an instance of the generic system.
Hans H¨uttel
Binary session types for ψ-calculi 10
A generic process calculus framework: ψ-calculi
Bengtson, Johansson, Parrow and Victor introduce ψ-calculi as a
common 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 H¨uttel
Binary session types for ψ-calculi 11
Terms, assertions and conditions
Processes use a syntax similar to that of π-calculus and also make
use of
T data terms M, N
C conditions ϕ
A assertions Ψ
These are different for each instance.
Hans H¨uttel
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 fusions
P | [a = b]
Assertions are composed using an operator called ⊗ and compared
using the equivalence relation .
Hans H¨uttel
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
(|Ψ|) assertion
Hans H¨uttel
Binary session types for ψ-calculi 14
ψ-calculi: Semantics
Bengtson et al. give a labelled semantics of ψ-calculi. Transitions
are of the form
Ψ P
α
−→ P
Ψ is a global assertion. Think of it as the knowledge external to
the process P.
Hans H¨uttel
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 a
session 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 H¨uttel
Binary session types for ψ-calculi 16
Types in the generic type system
Types have an addition operator defined.
Types have transitions that describe the protocol steps
followed by a channel:
T1
!T2
−−→ T3 T4
?T5
−−→ T6
T1
T2
−−−→ T3 T4
T5
−−−→ T6
Hans H¨uttel
Binary session types for ψ-calculi 17
How to define an instance of the type system
Define the types
The set of types
Define how to add types T1 + T2
Define transitions for types
Define the missing type rules
Type rules for terms: Γ, Ψ M : T
Type rules for assertions: Γ, Ψ Ψ
Type rules for conditions: Γ, Ψ ϕ
Hans H¨uttel
Binary session types for ψ-calculi 18
Typing processes
Typings can depend on
The types of names; these are recorded in Γ
Global knowledge (e.g. identities on names); this is recorded
in an assertion Ψ
The type judgements for processes have the form
Γ, Ψ P
Hans H¨uttel
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 H¨uttel
Binary session types for ψ-calculi 20
Fidelity, generalized
Definition
We write Γ, Ψ bal P if all types in Γ and in P are balanced.
Definition
Let α be an action. We let Γ ↑ α denote the type environment
where the session type for the names used in α have progressed.
Hans H¨uttel
Binary session types for ψ-calculi 21
Fidelity, generalized
Theorem
Suppose we have Ψ0 P
τ
−→ P , that Γ, Ψ bal P and Ψ ≤ Ψ0.
Then for some Ψ ≤ Ψ we have Γ ↑ τ, Ψ bal P .
Hans H¨uttel
Binary session types for ψ-calculi 22
Progress
A type system due to Vieira and Vasconcelos that guarantees
progress in the π-calculus. Type judgments are of the form
Γ, P
where is a well-founded order on names. The key insight is to
represent these as assertions.
Here, the representation of the type system makes use of
psi-assertions to play the part of well-founded orders.
Hans H¨uttel
Binary session types for ψ-calculi 23
Other type systems that are instances of our generic
system
A type system for refinement types (Baltazar, Mostrous and
Vasconcelos)
A type system with subtyping (Gay and Hole)
. . .
Hans H¨uttel
Binary session types for ψ-calculi 24
Conclusions
A generic type system for binary session types in the
psi-calculus setting.
A general fidelity result
Known type systems can be represented as instances of the
generic system.
Hans H¨uttel
Binary session types for ψ-calculi 25
Further work
There is no general theorem that tells us what it means to
type-safe for instances. Can we find a way to improve on this?
Our generic type system can capture both liveness and safety
properties!
Can we handle notions of duality other than the standard
one? (Cf. Bernardi et al.)
Hans H¨uttel
Binary session types for ψ-calculi 26

Binary Session Types for Psi-Calculi (APLAS 2016)

  • 1.
    Binary session typesfor ψ-calculi APLAS 2016 Hanoi, Vietnam,November 2016 Hans H¨uttel Department of Computer Science Aalborg University Selma Lagerl¨ofs Vej 300 Denmark 23 November 2016 1 / 45
  • 2.
    What are binarysession types? A type discipline for communicating processes with channels due to Honda, Kubo and Vasconcelos. The type of a channel describes the values that can be transmitted along it. Different kinds of values can be transmitted on the same channel at different times. A channel has two endpoints. The type of a channel describes the protocol followed by the endpoints. Hans H¨uttel Binary session types for ψ-calculi 2
  • 3.
    What are binarysession 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 the protocol 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 that c is balanced. Hans H¨uttel Binary session types for ψ-calculi 3
  • 4.
    What are binarysession types? Honda, Kubo and Vasconcelos added the notions of branching and selection to the π-calculus. a lk.Q selection | a {l1 : P1, . . . , lk : Pk, . . . ln : Pn} branching → Q | Pk The type of an endpoint used for selection: {l1, T1, . . . , ln : Tn} The type of an endpoint used for branching: &{l1, T1, . . . , ln : Tn} The type of a branching/selection name a is (T, T). Hans H¨uttel Binary session types for ψ-calculi 4
  • 5.
    Adding types andtype 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. We define (Γ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 H¨uttel Binary session types for ψ-calculi 5
  • 6.
    Typing parallel compositionby environment splitting The rule Γ1 P1 Γ2 P2 Γ1 + Γ2 P1 | P2 separates the end points of each channel. Hans H¨uttel Binary session types for ψ-calculi 6
  • 7.
    A type rulefor output Γ, c : T2 P Γ x : T1 Γ, c :!T1.T2 cx.P Hans H¨uttel Binary session types for ψ-calculi 7
  • 8.
    Usual properties ofbinary session type systems Theorem (Fidelity) If Γ P, if all types in Γ and P are balanced and P τ −→ P then Γ P where all types in Γ and P are balanced and If c was used in the τ-step, then if Γ(c) = T, then Γ (c) = T where T is the “remains” of T Hans H¨uttel Binary session types for ψ-calculi 8
  • 9.
    A plethora ofbinary session type systems Type systems for progress (Vieira and Vasconcelos) Type systems for refinement types (Baltazar, Mostrous and Vasconcelos) Type systems with subtyping (Gay and Hole) . . . Hans H¨uttel Binary session types for ψ-calculi 9
  • 10.
    A generic typesystem The goal of this work is to present a generic type system such that Known binary session type systems can be represented as instances of the generic system A general fidelity theorem holds such that fidelity holds for every instance of the generic system So whenever we see a new type system in the future, all we need to do is to show that it is an instance of the generic system. Hans H¨uttel Binary session types for ψ-calculi 10
  • 11.
    A generic processcalculus framework: ψ-calculi Bengtson, Johansson, Parrow and Victor introduce ψ-calculi as a common 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 H¨uttel Binary session types for ψ-calculi 11
  • 12.
    Terms, assertions andconditions Processes use a syntax similar to that of π-calculus and also make use of T data terms M, N C conditions ϕ A assertions Ψ These are different for each instance. Hans H¨uttel Binary session types for ψ-calculi 12
  • 13.
    The role ofassertions Assertions can be used to represent e.g. Active substitutions (νx)(P | [x := M]) Name fusions P | [a = b] Assertions are composed using an operator called ⊗ and compared using the equivalence relation . Hans H¨uttel Binary session types for ψ-calculi 13
  • 14.
    Processes in ψ-calculi Everyprocess 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 (|Ψ|) assertion Hans H¨uttel Binary session types for ψ-calculi 14
  • 15.
    ψ-calculi: Semantics Bengtson etal. give a labelled semantics of ψ-calculi. Transitions are of the form Ψ P α −→ P Ψ is a global assertion. Think of it as the knowledge external to the process P. Hans H¨uttel Binary session types for ψ-calculi 15
  • 16.
    Session channels inthe 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 a session 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 H¨uttel Binary session types for ψ-calculi 16
  • 17.
    Types in thegeneric type system Types have an addition operator defined. Types have transitions that describe the protocol steps followed by a channel: T1 !T2 −−→ T3 T4 ?T5 −−→ T6 T1 T2 −−−→ T3 T4 T5 −−−→ T6 Hans H¨uttel Binary session types for ψ-calculi 17
  • 18.
    How to definean instance of the type system Define the types The set of types Define how to add types T1 + T2 Define transitions for types Define the missing type rules Type rules for terms: Γ, Ψ M : T Type rules for assertions: Γ, Ψ Ψ Type rules for conditions: Γ, Ψ ϕ Hans H¨uttel Binary session types for ψ-calculi 18
  • 19.
    Typing processes Typings candepend on The types of names; these are recorded in Γ Global knowledge (e.g. identities on names); this is recorded in an assertion Ψ The type judgements for processes have the form Γ, Ψ P Hans H¨uttel Binary session types for ψ-calculi 19
  • 20.
    An example rulefrom 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 H¨uttel Binary session types for ψ-calculi 20
  • 21.
    Fidelity, generalized Definition We writeΓ, Ψ bal P if all types in Γ and in P are balanced. Definition Let α be an action. We let Γ ↑ α denote the type environment where the session type for the names used in α have progressed. Hans H¨uttel Binary session types for ψ-calculi 21
  • 22.
    Fidelity, generalized Theorem Suppose wehave Ψ0 P τ −→ P , that Γ, Ψ bal P and Ψ ≤ Ψ0. Then for some Ψ ≤ Ψ we have Γ ↑ τ, Ψ bal P . Hans H¨uttel Binary session types for ψ-calculi 22
  • 23.
    Progress A type systemdue to Vieira and Vasconcelos that guarantees progress in the π-calculus. Type judgments are of the form Γ, P where is a well-founded order on names. The key insight is to represent these as assertions. Here, the representation of the type system makes use of psi-assertions to play the part of well-founded orders. Hans H¨uttel Binary session types for ψ-calculi 23
  • 24.
    Other type systemsthat are instances of our generic system A type system for refinement types (Baltazar, Mostrous and Vasconcelos) A type system with subtyping (Gay and Hole) . . . Hans H¨uttel Binary session types for ψ-calculi 24
  • 25.
    Conclusions A generic typesystem for binary session types in the psi-calculus setting. A general fidelity result Known type systems can be represented as instances of the generic system. Hans H¨uttel Binary session types for ψ-calculi 25
  • 26.
    Further work There isno general theorem that tells us what it means to type-safe for instances. Can we find a way to improve on this? Our generic type system can capture both liveness and safety properties! Can we handle notions of duality other than the standard one? (Cf. Bernardi et al.) Hans H¨uttel Binary session types for ψ-calculi 26