Thinking About Mechanizing the Meta-Theory of Session Types - - PowerPoint PPT Presentation

thinking about mechanizing the meta theory of session
SMART_READER_LITE
LIVE PREVIEW

Thinking About Mechanizing the Meta-Theory of Session Types - - PowerPoint PPT Presentation

Thinking About Mechanizing the Meta-Theory of Session Types Francisco Ferreira (joint work with Nobuko Yoshida) 17th Dec ABCD Meeting - Imperial College London 1 /27 Engineering the Meta-Theory of Session Types Francisco Ferreira (joint


slide-1
SLIDE 1

/27

Thinking About Mechanizing the Meta-Theory of Session Types

Francisco Ferreira (joint work with Nobuko Yoshida) 17th Dec ABCD Meeting - Imperial College London

1

slide-2
SLIDE 2

/27

Engineering the Meta-Theory of Session Types

17th Dec ABCD Meeting - Imperial College London Francisco Ferreira (joint work with Nobuko Yoshida)

2

slide-3
SLIDE 3

/27

–Ludwig Wittgenstein

“The limits of my language mean the limits of my world.”

3

slide-4
SLIDE 4

/27

Who Am I?

  • I did my PhD at McGill University, advised by Brigitte Pientka.
  • I worked with Higher Order Abstract Syntax.
  • Also on the meta-theory of programming languages.

4

slide-5
SLIDE 5

/27

Who Am I?

  • I did my PhD at McGill University, advised by Brigitte Pientka.
  • I worked with Higher Order Abstract Syntax.
  • Also on the meta-theory of programming languages.
  • I worked in the implementation of:

4

slide-6
SLIDE 6

/27

Who Am I?

  • I did my PhD at McGill University, advised by Brigitte Pientka.
  • I worked with Higher Order Abstract Syntax.
  • Also on the meta-theory of programming languages.
  • I worked in the implementation of:
  • Beluga — My supervisor’s project on computational reasoning about LF

definitions.

4

slide-7
SLIDE 7

/27

Who Am I?

  • I did my PhD at McGill University, advised by Brigitte Pientka.
  • I worked with Higher Order Abstract Syntax.
  • Also on the meta-theory of programming languages.
  • I worked in the implementation of:
  • Beluga — My supervisor’s project on computational reasoning about LF

definitions.

  • Babybel — Our project on supporting HOAS in functional programming

languages (e.g.: OCaml).

4

slide-8
SLIDE 8

/27

Who Am I?

  • I did my PhD at McGill University, advised by Brigitte Pientka.
  • I worked with Higher Order Abstract Syntax.
  • Also on the meta-theory of programming languages.
  • I worked in the implementation of:
  • Beluga — My supervisor’s project on computational reasoning about LF

definitions.

  • Babybel — Our project on supporting HOAS in functional programming

languages (e.g.: OCaml).

  • Orca — Our project on combining HOAS and Type Theory.

4

slide-9
SLIDE 9

/27

Mechanising the Meta-Theory Session Types

  • Names are ubiquitous.
  • The binding structure is quite rich.
  • Channels are handled linearly.
  • Names exist besides binders. Names are a first

class notion.

5

slide-10
SLIDE 10

/27

The First Step

  • Do a case study:
  • Language Primitives and Type Discipline for

Structured Communication-Based Programming Revisited, by Yoshida and Vasconcelos.

6

slide-11
SLIDE 11

/27

How Best To Represent Session Types Calculi?

Logical framework LF Constructive FOL
 +
 Induction Contextual types

7

slide-12
SLIDE 12

/27

Nominal Equation Logic

How Best To Represent Session Types Calculi?

Constructive FOL
 +
 Induction

7

slide-13
SLIDE 13

/27

But, Really? Another Proof Assistant?

8

slide-14
SLIDE 14

/27

But, Really? Another Proof Assistant?

  • What if we relax the requirement for


α-conversion?

8

slide-15
SLIDE 15

/27

But, Really? Another Proof Assistant?

  • What if we relax the requirement for


α-conversion?

  • Work by Ernesto Copello, Maribel Fernandez, et al.
  • Defines a notion of α-compatible relations.
  • Defines a notion of α-structural induction.

8

slide-16
SLIDE 16

/27

But, Really? Another Proof Assistant?

  • What if we relax the requirement for


α-conversion?

  • Work by Ernesto Copello, Maribel Fernandez, et al.
  • Defines a notion of α-compatible relations.
  • Defines a notion of α-structural induction.

It can be readily implemented in Agda and Coq!

8

slide-17
SLIDE 17

/27

But, Really? Another Proof Assistant?

  • What if we relax the requirement for


α-conversion?

  • Work by Ernesto Copello, Maribel Fernandez, et al.
  • Defines a notion of α-compatible relations.
  • Defines a notion of α-structural induction.

It can be readily implemented in Agda and Coq! Induction on judgments is still an “it should be possible” problem in this approach.

8

slide-18
SLIDE 18

/27

Time To Consider Existing Solutions

  • Well established work on Locally Nameless:
  • Use names for free variables.
  • Use indices for bound variables.
  • Mediate between them with open & close
  • perations.

9

slide-19
SLIDE 19

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t

10

slide-20
SLIDE 20

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t

10

slide-21
SLIDE 21

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t

10

slide-22
SLIDE 22

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t

10

slide-23
SLIDE 23

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

10

slide-24
SLIDE 24

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

  • k E

(x : T) ∈ E E ⊢ fvar x : T

typing-var

E ⊢ t1 : T1 → T2 E ⊢ t2 : T1 E ⊢ app t1 t2 : T2

typing-app

∀ x ̸∈ L, E, x : T1 ⊢ t x : T2 E ⊢ abs t : T1 → T2

typing-abs

10

slide-25
SLIDE 25

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

  • k E

(x : T) ∈ E E ⊢ fvar x : T

typing-var

E ⊢ t1 : T1 → T2 E ⊢ t2 : T1 E ⊢ app t1 t2 : T2

typing-app

∀ x ̸∈ L, E, x : T1 ⊢ t x : T2 E ⊢ abs t : T1 → T2

typing-abs

10

slide-26
SLIDE 26

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

  • k E

(x : T) ∈ E E ⊢ fvar x : T

typing-var

E ⊢ t1 : T1 → T2 E ⊢ t2 : T1 E ⊢ app t1 t2 : T2

typing-app

∀ x ̸∈ L, E, x : T1 ⊢ t x : T2 E ⊢ abs t : T1 → T2

typing-abs

10

slide-27
SLIDE 27

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

  • k E

(x : T) ∈ E E ⊢ fvar x : T

typing-var

E ⊢ t1 : T1 → T2 E ⊢ t2 : T1 E ⊢ app t1 t2 : T2

typing-app

∀ x ̸∈ L, E, x : T1 ⊢ t x : T2 E ⊢ abs t : T1 → T2

typing-abs

10

slide-28
SLIDE 28

/27

STLC

t :=

bvar x

|

fvar p

|

abs x t

|

app t t t x ≡ {0 → x} t

\xt

≡ {0 ← x} t

  • k E

(x : T) ∈ E E ⊢ fvar x : T

typing-var

E ⊢ t1 : T1 → T2 E ⊢ t2 : T1 E ⊢ app t1 t2 : T2

typing-app

∀ x ̸∈ L, E, x : T1 ⊢ t x : T2 E ⊢ abs t : T1 → T2

typing-abs

10

Open and close should admit several lemmas:

  • Opening locally closed terms does not change the

term

  • Opening and substitution commute
  • The interaction of opening and substitutions of

variables

slide-29
SLIDE 29

/27

The Send Receive System and its Cousins the Relaxed and the Revisited System.

11

slide-30
SLIDE 30

/27

The Send Receive System and its Cousins the Relaxed and the Revisited System.

Start developing the infrastructure and eventually move on to MPST

11

slide-31
SLIDE 31

/27

A Tale of Three Systems

  • We set out to represent the three systems described

in the paper:

  • The Honda, Vasconcelos, Kubo system from ESOP’98
  • Its naïve but ultimately unsound extension
  • Its revised system inspired by Gay and Hole in Acta

Informatica

12

slide-32
SLIDE 32

/27

The Send Receive System

P ::= request a(k) in P session request | accept a(k) in P session acceptance | k![˜ e]; P data sending | k?(˜ x) in P data reception | k ✁ l; P label selection | k ✄ {l1 : P1[ ] · · · [ ]ln : Pn} label branching | throw k[k′]; P channel sending | catch k(k′) in P channel reception | if e then P else Q conditional branch | P | Q parallel composition | inact inaction | (νu)P name/channel hiding | def D in P recursion | X[˜ e˜ k] process variables e ::= c constant | e + e′ | e − e′ | e × e | not(e) | . . .

  • perators

D ::= X1(˜ x1˜ k1) = P1 and · · · and Xn(˜ xn˜ kn) = Pn declaration for recursion

13

slide-33
SLIDE 33

/27

The Send Receive System

P ::= request a(k) in P session request | accept a(k) in P session acceptance | k![˜ e]; P data sending | k?(˜ x) in P data reception | k ✁ l; P label selection | k ✄ {l1 : P1[ ] · · · [ ]ln : Pn} label branching | throw k[k′]; P channel sending | catch k(k′) in P channel reception | if e then P else Q conditional branch | P | Q parallel composition | inact inaction | (νu)P name/channel hiding | def D in P recursion | X[˜ e˜ k] process variables e ::= c constant | e + e′ | e − e′ | e × e | not(e) | . . .

  • perators

D ::= X1(˜ x1˜ k1) = P1 and · · · and Xn(˜ xn˜ kn) = Pn declaration for recursion

13

slide-34
SLIDE 34

/27

α-Conversion for Free

  • The original system depends crucially on names

(throw k[k′]; P1) | (catch k(k′) in P2) → P1 | P2

14

slide-35
SLIDE 35

/27

α-Conversion for Free

  • The original system depends crucially on names

(throw k[k′]; P1) | (catch k(k′) in P2) → P1 | P2

14

slide-36
SLIDE 36

/27

α-Conversion for Free

  • The original system depends crucially on names

(throw k[k′]; P1) | (catch k(k′) in P2) → P1 | P2

This is a bound variable.

14

slide-37
SLIDE 37

/27

α-Conversion for Free

  • The original system depends crucially on names

(throw k[k′]; P1) | (catch k(k′) in P2) → P1 | P2

This is a bound variable.

  • If α-conversion is built in, this rule collapses to:

(throw k[k′]; P1) | (catch k(k′′) in P2) → P1 | P2[k′/k′′]

14

slide-38
SLIDE 38

/27

α-Conversion for Free

  • The original system depends crucially on names

(throw k[k′]; P1) | (catch k(k′) in P2) → P1 | P2

This is a bound variable.

  • If α-conversion is built in, this rule collapses to:

(throw k[k′]; P1) | (catch k(k′′) in P2) → P1 | P2[k′/k′′]

14

Locally Nameless makes it impossible to express the

  • riginal system’s name

handling!

slide-39
SLIDE 39

/27

The Typing Judgement

The rule for parallel composition is where the fun begins:

15

slide-40
SLIDE 40

/27

The Typing Judgement

Θ; Γ ⊢ P ◃ ∆ Θ; Γ ⊢ Q ◃ ∆′ Θ; Γ ⊢ P | Q ◃ ∆ ◦ ∆′ (∆ ≍ ∆′) [Conc]

The rule for parallel composition is where the fun begins:

15

slide-41
SLIDE 41

/27

The Typing Judgement

Θ; Γ ⊢ P ◃ ∆ Θ; Γ ⊢ Q ◃ ∆′ Θ; Γ ⊢ P | Q ◃ ∆ ◦ ∆′ (∆ ≍ ∆′) [Conc]

The rule for parallel composition is where the fun begins:

15

slide-42
SLIDE 42

/27

The Typing Judgement

Θ; Γ ⊢ P ◃ ∆ Θ; Γ ⊢ Q ◃ ∆′ Θ; Γ ⊢ P | Q ◃ ∆ ◦ ∆′ (∆ ≍ ∆′) [Conc]

The rule for parallel composition is where the fun begins:

15

slide-43
SLIDE 43

/27

The Typing Judgement

Θ; Γ ⊢ P ◃ ∆ Θ; Γ ⊢ Q ◃ ∆′ Θ; Γ ⊢ P | Q ◃ ∆ ◦ ∆′ (∆ ≍ ∆′) [Conc]

The rule for parallel composition is where the fun begins:

Definition 2.4 (Type algebra) Typings ∆0 and ∆1 are compatible, written ∆0 ≍ ∆1, if ∆0(k) = ∆1(k) for all k ∈ dom(∆0) ∩ dom(∆1). When ∆0 ≍ ∆1, the com- position of ∆0 and ∆1, written ∆0 ◦ ∆1, is given as a typing such that (∆0 ◦ ∆1)(k) is (1) ⊥, if k ∈ dom(∆0) ∩ dom(∆1); (2) ∆i(k), if k ∈ dom(∆i) \ dom(∆i+1 mod 2) for i ∈ {0, 1}; and (3) undefined otherwise.

15

slide-44
SLIDE 44

/27

Typing Environments

16

slide-45
SLIDE 45

/27

Typing Environments

16

slide-46
SLIDE 46

/27

Typing Environments

16

slide-47
SLIDE 47

/27

Typing Environments

  • Store their assumptions in a unique order 


(easy to compare)

  • Only store unique assumptions 


(easy to split)

17

slide-48
SLIDE 48

/27

Typing Environments

  • Store their assumptions in a unique order 


(easy to compare)

  • Only store unique assumptions 


(easy to split)

This together requires implementing our

  • wn LN infrastructure.

But it allows for names and linearity.

17

slide-49
SLIDE 49

/27

The Revisited System

  • Now we distinguish between the endpoints of

channels.

  • It can be represented with LN-variables and

names.

18

slide-50
SLIDE 50

/27

Two Kinds of Atoms

19

slide-51
SLIDE 51

/27

Two Kinds of Atoms

19

slide-52
SLIDE 52

/27

Channels and Expressions

20

slide-53
SLIDE 53

/27

Channels and Expressions

20

slide-54
SLIDE 54

/27

Channels and Expressions

20

slide-55
SLIDE 55

/27

Processes

21

Binders are “invisible”

slide-56
SLIDE 56

/27

Processes

21

Binders are “invisible”

slide-57
SLIDE 57

/27

Processes

21

Binders are “invisible”

slide-58
SLIDE 58

/27

Processes

21

Binders are “invisible”

slide-59
SLIDE 59

/27

But Mechanical Proofs Are..

  • Well, very mechanical. We have to be very precise

with the theorems.

22

The typing judgements:

slide-60
SLIDE 60

/27

One of the Substitution Lemmas

Lemma 3.1 (Channel Replacement) If Θ; Γ ⊢ P◃∆·x: α, then Θ; Γ ⊢ P[κp/x]◃ ∆ · κp : α.

  • Proof. A straightforward induction on the derivation tree for P.

23

slide-61
SLIDE 61

/27

One of the Substitution Lemmas

Lemma 3.1 (Channel Replacement) If Θ; Γ ⊢ P◃∆·x: α, then Θ; Γ ⊢ P[κp/x]◃ ∆ · κp : α.

  • Proof. A straightforward induction on the derivation tree for P.

Becomes:

23

slide-62
SLIDE 62

/27

One of the Substitution Lemmas

Lemma 3.1 (Channel Replacement) If Θ; Γ ⊢ P◃∆·x: α, then Θ; Γ ⊢ P[κp/x]◃ ∆ · κp : α.

  • Proof. A straightforward induction on the derivation tree for P.

Becomes:

23

slide-63
SLIDE 63

/27

One of the Substitution Lemmas

Lemma 3.1 (Channel Replacement) If Θ; Γ ⊢ P◃∆·x: α, then Θ; Γ ⊢ P[κp/x]◃ ∆ · κp : α.

  • Proof. A straightforward induction on the derivation tree for P.

Becomes:

23

slide-64
SLIDE 64

/27

One of the Substitution Lemmas

Lemma 3.1 (Channel Replacement) If Θ; Γ ⊢ P◃∆·x: α, then Θ; Γ ⊢ P[κp/x]◃ ∆ · κp : α.

  • Proof. A straightforward induction on the derivation tree for P.

Becomes: Coq also demanded to be convinced about substituting expressions and various weakening lemmas

23

slide-65
SLIDE 65

/27

Subject Reduction

Theorem 3.3 (Subject Reduction) If Θ; Γ ⊢ P ◃ ∆ with ∆ balanced and P →∗ Q, then Θ; Γ ⊢ Q ◃ ∆′ and ∆′ balanced.

24

slide-66
SLIDE 66

/27

Subject Reduction

Theorem 3.3 (Subject Reduction) If Θ; Γ ⊢ P ◃ ∆ with ∆ balanced and P →∗ Q, then Θ; Γ ⊢ Q ◃ ∆′ and ∆′ balanced.

Is straightforward to represent:

24

slide-67
SLIDE 67

/27

And Lots of Fun To Prove

25

slide-68
SLIDE 68

/27

And Lots of Fun To Prove

25

slide-69
SLIDE 69

/27

And Lots of Fun To Prove

25

slide-70
SLIDE 70

/27

And Lots of Fun To Prove

25

slide-71
SLIDE 71

/27

And Lots of Fun To Prove

25

slide-72
SLIDE 72

/27

And Lots of Fun To Prove

25

slide-73
SLIDE 73

/27

And Lots of Fun To Prove

25

slide-74
SLIDE 74

/27

Finally:

26

slide-75
SLIDE 75

/27

What We Have:

  • The definition two systems, the unsound proved with a

counter example, and the revised with a proof by induction.

  • There are still some lemmas to prove (≈4.5 KLOC so far).
  • All using a locally nameless representation
  • Some use ssreflect and overloaded-lemmas to simply proofs.
  • More automation using overloaded-lemmas in the future.

27

slide-76
SLIDE 76

/27

What We Have:

  • The definition two systems, the unsound proved with a

counter example, and the revised with a proof by induction.

  • There are still some lemmas to prove (≈4.5 KLOC so far).
  • All using a locally nameless representation
  • Some use ssreflect and overloaded-lemmas to simply proofs.
  • More automation using overloaded-lemmas in the future.

Thanks for your attention. Questions?

27