intersections and unions of session types
play

Intersections and Unions of Session Types Co sku Acay Frank - PowerPoint PPT Presentation

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


  1. 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

  2. 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

  3. 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

  4. 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

  5. Communication Processes compute internally Exchange messages along channels c d e Q P R

  6. Communication Processes compute internally Exchange messages along channels c d e Q P R 3

  7. Communication Processes compute internally Exchange messages along channels c d e Q P R 3 end " aaa "

  8. 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

  9. Higher-order Messages Processes can also send channels they own R e c d e Q P R

  10. Higher-order Messages Processes can also send channels they own R e c d e Q P R e

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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 "

  18. 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 "

  19. 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

  20. 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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

  27. 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

  28. 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

  29. 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

  30. 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend