chaperone contracts for higher order sessions
play

Chaperone Contracts for Higher-Order Sessions Hernn Melgratti, - PowerPoint PPT Presentation

Chaperone Contracts for Higher-Order Sessions Hernn Melgratti, Buenos Aires, Argentina Luca Padovani, Torino, Italy Dagstuhl Seminar 17051, 2017 A simple FuSe program let server ep = let p, ep = receive ep in let root = ... in let ep = send


  1. Chaperone Contracts for Higher-Order Sessions Hernán Melgratti, Buenos Aires, Argentina Luca Padovani, Torino, Italy Dagstuhl Seminar 17051, 2017

  2. A simple FuSe program let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server

  3. A simple FuSe program let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server let user () = let ep = connect math_service in let ep = send (from_list [2.0; -3.0; 1.0]) ep in let _, ep = receive ep in close ep

  4. A simple FuSe program + Contracts let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server contract "Server" let user () = let ep = connect math_service "Client" in let ep = send (from_list [2.0; -3.0; 1.0]) ep in let _, ep = receive ep in close ep

  5. Contracts ◮ A contract is a term that describes exchanged messages and their relationships. flat _ c : ( t → bool ) → [ t ] t :: ω end _ c : [end] send _ c : [ t ] → [ T ] → [! t . T ] receive _ c : [ t ] → [ T ] → [? t . T ] send _ d : [ t ] → ( t → [ T ] ) → [! t . T ] t :: ω receive _ d : [ t ] → ( t → [ T ] ) → [? t . T ] t :: ω

  6. Contracts let contract = send_c (flat_c (fun p → degree p == 1)) @@ ... (* contract for the continuation *)

  7. Contracts let contract = send_c (flat_c (fun p → degree p == 1)) @@ any_c (* contract for the continuation *)

  8. Contracts let contract = send_d (flat_c (fun p → degree p == 1)) @@ fun p → receive_c (flat_c (root_of p)) @@ end_c

  9. Contracts and the structure of the session choice _ c : [bool] → [ T ] → [ S ] → [ T ⊕ S ] branch _ c : [bool] → [ T ] → [ S ] → [ T & S ]

  10. Contracts and the structure of the session ep : !poly.rec A .(?float. A & end)

  11. Contracts and the structure of the session ep : !poly.rec A .(?float. A & end) let contract = send_d (flat_c (fun p → degree p > 0)) @@ fun p → let rec missing_roots n = if n > 0 then branch_c any_c (receive_c (flat_c (root_of p)) @@ missing_roots (n - 1)) end_c else branch_c (flat_c not) any_c end_c in missing_roots (degree p)

  12. First order y [ v 1 , v 2 ] Source Operator User x [ v 1 , v 2 ] y [ w ] x : ?int.?int.end y : !int.!int.?int.end

  13. First order y [ v 1 , v 2 ] Source Operator User x [ v 1 , v 2 ] y [ w ] x : ?int.?int.end y : !int.!int.?int.end op_c = send_c any_c @@ src_c = any_c send_c (flat_c ( � = 0)) @@ receive_c (flat_c ( ≥ 0)) @@ end_c

  14. Second order x [ v 1 , v 2 ] Source Operator y [ x ] User x y [ w ] x : ?int.?int.end y : !(?int.?int.end).?int.end

  15. Second order x [ v 1 , v 2 ] Source Operator y [ x ] User x y [ w ] x : ?int.?int.end y : !(?int.?int.end).?int.end op_c = send_c d_c @@ receive_c (flat_c ( ≥ 0)) @@ end_c src_c = any_c d_c = receive_c any_c @@ receive_c (flat_c ( � = 0)) @@ end_c

  16. Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]  �E [ [ s + ] c ,q,p ] �      �E [ connect a p ] �  | a ⇐ c  → ( νs ) q v     � ( v [ s - ] dual c ,p,q ) �  a ⇐ c    q v s fresh

  17. Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]  �E [ [ s + ] c ,q,p ] �      �E [ connect a p ] �  | a ⇐ c  → ( νs ) q v     � ( v [ s - ] dual c ,p,q ) �  a ⇐ c    q v s fresh  �E [ send v [ a ι ] ! c ; d ,σ ] �  �E [ [ a ι ] d ,σ ] �      →     �E ′ [ receive [ a ι ] ? e ; f ,̺ ] �    �E ′ [ ([[ v ] c , ¬ σ ] e ,̺ ,[ a ι ] f ,̺ ) ] �  

  18. Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]  �E [ [ s + ] c ,q,p ] �      �E [ connect a p ] �  | a ⇐ c  → ( νs ) q v     � ( v [ s - ] dual c ,p,q ) �  a ⇐ c    q v s fresh  �E [ send v [ a ι ] ! c ; d ,σ ] �  �E [ [ a ι ] d ,σ ] �      →     �E ′ [ receive [ a ι ] ? e ; f ,̺ ] �    �E ′ [ ([[ v ] c , ¬ σ ] e ,̺ ,[ a ι ] f ,̺ ) ] �   v ⊳ p wv [ v ] flat _ c w,p,q →

  19. Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]  �E [ [ s + ] c ,q,p ] �      �E [ connect a p ] �  | a ⇐ c  → ( νs ) q v     � ( v [ s - ] dual c ,p,q ) �  a ⇐ c    q v s fresh  �E [ send v [ a ι ] ! c ; d ,σ ] �  �E [ [ a ι ] d ,σ ] �      →     �E ′ [ receive [ a ι ] ? e ; f ,̺ ] �    �E ′ [ ([[ v ] c , ¬ σ ] e ,̺ ,[ a ι ] f ,̺ ) ] �   v ⊳ p wv [ v ] flat _ c w,p,q → v ⊳ p true → v v ⊳ p false → blame p

  20. Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]  �E [ send v [ a ι ] ! c ; d ,σ ] �   �E [ [ a ι ] d ,σ ] �    →        �E ′ [ receive [ a ι ] ? e ; f ,̺ ] �    �E ′ [ ([[ v ] c , ¬ σ ] e ,̺ ,[ a ι ] f ,̺ ) ] �    

  21. Locally correctness & blame safety ◮ p is locally correct in P if ◮ P = P p [ send v [_] ! flat _ c w ;_ , _ , _ ] implies v ∈ w , and ◮ P = P p [ send [ ε ] c , _ , _ [_] ! d ;_ , _ , _ ] implies c � d, and ... ◮ P → Q implies p is locally correct in Q

  22. Locally correctness & blame safety ◮ p is locally correct in P if ◮ P = P p [ send v [_] ! flat _ c w ;_ , _ , _ ] implies v ∈ w , and ◮ P = P p [ send [ ε ] c , _ , _ [_] ! d ;_ , _ , _ ] implies c � d, and ... ◮ P → Q implies p is locally correct in Q ◮ Useful invariant: If P → ∗ P p [ send v [_] c , _ ,q ] , then q = p

  23. Locally correctness & blame safety ◮ p is locally correct in P if ◮ P = P p [ send v [_] ! flat _ c w ;_ , _ , _ ] implies v ∈ w , and ◮ P = P p [ send [ ε ] c , _ , _ [_] ! d ;_ , _ , _ ] implies c � d, and ... ◮ P → Q implies p is locally correct in Q ◮ Useful invariant: If P → ∗ P p [ send v [_] c , _ ,q ] , then q = p ◮ Blame safety: p is locally correct in P , then P → ∗ Q implies blame p �⊂ Q .

  24. Final remarks ◮ The language is implemented on top of FuSe ◮ It avoids double checking of contracts ◮ It relies on a small-step semantics for unwinding monitors ◮ Monitors are communicated only when delegating ◮ Communication is restricted to unlimited values and delegation

Recommend


More recommend