binary session types for psi-calculi (aplas 2016)

26
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

Upload: hans-hyttel

Post on 13-Apr-2017

575 views

Category:

Science


2 download

TRANSCRIPT

Page 1: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 2: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 3: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 4: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 5: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 6: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 7: Binary Session Types for Psi-Calculi (APLAS 2016)

A type rule for output

Γ, c : T2 ` P Γ ` x : T1

Γ, c :!T1.T2 ` cx .P

Hans Huttel

Binary session types for ψ-calculi 7

Page 8: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 9: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 10: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 11: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 12: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 13: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 14: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 15: Binary Session Types for Psi-Calculi (APLAS 2016)

ψ-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

Page 16: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 17: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 18: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 19: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 20: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 21: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 22: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 23: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 24: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 25: Binary Session Types for Psi-Calculi (APLAS 2016)

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

Page 26: Binary Session Types for Psi-Calculi (APLAS 2016)

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