DL A Linear -Calculus with Dependent Types in Agda Luca Ciccone - - PowerPoint PPT Presentation

dl
SMART_READER_LITE
LIVE PREVIEW

DL A Linear -Calculus with Dependent Types in Agda Luca Ciccone - - PowerPoint PPT Presentation

DL A Linear -Calculus with Dependent Types in Agda Luca Ciccone Luca Padovani 5 June 2020 Luca Ciccone, Luca Padovani DL 5 June 2020 1 / 33 Motivation and Goal Motivation and Goal 1 DL - Language 2 DL - Agda Formalization 3


slide-1
SLIDE 1

DLπ

A Linear π-Calculus with Dependent Types in Agda Luca Ciccone Luca Padovani 5 June 2020

Luca Ciccone, Luca Padovani DLπ 5 June 2020 1 / 33

slide-2
SLIDE 2

Motivation and Goal

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 2 / 33

slide-3
SLIDE 3

Motivation and Goal

Motivation

Session types = linear channels + pairs + sums [Dardha et al., 2017] Session = chain of one-shot communications Messages are pairs: payload + continuation channel

Luca Ciccone, Luca Padovani DLπ 5 June 2020 3 / 33

slide-4
SLIDE 4

Motivation and Goal

Motivation

Session types = linear channels + pairs + sums [Dardha et al., 2017] Session = chain of one-shot communications Messages are pairs: payload + continuation channel Dependent session types = linear channels + dependent pairs? Value-dependent session types [Toninho et al., 2011] Liquid Pi [Griffith and Gunter, 2013] Dependent protocols in Idris [Brady, 2017] Dependent session-typed processes [Toninho and Yoshida, 2018] Label-dependent session types [Thiemann and Vasconcelos, 2020]

Luca Ciccone, Luca Padovani DLπ 5 June 2020 3 / 33

slide-5
SLIDE 5

Motivation and Goal

Motivation

Session types = linear channels + pairs + sums [Dardha et al., 2017] Session = chain of one-shot communications Messages are pairs: payload + continuation channel Dependent session types = linear channels + dependent pairs? Value-dependent session types [Toninho et al., 2011] Liquid Pi [Griffith and Gunter, 2013] Dependent protocols in Idris [Brady, 2017] Dependent session-typed processes [Toninho and Yoshida, 2018] Label-dependent session types [Thiemann and Vasconcelos, 2020]

Yes!

Luca Ciccone, Luca Padovani DLπ 5 June 2020 3 / 33

slide-6
SLIDE 6

Motivation and Goal

Goal

Develop a minimal, Agda-based, linear π-calculus with dependent pairs (DLπ) in which dependent session types can be encoded

Luca Ciccone, Luca Padovani DLπ 5 June 2020 4 / 33

slide-7
SLIDE 7

Motivation and Goal

Goal

Develop a minimal, Agda-based, linear π-calculus with dependent pairs (DLπ) in which dependent session types can be encoded Analogous expressiveness of Brady [2017]’s DSL and Toninho and Yoshida [2018]’s calculus, but: different type structure

linear channels + dependent pairs instead of session types

Agda mechanisation of the metatheory we lift from Agda all the machinery related to dependent types

computation of data-dependent types and processes

Luca Ciccone, Luca Padovani DLπ 5 June 2020 4 / 33

slide-8
SLIDE 8

DLπ - Language

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 5 / 33

slide-9
SLIDE 9

DLπ - Language

DLπ - Processes

Terms M, N ::= p pure term | u name | M, N pair Processes P, Q ::= idle inaction | u(x).P input | uM

  • utput

| let x, y = M in P pair splitting | P | Q parallel composition | (a)P restriction | ∗P replication

Luca Ciccone, Luca Padovani DLπ 5 June 2020 6 / 33

slide-10
SLIDE 10

DLπ - Language

DLπ - Processes

Terms M, N ::= p pure term | u name | M, N pair Processes P, Q ::= idle inaction | u(x).P input | uM

  • utput

| let x, y = M in P pair splitting | P | Q parallel composition | (a)P restriction | ∗P replication

