Intersections and Unions of Session Types Co¸ sku Acay Frank Pfenning Carnegie Mellon University School of Computer Science ITRS 2016 C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 1 / 35
Overview Background 1 Message-passing Concurrency Session Types Subtyping Configurations and Reduction Intersections and Unions 2 Intersection Types Union Types Reinterpreting Choice Algorithmic System 3 Metatheory 4 C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 2 / 35
Plan Background 1 Message-passing Concurrency Session Types Subtyping Configurations and Reduction Intersections and Unions 2 Intersection Types Union Types Reinterpreting Choice Algorithmic System 3 Metatheory 4 C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 3 / 35
Setting Processes represented as nodes Channels go between processes and represented as edges Each channel is “provided” by a specific process (e.g. P provides c , Q provides d etc.): one-to-one correspondence between channels and processes T g c d e Q P R f S C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 4 / 35
Communication Processes compute internally Exchange messages along channels c d e Q P R
Communication Processes compute internally Exchange messages along channels c d e Q P R 3
Communication Processes compute internally Exchange messages along channels c d e Q P R 3 end " aaa "
Communication Processes compute internally Exchange messages along channels c d e Q P R 3 end " aaa " ∗ Note that communication is synchronous. C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 5 / 35
Higher-order Messages Processes can also send channels they own R e c d e Q P R
Higher-order Messages Processes can also send channels they own R e c d e Q P R e
Higher-order Messages Processes can also send channels they own R e c d e Q P R e C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 6 / 35
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 7 / 35
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 7 / 35
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 7 / 35
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). d : int ⊃ string ∧ B d : string ∧ B c : A d : B e : 1 P Q R
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). d : int ⊃ string ∧ B d : string ∧ B c : A d : B e : 1 P Q R 3
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). d : int ⊃ string ∧ B d : string ∧ B c : A d : B e : 1 P Q R 3 " aaa "
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). d : int ⊃ string ∧ B d : string ∧ B c : A d : B e : 1 P Q R 3 end " aaa "
Session Types Don’t want to send int if expecting string Don’t try to receive if other process is not sending Solution: Assign types to each channel (from provider’s perspective). d : int ⊃ string ∧ B d : string ∧ B c : A d : B e : 1 P Q R 3 end " aaa " C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 7 / 35
Why linear? Sessions are resources: communicating along a channel consumes the old type Contraction would violate type safety Weakening would work, but we keep things simple C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 8 / 35
Linear Propositions as Session Types 1 send end and terminate A ⊗ B send channel of type A and continue as B τ ∧ B send value of type τ and continue as B ⊕{ lab k : A k } k ∈ I send lab i and continue as A i for some i ∈ I A ⊸ B receive channel of type A and continue as B τ ⊃ B receive value of type τ and continue as B & { lab k : A k } k ∈ I receive lab i and continue as A i for some i ∈ I µ t . A t (equi-)recursive type C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 9 / 35
Linear Propositions as Session Types 1 send end and terminate A ⊗ B send channel of type A and continue as B τ ∧ B send value of type τ and continue as B ⊕{ lab k : A k } k ∈ I send lab i and continue as A i for some i ∈ I A ⊸ B receive channel of type A and continue as B τ ⊃ B receive value of type τ and continue as B & { lab k : A k } k ∈ I receive lab i and continue as A i for some i ∈ I µ t . A t (equi-)recursive type Example: Queue Interface type queue = &{ enq : A -o queue , deg : +{none : 1, some : A * queue} } C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 9 / 35
Proof Terms as Concurrent Processes P , Q , R ::= x ← P x ; Q x cut (spawn) c ← d id (forward) close c | wait c ; P 1 A ⊗ B , A ⊸ B send c ( y ← P y ) ; Q | x ← recv c ; R x c . lab ; P | case c of { lab k → Q k } k ∈ I & { lab k : A k } k ∈ I , ⊕{ lab k : A k } k ∈ I C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 10 / 35
Example: An Implementation of Queues type queue = &{ enq : A -o queue , deg : +{none : 1, some : A * queue} } empty : queue q <- empty = case q of enq -> x <- recv q; e <- empty; q <- elem x e deq -> q.none; close q elem : A -o queue -o queue q <- elem x r = case q of enq -> y <- recv q; r.enq; send r y; q <- elem x r deq -> q.some; send q x; q <- r C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 11 / 35
Process Typing Typing judgement has the form Ψ ⊢ η P :: ( c : A ) meaning “process P offers along channel c the session A under the context Ψ.” η tracks recursive variables. C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 12 / 35
Process Typing Typing judgement has the form Ψ ⊢ η P :: ( c : A ) meaning “process P offers along channel c the session A under the context Ψ.” η tracks recursive variables. Some examples: c : A ⊢ d ← c :: ( d : A ) id Ψ ′ , c : A ⊢ Q c :: ( d : D ) Ψ ⊢ P c :: ( c : A ) cut Ψ , Ψ ′ ⊢ c ← P c ; Q c :: ( d : D ) Ψ ⊢ P :: ( d : A ) ∅ ⊢ close c :: ( c : 1 ) 1 R Ψ , c : 1 ⊢ wait c ; P :: ( d : A ) 1 L Ψ ′ ⊢ Q :: ( c : B ) Ψ ⊢ P :: ( d : A ) Ψ , Ψ ′ ⊢ send c ( d ← P d ) ; Q :: ( c : A ⊗ B ) ⊗ R C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 12 / 35
Subtyping Width and depth subtyping for n -ary choices Width: & { lab k : A k } k ∈ I ≤ & { lab k : A k } k ∈ J whenever J ⊆ I Depth: & { lab k : A k } k ∈ I ≤ & { lab k : A ′ k } k ∈ I whenever A i ≤ A ′ i C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 13 / 35
Subtyping Width and depth subtyping for n -ary choices Width: & { lab k : A k } k ∈ I ≤ & { lab k : A k } k ∈ J whenever J ⊆ I Depth: & { lab k : A k } k ∈ I ≤ & { lab k : A ′ k } k ∈ I whenever A i ≤ A ′ i Defined coinductively because of recursive types C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 13 / 35
Subtyping Width and depth subtyping for n -ary choices Width: & { lab k : A k } k ∈ I ≤ & { lab k : A k } k ∈ J whenever J ⊆ I Depth: & { lab k : A k } k ∈ I ≤ & { lab k : A ′ k } k ∈ I whenever A i ≤ A ′ i Defined coinductively because of recursive types Introduced to process typing using subsumption: A ′ ≤ A Ψ ⊢ η P :: ( c : A ′ ) SubR Ψ ⊢ η P :: ( c : A ) Ψ , c : A ′ ⊢ η P :: ( d : B ) A ≤ A ′ SubL Ψ , c : A ⊢ η P :: ( d : B ) C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 13 / 35
Configurations A processes by itself is not very useful in concurrent setting Need to be able to talk about interactions C. Acay & F. Pfenning (CMU) Intersections and Unions of Session Types ITRS 2016 14 / 35
Recommend
More recommend