gradual session types
play

Gradual Session Types Albert-Ludwigs-Universit at Freiburg Atsushi - PowerPoint PPT Presentation

Gradual Session Types Albert-Ludwigs-Universit at Freiburg Atsushi Igarashi 1 Peter Thiemann 2 Vasco Vasconcelos 3 1 Kyoto University, 2 University of Freiburg, 3 University of Lisbon 31 Jan 2017 Session Types are Good for You communication


  1. Gradual Session Types Albert-Ludwigs-Universit¨ at Freiburg Atsushi Igarashi 1 Peter Thiemann 2 Vasco Vasconcelos 3 1 Kyoto University, 2 University of Freiburg, 3 University of Lisbon 31 Jan 2017

  2. Session Types are Good for You communication on typed channels bidirectional and heterogeneous type safety and communication safety (scalable to multi-session) (deadlock freedom) Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 2 / 19

  3. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  4. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  5. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  6. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  7. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  8. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  9. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  10. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  11. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  12. Example: CurrenCy Conversion Protocol Client Perspective, fully session typed cccp = ! CCY . ! Double . cccp-loop cccp-loop = & { MORE : ? CCY . ? Double . cccp-loop , EXIT : end } Send a currency abbreviation { element of enumeration type } Send an amount while received MORE do Receive a currency abbreviation Receive an amount received EXIT Close the channel Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 3 / 19

  13. A CCCP Server Switch of perspective Let’s look at a SERVER Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 4 / 19

  14. A CCCP Server Switch of perspective Let’s look at a SERVER Suppose the first part (before the loop) is typed, but the loop is written in an untyped language. Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 4 / 19

  15. A CCCP Server Switch of perspective Let’s look at a SERVER Suppose the first part (before the loop) is typed, but the loop is written in an untyped language. Gradual typing provides the protective interface via casts Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 4 / 19

  16. Excursion: Gradual Typing Simply-Typed Lambda Calculus T , U ::= B | T → U | T × U Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  17. Excursion: Gradual Typing Gradual Lambda Calculus T , U ::= B | T → U | T × U | ? ? ? any simple type Extended with type dynamic ? ? ? Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  18. Excursion: Gradual Typing Simply-Typed Lambda Calculus with Sessions (Mini-GV) T , U ::= S | B | T → U | T × U R , S ::= end | ! T . S | ? T . S Extended with session types Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  19. Excursion: Gradual Typing Gradual Lambda Calculus with Sessions (Mini-GV) T , U ::= S | B | T → U | T × U | ? ? ? any simple type � ? R , S ::= end | ! T . S | ? T . S | ? ? any session type � Extended with type dynamic ? ? and dynamic session ? ? ? ? Extended with session types Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  20. Excursion: Gradual Typing Gradual Lambda Calculus with Sessions (Mini-GV) T , U ::= S | B | T → U | T × U | ? ? ? any simple type � ? R , S ::= end | ! T . S | ? T . S | ? ? any session type � Extended with type dynamic ? ? and dynamic session ? ? ? ? Extended with session types Mediated by explicit casts M : T ⇒ U Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  21. Excursion: Gradual Typing Gradual Lambda Calculus with Sessions (Mini-GV) T , U ::= S | B | T → U | T × U | ? ? ? any simple type � ? R , S ::= end | ! T . S | ? T . S | ? ? any session type � Extended with type dynamic ? ? ? and dynamic session ? ? ? Extended with session types Mediated by explicit casts M : T ⇒ U Complication: session types are linear Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 5 / 19

  22. Example CCCP Server with Gradual Typing Barrier # typed part def cccp_server (c: CCCP ): (ccy , c) = receive (c) (amt , c) = receive (c) amt = toEUR(ccy , amt) # normalize to EUR exchange_rates (CAST(amt : Double => ?), CAST(c : CCCP -LOOP => ?)) # untyped part def exchange_rates (amt , c): for cy , r in available_rates (): sendDyn (True , c) sendDyn (cy , c) sendDyn (r * amt , c) else: sendDyn (False , c) Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 6 / 19

  23. What Can Go Wrong def exchange_rates (amt , c): for cy , r in available_rates (): sendDyn (True , c) # MORE sendDyn (cy , c) # cy sendDyn (r * amt , c) # c else: sendDyn (False , c) # EXIT Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 7 / 19

  24. What Can Go Wrong Encoding of MORE = 1 ? def exchange_rates (amt , c): for cy , r in available_rates (): sendDyn (True , c) # MORE sendDyn (cy , c) # cy sendDyn (r * amt , c) # c else: sendDyn (False , c) # EXIT Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 7 / 19

  25. What Can Go Wrong Encoding of MORE = 1 ? def exchange_rates (amt , c): for cy , r in available_rates (): Number between 1 and N? sendDyn (True , c) # MORE sendDyn (cy , c) # cy sendDyn (r * amt , c) # c else: sendDyn (False , c) # EXIT Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 7 / 19

  26. What Can Go Wrong Encoding of MORE = 1 ? def exchange_rates (amt , c): for cy , r in available_rates (): Number between 1 and N? sendDyn (True , c) # MORE Uncoordinated use of channel sendDyn (cy , c) # cy sendDyn (r * amt , c) # c else: sendDyn (False , c) # EXIT Igarashi, Thiemann, Vasconcelos Gradual Session Types 31 Jan 2017 7 / 19

Recommend


More recommend