Pure terms injected in DLπ

Luca Ciccone, Luca Padovani DLπ 5 June 2020 6 / 33

slide-11
SLIDE 11

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-12
SLIDE 12

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair Multiplicities can be combined with a sum

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-13
SLIDE 13

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair Multiplicities can be combined with a sum 1 + 1 = ω , ω + ω = ω

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-14
SLIDE 14

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair Multiplicities can be combined with a sum 1 + 1 = ω , ω + ω = ω Types can be combined

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-15
SLIDE 15

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair Multiplicities can be combined with a sum 1 + 1 = ω , ω + ω = ω Types can be combined

Partial operation (in Agda represented as a relation)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-16
SLIDE 16

DLπ - Language

DLπ - Types

Domains A, B ∈ A pure types σ, ρ ∈ {0, 1, ω} multiplicities Types t, s ::= A pure type |

σ,ρ[t]

channel type | Σ(x : t)s linear dependent pair Multiplicities can be combined with a sum 1 + 1 = ω , ω + ω = ω Types can be combined

Partial operation (in Agda represented as a relation)

Pairs are linear

Luca Ciccone, Luca Padovani DLπ 5 June 2020 7 / 33

slide-17
SLIDE 17

DLπ - Language

Parallel composition

t-par

Γ1 ⊢ P Γ2 ⊢ Q Γ1 + Γ2 ⊢ P | Q

Luca Ciccone, Luca Padovani DLπ 5 June 2020 8 / 33

slide-18
SLIDE 18

DLπ - Language

Parallel composition

t-par

Γ1 ⊢ P Γ2 ⊢ Q Γ1 + Γ2 ⊢ P | Q Resources are combined Γ1 + Γ2 = Γ1, Γ2 dom(Γ1) ∩ dom(Γ2) = ∅ (u : t, Γ1) + (u : s, Γ2) = (u : t + s), (Γ1 + Γ2)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 8 / 33

slide-19
SLIDE 19

DLπ - Language

Parallel composition

t-par

Γ1 ⊢ P Γ2 ⊢ Q Γ1 + Γ2 ⊢ P | Q Resources are combined Γ1 + Γ2 = Γ1, Γ2 dom(Γ1) ∩ dom(Γ2) = ∅ (u : t, Γ1) + (u : s, Γ2) = (u : t + s), (Γ1 + Γ2) Sum of types

1,0[t] + 0,1[t] = 1,1[t]

Luca Ciccone, Luca Padovani DLπ 5 June 2020 8 / 33

slide-20
SLIDE 20

DLπ - Language

Receive - Send

t-input

Γ1 ⊢ u : 1,0[t] Γ2, x : t ⊢ P Γ1 + Γ2 ⊢ u(x).P

t-output

Γ1 ⊢ u : 0,1[t] Γ2 ⊢ M : t Γ1 + Γ2 ⊢ uM Resources must be combined

Luca Ciccone, Luca Padovani DLπ 5 June 2020 9 / 33

slide-21
SLIDE 21

DLπ - Language

Receive - Send

t-input

Γ1 ⊢ u : 1,0[t] Γ2, x : t ⊢ P Γ1 + Γ2 ⊢ u(x).P

t-output

Γ1 ⊢ u : 0,1[t] Γ2 ⊢ M : t Γ1 + Γ2 ⊢ uM Resources must be combined Linear channels

Input 1, 0 Output 0, 1

Luca Ciccone, Luca Padovani DLπ 5 June 2020 9 / 33

slide-22
SLIDE 22

DLπ - Language

Receive - Send

t-input

Γ1 ⊢ u : 1,0[t] Γ2, x : t ⊢ P Γ1 + Γ2 ⊢ u(x).P

t-output

Γ1 ⊢ u : 0,1[t] Γ2 ⊢ M : t Γ1 + Γ2 ⊢ uM Resources must be combined Linear channels

Input 1, 0 Output 0, 1

Luca Ciccone, Luca Padovani DLπ 5 June 2020 9 / 33

slide-23
SLIDE 23

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-24
SLIDE 24

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Filter function introduced

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-25
SLIDE 25

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Filter function introduced

Map from DLπ terms to pure terms

p = p x = x a = tt M, N = M, N

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-26
SLIDE 26

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Filter function introduced

Map from DLπ terms to pure terms

p = p x = x a = tt M, N = M, N From the point of view of types A = A σ,ρ[t] = ⊤ Σ(x : t)s = Σ(x : t)s

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-27
SLIDE 27

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Filter function introduced

Map from DLπ terms to pure terms

p = p x = x a = tt M, N = M, N From the point of view of types A = A σ,ρ[t] = ⊤ Σ(x : t)s = Σ(x : t)s Channels are erased

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-28
SLIDE 28

DLπ - Language

Dependent Pairs

t-pair Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s

Filter function introduced

Map from DLπ terms to pure terms

p = p x = x a = tt M, N = M, N From the point of view of types A = A σ,ρ[t] = ⊤ Σ(x : t)s = Σ(x : t)s Channels are erased

No dependency on channels

Luca Ciccone, Luca Padovani DLπ 5 June 2020 10 / 33

slide-29
SLIDE 29

DLπ - Agda Formalization

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 11 / 33

slide-30
SLIDE 30

DLπ - Agda Formalization

Multiplicities

data Mult : Set where #0 #1 #ω : Mult data MSplit : Mult ✙ Mult ✙ Mult ✙ Set

Luca Ciccone, Luca Padovani DLπ 5 June 2020 12 / 33

slide-31
SLIDE 31

DLπ - Agda Formalization

Multiplicities

data Mult : Set where #0 #1 #ω : Mult data MSplit : Mult ✙ Mult ✙ Mult ✙ Set Types for defining combinations

Combination of two multiplicities (sum)

MSplit σ σ1 σ2 is inhabited if and only if σ = σ1 + σ2 Relations lifted at type level

Luca Ciccone, Luca Padovani DLπ 5 June 2020 12 / 33

slide-32
SLIDE 32

DLπ - Agda Formalization

Types

mutual data Type : Set1 where Pure : Set ✙ Type Chan : Mult ✙ Mult ✙ Type ✙ Type Pair : (t : Type) ✙ ( t ✙ Type) ✙ Type : Type ✙ Set Pure A = A Chan = ⊤ Pair t f = t λ x ✙ f x

Luca Ciccone, Luca Padovani DLπ 5 June 2020 13 / 33

slide-33
SLIDE 33

DLπ - Agda Formalization

Types

mutual data Type : Set1 where Pure : Set ✙ Type Chan : Mult ✙ Mult ✙ Type ✙ Type Pair : (t : Type) ✙ ( t ✙ Type) ✙ Type : Type ✙ Set Pure A = A Chan = ⊤ Pair t f = t λ x ✙ f x

Inductive-Recursive definition Interpretation function Higher level of Set

Luca Ciccone, Luca Padovani DLπ 5 June 2020 13 / 33

slide-34
SLIDE 34

DLπ - Agda Formalization

Representation of names

Intrinsically typed terms and processes ✙ ✙ ✙ ✙ ✙ ✙ ✙ ✙ ✙

Luca Ciccone, Luca Padovani DLπ 5 June 2020 14 / 33

slide-35
SLIDE 35

DLπ - Agda Formalization

Representation of names

Intrinsically typed terms and processes

Instances are type derivations

✙ ✙ ✙ ✙ ✙ ✙ ✙ ✙ ✙

Luca Ciccone, Luca Padovani DLπ 5 June 2020 14 / 33

slide-36
SLIDE 36

DLπ - Agda Formalization

Representation of names

Intrinsically typed terms and processes

Instances are type derivations

