Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependent Session Types

Hanwen Wu
December 11, 2017

Dependent Session Types

IBM PL Day 2017

Hanwen Wu

December 11, 2017
Tweet

More Decks by Hanwen Wu

Other Decks in Research

Transcript

  1. Sending an Array Server send(sock, len) loop(sock, arr, 0, len)

    wait(sock) Client len = recv(sock) arr = malloc(len) loop(sock, arr, 0, len) close(sock)
  2. Sending an Array, Untyped Server send(sock, len) loop(sock, arr, 0,

    len) wait(sock) Client len = recv(sock) arr = malloc(len) loop(sock, arr, 0, len) close(sock) The socket is untyped. What could go wrong?
  3. Sending an Array, Simple Server send(len) loop(len) wait Client recv

    malloc loop(len) close The socket is typed using simple session types. Linear types guarantee correct order and no leak. What else could go wrong? msg(S,int)::repeat(n, msg(S,int))::end(C) repeat(n, msg(S,int))::end(C) send(socket, payload) recv(socket)
  4. Sending an Array, Dependent Server send(len) loop(len) wait Client recv

    malloc loop(len) close quan(S,n:int.msg(S,int(n))::repeat(n,... ∀n:int.msg(S,int(n))::repeat(n,… forall(socket) ∃n:int.msg(S,int(n))::repeat(n,… exists(socket) The socket is typed using dependent session types. Nothing could go wrong.
  5. Sending an Array, Dependent Server forall(sock) loop(sock, arr, 0, len)

    wait(sock) Client len = recv(sock) arr = malloc(len) loop(sock, arr, 0, len) close(sock) send(sock, len) exists(sock) unroll(sock) unroll(sock)
  6. Show Me the Code rpt(n,s) := fix(n,f:int→stype.n:int.ite(n>0,s::f(n-1),end(1))) proto := quan(S,n:int.msg(S,int(n))::rpt(n,msg(S,int)))

    server ∀n.int (ch:sock(S,proto), arr:int[n], len:int(n)) = let loop ∀m.int,m≤n (ch:sock(S,rpt(m,msg(S,int))), x:int(m)) = if x = 0 then unroll(ch); ite_false(ch); close(ch) else unroll(ch); ite_true(ch); send(ch,arr[len-x]) loop(ch,x-1) in forall(ch); send(ch,len); loop(ch,len) end
  7. Takeaway untyped sockets • runtime errors • hard to debug

    • deadlock • resource leak simple session types • type errors • correct use of sockets • deadlock-free • no leak dependent session types • more expressive • quantifiers • recursions • polymorphic sessions
  8. Even More Implementations Erlang, C, Javascript Logic Foundation Multirole Logic,

    Cut-Free Multiparty Sessions Formulatation Lambda Calculus + Some Bi-directional Forwarding Multi-directional Forwarding Used in Classrooms Proof of Deadlock-Freeness Higher-order Sessions
  9. learn more at multirolelogic.org Thank you! Hanwen Wu and Hongwei

    Xi Dec 2017, IBM Programming Language Day