data Name : N ✙ Context ✙ (t : Type) ✙ t ✙ Set1 where here : ∀{ Γ t p } ✙ CNull Γ ✙ Name zero (t # p :: Γ) t p next : ∀{ k Γ t s p q } ✙ TNull s ✙ Name k Γ t p ✙ Name (suc k) (s # q :: Γ) t p

Luca Ciccone, Luca Padovani DLπ 5 June 2020 14 / 33

slide-37
SLIDE 37

DLπ - Agda Formalization

Representation of names

Intrinsically typed terms and processes

Instances are type derivations

data Name : N ✙ Context ✙ (t : Type) ✙ t ✙ Set1 where here : ∀{ Γ t p } ✙ CNull Γ ✙ Name zero (t # p :: Γ) t p next : ∀{ k Γ t s p q } ✙ TNull s ✙ Name k Γ t p ✙ Name (suc k) (s # q :: Γ) t p de Bruijn representation Association to Agda value Type isomorphic to natural numbers

Luca Ciccone, Luca Padovani DLπ 5 June 2020 14 / 33

slide-38
SLIDE 38

DLπ - Agda Formalization

Representation of terms

t-pair

Γ1 ⊢ M : t Γ2 ⊢ N : s{M/x} Γ1 + Γ2 ⊢ M, N : Σ(x : t)s data Term : Context ✙ (t : Type) ✙ t ✙ Set1 where name : ∀{ k Γ t p } ✙ Name k Γ t p ✙ Term Γ t p pure : ∀{ Γ A } ✙ CNull Γ ✙ (p : A) ✙ Term Γ (Pure A) p pair : ∀{ Γ Γ 1 Γ 2 t f p q } ✙ CSplit Γ Γ 1 Γ 2 ✙ Term Γ 1 t p ✙ Term Γ 2 (f p) q ✙ Term Γ (Pair t f) (p , q)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 15 / 33

slide-39
SLIDE 39

DLπ - Agda Formalization

Parallel composition

t-par

Γ1 ⊢ P Γ2 ⊢ Q Γ1 + Γ2 ⊢ P | Q data Process : Context ✙ Set1 where Par : ∀{ Γ Γ 1 Γ 2 } ✙ CSplit Γ Γ 1 Γ 2 ✙ Process Γ 1 ✙ Process Γ 2 ✙ Process Γ

Luca Ciccone, Luca Padovani DLπ 5 June 2020 16 / 33

slide-40
SLIDE 40

DLπ - Agda Formalization

Parallel composition

t-par

Γ1 ⊢ P Γ2 ⊢ Q Γ1 + Γ2 ⊢ P | Q data Process : Context ✙ Set1 where Par : ∀{ Γ Γ 1 Γ 2 } ✙ CSplit Γ Γ 1 Γ 2 ✙ Process Γ 1 ✙ Process Γ 2 ✙ Process Γ Resources combined

Luca Ciccone, Luca Padovani DLπ 5 June 2020 16 / 33

slide-41
SLIDE 41

DLπ - Agda Formalization

Receive

t-input

Γ1 ⊢ u : 1,0[t] Γ2, x : t ⊢ P Γ1 + Γ2 ⊢ u(x).P Recv : ∀{ Γ Γ 1 Γ 2 t } ✙ CSplit Γ Γ 1 Γ 2 ✙ Term Γ 1 (Chan #1 #0 t) ✙ ((x : t ) ✙ Process (t # x :: Γ 2)) ✙ Process Γ

Luca Ciccone, Luca Padovani DLπ 5 June 2020 17 / 33

slide-42
SLIDE 42

DLπ - Agda Formalization

Receive

t-input

Γ1 ⊢ u : 1,0[t] Γ2, x : t ⊢ P Γ1 + Γ2 ⊢ u(x).P Recv : ∀{ Γ Γ 1 Γ 2 t } ✙ CSplit Γ Γ 1 Γ 2 ✙ Term Γ 1 (Chan #1 #0 t) ✙ ((x : t ) ✙ Process (t # x :: Γ 2)) ✙ Process Γ Agda value of a channel omitted (it is tt) Continuation inside a function

Agda value of the received message stored in context

Luca Ciccone, Luca Padovani DLπ 5 June 2020 17 / 33

slide-43
SLIDE 43

DLπ - Agda Formalization

Pair splitting

t-let

Γ1 ⊢ M : Σ(x : t)s Γ2, x : t, y : s ⊢ P Γ1 + Γ2 ⊢ let x, y = M in P Let : ∀{ Γ Γ 1 Γ 2 t f p q } ✙ CSplit Γ Γ 1 Γ 2 ✙ Term Γ 1 (Pair t f) (p , q) ✙ Process (t # p :: f p # q :: Γ 2) ✙ Process Γ

Luca Ciccone, Luca Padovani DLπ 5 June 2020 18 / 33

slide-44
SLIDE 44

DLπ - Agda Formalization

Pair splitting

t-let

Γ1 ⊢ M : Σ(x : t)s Γ2, x : t, y : s ⊢ P Γ1 + Γ2 ⊢ let x, y = M in P Let : ∀{ Γ Γ 1 Γ 2 t f p q } ✙ CSplit Γ Γ 1 Γ 2 ✙ Term Γ 1 (Pair t f) (p , q) ✙ Process (t # p :: f p # q :: Γ 2) ✙ Process Γ Let reflects the pair construction

Luca Ciccone, Luca Padovani DLπ 5 June 2020 18 / 33

slide-45
SLIDE 45

Examples

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 19 / 33

slide-46
SLIDE 46

Examples

Example 1: successor of a number

Q1(u)

def

= u(x, y).yx + 1 ✙ ✙ ✩

Luca Ciccone, Luca Padovani DLπ 5 June 2020 20 / 33

slide-47
SLIDE 47

Examples

Example 1: successor of a number

Q1(u)

def

= u(x, y).yx + 1 Agda code t1 : Type t1 = Chan #1 #0 (Pair (Pure N) λ ✙ Chan #0 #1 (Pure N)) ✙ ✩

Luca Ciccone, Luca Padovani DLπ 5 June 2020 20 / 33

slide-48
SLIDE 48

Examples

Example 1: successor of a number

Q1(u)

def

= u(x, y).yx + 1 Agda code t1 : Type t1 = Chan #1 #0 (Pair (Pure N) λ ✙ Chan #0 #1 (Pure N)) Q1 : Process (t1 # :: []) Q1 = Recv (L []) (name (here [])) λ (x , ) ✙ Let (L []) (name (here [])) ✩ Send (R L []) (name (here [])) (pure (P :: []) (x + 1)) Resource are distributed where needed Pattern matching on the Agda value of the received message

Luca Ciccone, Luca Padovani DLπ 5 June 2020 20 / 33

slide-49
SLIDE 49

Examples

Example 2: predecessor of a number

Q2(u)

def

= u(x, v).v(y, w).wpred(x, y)

✙ ✙ ✙ ✩ ✙ ✩

Luca Ciccone, Luca Padovani DLπ 5 June 2020 21 / 33

slide-50
SLIDE 50

Examples

Example 2: predecessor of a number

Q2(u)

def

= u(x, v).v(y, w).wpred(x, y)

t2 : Type t2 = Chan #1 #0 (Pair (Pure N) λ x ✙ Chan #1 #0 (Pair (Pure (x ≡ 0)) λ ✙ Chan #0 #1 (Pure N))) ✙ ✩ ✙ ✩

Luca Ciccone, Luca Padovani DLπ 5 June 2020 21 / 33

slide-51
SLIDE 51

Examples

Example 2: predecessor of a number

Q2(u)

def

= u(x, v).v(y, w).wpred(x, y)

t2 : Type t2 = Chan #1 #0 (Pair (Pure N) λ x ✙ Chan #1 #0 (Pair (Pure (x ≡ 0)) λ ✙ Chan #0 #1 (Pure N))) Q2 : Process (t2 # :: []) Q2 = Recv (L []) (name (here [])) λ (x , ) ✙ Let (L []) (name (here [])) ✩ Recv (R L []) (name (here [])) λ (y , ) ✙ Let (L R []) (name (here [])) ✩ Send (R L R []) (name (here [])) (pure (P :: P :: []) (pred x y))

Luca Ciccone, Luca Padovani DLπ 5 June 2020 21 / 33

slide-52
SLIDE 52

Examples

Example 3: combining successor and predecessor

Q3

def

= ∗a(x, y).F(x, y) F(true , y) = Q1(y) F(false, y) = Q2(y)

✙ ✩ ✙ ✙

Luca Ciccone, Luca Padovani DLπ 5 June 2020 22 / 33

slide-53
SLIDE 53

Examples

Example 3: combining successor and predecessor

Q3

def

= ∗a(x, y).F(x, y) F(true , y) = Q1(y) F(false, y) = Q2(y)

t3 : Type t3 = Chan #ω #0 (Pair (Pure Bool) (λ b ✙ if b then t1 else t2)) ✩ ✙ ✙

Luca Ciccone, Luca Padovani DLπ 5 June 2020 22 / 33

slide-54
SLIDE 54

Examples

Example 3: combining successor and predecessor

Q3

def

= ∗a(x, y).F(x, y) F(true , y) = Q1(y) F(false, y) = Q2(y)

t3 : Type t3 = Chan #ω #0 (Pair (Pure Bool) (λ b ✙ if b then t1 else t2)) Q3 : Process (t3 # :: []) Q3 = Rep (chan sc1 sc0 :: []) ✩ Recv (L []) (name (here [])) λ { (true , ) ✙ Let (L []) (name (here [])) (weaken Q1) ; (false , ) ✙ Let (L []) (name (here [])) (weaken Q2) }

Explicit case analysis inside the lambda Weakened processes

Luca Ciccone, Luca Padovani DLπ 5 June 2020 22 / 33

slide-55
SLIDE 55

Encoding

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 23 / 33

slide-56
SLIDE 56

Encoding

Plain session types

T, S ::= end | ?m.T | !m.T | T & S | T ⊕ S m ::= A | T

Luca Ciccone, Luca Padovani DLπ 5 June 2020 24 / 33

slide-57
SLIDE 57

Encoding

Plain session types

T, S ::= end | ?m.T | !m.T | T & S | T ⊕ S m ::= A | T Branches and Choices involve a single bit

We assume that it is represented by a Boolean value

Branches and Choices introduce a simple dependency

Luca Ciccone, Luca Padovani DLπ 5 June 2020 24 / 33

slide-58
SLIDE 58

Encoding

Encoding [Dardha et al., 2017]

⌊ ⌊end⌋ ⌋ = 0,0[⊤] ⌊ ⌊?m.T⌋ ⌋ = 1,0[⌊ ⌊m⌋ ⌋ × ⌊ ⌊T⌋ ⌋] ⌊ ⌊!m.T⌋ ⌋ =

0,1[⌊

⌊m⌋ ⌋ × ⌊ ⌊T⌋ ⌋] ⌊ ⌊T & S⌋ ⌋ = 1,0[Σ(x : Bool) if x then ⌊ ⌊T⌋ ⌋ else ⌊ ⌊S⌋ ⌋] ⌊ ⌊T ⊕ S⌋ ⌋ =

0,1[Σ(x : Bool) if x then ⌊

⌊T⌋ ⌋ else ⌊ ⌊S⌋ ⌋] Encoding adapted to DLπ: dependent pairs subsume sums One-shot communications

Payloads have a continuation associated

Continuations on send operations are dualized if x then t else s is a term at the functional layer

Luca Ciccone, Luca Padovani DLπ 5 June 2020 25 / 33

slide-59
SLIDE 59

Encoding

Value-dependent session types [Toninho et al., 2011]

T, S ::= · · · | ∀x : A.T | ∃x : A.T Extension with quantifiers

Luca Ciccone, Luca Padovani DLπ 5 June 2020 26 / 33

slide-60
SLIDE 60

Encoding

Value-dependent session types [Toninho et al., 2011]

T, S ::= · · · | ∀x : A.T | ∃x : A.T Extension with quantifiers Exchanged messages are bound

∀ and ∃ represent input/output operations

Luca Ciccone, Luca Padovani DLπ 5 June 2020 26 / 33

slide-61
SLIDE 61

Encoding

Value-dependent session types [Toninho et al., 2011]

T, S ::= · · · | ∀x : A.T | ∃x : A.T Extension with quantifiers Exchanged messages are bound

∀ and ∃ represent input/output operations

Properties can be expressed ∀x : N.?(x ≡ 0).!N.end

Luca Ciccone, Luca Padovani DLπ 5 June 2020 26 / 33

slide-62
SLIDE 62

Encoding

Value-dependent session types [Toninho et al., 2011]

T, S ::= · · · | ∀x : A.T | ∃x : A.T Extension with quantifiers Exchanged messages are bound

∀ and ∃ represent input/output operations

Properties can be expressed ∀x : N.?(x ≡ 0).!N.end Extension of the encoding ⌊ ⌊∀x : A.T⌋ ⌋ = 1,0[Σ(x : A)⌊ ⌊T⌋ ⌋] ⌊ ⌊∃x : A.T⌋ ⌋ =

0,1[Σ(x : A)⌊

⌊T⌋ ⌋]

Luca Ciccone, Luca Padovani DLπ 5 June 2020 26 / 33

slide-63
SLIDE 63

Encoding

Label-dependent session types [Thiemann and Vasconcelos, 2020]

T, S ::= end | ?x : m.T | !x : m.S | case x of {T, S} No branches and choices constructs

Luca Ciccone, Luca Padovani DLπ 5 June 2020 27 / 33

slide-64
SLIDE 64

Encoding

Label-dependent session types [Thiemann and Vasconcelos, 2020]

T, S ::= end | ?x : m.T | !x : m.S | case x of {T, S} No branches and choices constructs Label dependency

case x of {T, S} for pattern matching over a label

Luca Ciccone, Luca Padovani DLπ 5 June 2020 27 / 33

slide-65
SLIDE 65

Encoding

Label-dependent session types [Thiemann and Vasconcelos, 2020]

T, S ::= end | ?x : m.T | !x : m.S | case x of {T, S} No branches and choices constructs Label dependency

case x of {T, S} for pattern matching over a label

We consider boolean values as set of labels

Luca Ciccone, Luca Padovani DLπ 5 June 2020 27 / 33

slide-66
SLIDE 66

Encoding

Encoding of label-dependent session types

⌊ ⌊end⌋ ⌋ = 0,0[⊤] ⌊ ⌊?x : m.T⌋ ⌋ = 1,0[Σ(x : ⌊ ⌊m⌋ ⌋)⌊ ⌊T⌋ ⌋] ⌊ ⌊!x : m.T⌋ ⌋ =

0,1[Σ(x : ⌊

⌊m⌋ ⌋)⌊ ⌊T⌋ ⌋] ⌊ ⌊case x of {T, S}⌋ ⌋ = if x then ⌊ ⌊T⌋ ⌋ else ⌊ ⌊S⌋ ⌋ Again, we take advantage of the functional layer An environment is needed to track labels

Luca Ciccone, Luca Padovani DLπ 5 June 2020 28 / 33

slide-67
SLIDE 67

Encoding

Properties of the encodings

Encodings ⌊ ⌊·⌋ ⌋ are not injective ⌊ ⌊?Bool.T⌋ ⌋ = ⌊ ⌊T & T⌋ ⌋ = ⌊ ⌊∀x : Bool.T⌋ ⌋ ⌊ ⌊!Bool.T⌋ ⌋ = ⌊ ⌊T ⊕ T⌋ ⌋ = ⌊ ⌊∃x : Bool.T⌋ ⌋ Consequences Semantics of different constructs overlap Encoding is not invertible Decoding ⌈ ⌈·⌉ ⌉ produces a “canonical” session type that is proved to be bisimilar to the original one (details in the repository)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 29 / 33

slide-68
SLIDE 68

Conclusions

1

Motivation and Goal

2

DLπ - Language

3

DLπ - Agda Formalization

4

Examples

5

Encoding

6

Conclusions

Luca Ciccone, Luca Padovani DLπ 5 June 2020 30 / 33

slide-69
SLIDE 69

Conclusions

Summary

“Simple” but expressive type system Linear channels + linear dependent pairs Agda: mechanised methatheory + functional layer Capable of encoding dependent session types

Luca Ciccone, Luca Padovani DLπ 5 June 2020 31 / 33

slide-70
SLIDE 70

Conclusions

Summary

“Simple” but expressive type system Linear channels + linear dependent pairs Agda: mechanised methatheory + functional layer Capable of encoding dependent session types More in the repository Full structural congruence and reduction

Implicitly: congruence and reduction preserve typing

Additional properties

Linear channels not discarded and used at most once

Examples of variable-length protocols Recursive protocols (with sized types [Abel, 2010])

Luca Ciccone, Luca Padovani DLπ 5 June 2020 31 / 33

slide-71
SLIDE 71

Conclusions

Summary

“Simple” but expressive type system Linear channels + linear dependent pairs Agda: mechanised methatheory + functional layer Capable of encoding dependent session types More in the repository Full structural congruence and reduction

Implicitly: congruence and reduction preserve typing

Additional properties

Linear channels not discarded and used at most once

Examples of variable-length protocols Recursive protocols (with sized types [Abel, 2010]) Ongoing work Inference of multiplicities, split and null relations (Agda prototype) Library implementation of dependent session types (Idris prototype)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 31 / 33

slide-72
SLIDE 72

Conclusions

Thank you

https://gitlab.di.unito.it/luca.padovani/DependentLinearPi

Luca Ciccone, Luca Padovani DLπ 5 June 2020 32 / 33

slide-73
SLIDE 73

Variable-length protocol

Q4

def

= ∗a(n, v).F(n, v, 1) F(0 , v, z) = vz F(n + 1, v, z) = v(x, y).F(n, y, x ∗ z) ✙ ✙

Luca Ciccone, Luca Padovani DLπ 5 June 2020 33 / 33

slide-74
SLIDE 74

Variable-length protocol

Q4

def

= ∗a(n, v).F(n, v, 1) F(0 , v, z) = vz F(n + 1, v, z) = v(x, y).F(n, y, x ∗ z) f : N ✙ Type f zero = Chan #0 #1 (Pure N) f (suc n) = Chan #1 #0 (Pair (Pure N) λ ✙ f n) t4 : Type t4 = Chan #ω #0 (Pair (Pure N) f)

Luca Ciccone, Luca Padovani DLπ 5 June 2020 33 / 33

slide-75
SLIDE 75

References

Andreas Abel. Miniagda: Integrating sized and dependent types. In PAR@ITP 2010, volume 5 of EPiC Series, pages 18–32. EasyChair, 2010. URL https://arxiv.org/pdf/1012.4896.pdf. Edwin Brady. Type-driven development of concurrent communicating systems. Computer Science (AGH), 18(3), 2017. doi: 10.7494/csci.2017.18.3.1413. Ornela Dardha, Elena Giachino, and Davide Sangiorgi. Session types revisited.

  • Inf. Comput., 256:253–286, 2017. doi: 10.1016/j.ic.2017.06.002.

Dennis Griffith and Elsa L. Gunter. Liquidpi: Inferrable dependent session types. In NFM 2013, volume 7871 of LNCS, pages 185–197. Springer, 2013. doi: 10.1007/978-3-642-38088-4\ 13. Peter Thiemann and Vasco T. Vasconcelos. Label-dependent session types. Proc. ACM Program. Lang., 4(POPL):67:1–67:29, 2020. doi: 10.1145/3371135. Bernardo Toninho and Nobuko Yoshida. Depending on session-typed processes. In FOSSACS 2018, volume 10803 of LNCS, pages 128–145. Springer, 2018. doi: 10.1007/978-3-319-89366-2\ 7. Bernardo Toninho, Lu´ ıs Caires, and Frank Pfenning. Dependent session types via intuitionistic linear type theory. In PPDP 2011, pages 161–172. ACM, 2011. doi: 10.1145/2003476.2003499.