Top Banner

Click here to load reader

22

Refinements for Session-typed Concurrency · PDF file Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1

Aug 01, 2020

ReportDownload

Documents

others

  • Refinements for Session-typed Concurrency

    Josh Acay & Frank Pfenning

    1May 4, 2016

  • Message-passing Concurrency

    • Processes represented as nodes • Channels between processes as edges • Each channel is “provided” by a specific process (P provides c, Q provides d etc.)

    P c

    Q d

    R e

    2May 4, 2016

  • Message-passing Concurrency

    • Processes compute internally • Exchange messages along channels

    P c

    Q d

    R e

    3May 4, 2016

  • Message-passing Concurrency

    • Processes compute internally • Exchange messages along channels

    P c

    Q d

    R e

    3

    3May 4, 2016

  • Message-passing Concurrency

    • Processes compute internally • Exchange messages along channels

    P c

    Q d

    R e

    3

    “aaa”

    3May 4, 2016

  • Message-passing Concurrency

    • Processes compute internally • Exchange messages along channels

    P c

    Q d

    R e

    3

    “aaa”

    end

    3May 4, 2016

  • Message-passing Concurrency

    • Processes compute internally • Exchange messages along channels

    P c

    Q d

    3

    “aaa”

    3May 4, 2016

  • Message-passing Concurrency

    • Processes can also send channels they own

    P c

    Q d

    R e

    4May 4, 2016

  • Message-passing Concurrency

    • Processes can also send channels they own

    P c

    Q d

    R e

    e

    4May 4, 2016

  • Message-passing Concurrency

    • Processes can also send channels they own

    P c

    Q d

    e

    R e

    4May 4, 2016

  • Linear Session-types

    • Don’t want to send int if expecting string • Don’t try to receive if other process is not sending

    • Assign types to each channel from provider’s perspective

    P c : B

    Q d : int ⊃ string ∧ A

    R e : 1

    5May 4, 2016

  • Linear Session-types

    • Don’t want to send int if expecting string • Don’t try to receive if other process is not sending

    • Assign types to each channel from provider’s perspective

    P c : B

    Q 3

    R e : 1d : string ∧ A

    5May 4, 2016

  • Linear Session-types

    • Don’t want to send int if expecting string • Don’t try to receive if other process is not sending

    • Assign types to each channel from provider’s perspective

    P c : B

    Q 3

    “aaa”

    R e : 1d : A

    5May 4, 2016

  • Linear Session-types

    • Don’t want to send int if expecting string • Don’t try to receive if other process is not sending

    • Assign types to each channel from provider’s perspective

    P c : B

    Q 3

    “aaa” end

    R e : 1d : A

    5May 4, 2016

  • Linear Session-types

    • Don’t want to send int if expecting string • Don’t try to receive if other process is not sending

    • Assign types to each channel from provider’s perspective

    P c : B

    Q 3

    “aaa”

    d : A

    5May 4, 2016

  • Linear Session Types

    • Example interface specification:

    1 Terminate &{labi:Ai}i External choice (receive) between labi, continue as Ai A –o B Receive channel of type A, continue as B τ ⊃ B Receive value of type τ, continue as B ⊕{labi:Ai}i Internal choice (send) between labi, continue as Ai A ⊗ B Send channel of type A, continue as B τ ∧ B Send value of type τ, continue as B

    queue = &{enq: A –o queue, deq: ⊕{none: 1, some: A ⊗ queue}}

    * where A is some predetermined type

    6May 4, 2016

  • Implementation of Queues queue = &{enq: A –o queue, deq: ⊕{none: 1, some: A ⊗ queue}}

    empty : queue q ← empty = case q 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 enq " y ← recv q ; r.enq ; send r y ; q ← elem x r deq " q.some ; send q x ; q ← r

    7May 4, 2016

  • Intersections and Unions

    • Allows describing more interesting behavior • Intersection of two types: A ⊓ B – c : A ⊓ B if channel c offers both behaviors

    • Union of two types: A ⊔ B – c : A ⊔ B if channel c offers either behavior

    8May 4, 2016

  • Refinement Types

    • What if we want to track more properties of queues? Empty, non-empty, even length?

    • We can define them in the base system:

    empty-queue = &{enq: A –o nonempty-queue, deq: ⊕{none: 1}}

    nonempty-queue = &{enq: A –o nonempty-queue, deq: ⊕{some: A ⊗ queue}}

    9May 4, 2016

  • Refinement Types

    • But we need intersections and unions to write interesting programs

    queue A = empty-queue ⊔ nonempty-queue

    empty : empty-queue

    elem : (A –o queue –o nonempty-queue)

    concat : (empty-queue –o empty-queue –o empty-queue) ⊓ (queue –o nonempty-queue –o nonempty-queue) ⊓ (nonempty-queue –o queue –o nonempty-queue)

    10May 4, 2016

  • Decidability of Type-checking

    • Algorithmic system that is easy to translate to code

    • Prove sound and complete with respect to the original system

    • Partial implementation in Haskell

    11May 4, 2016

  • Type Safety

    • Progress – Deadlock freedom in concurrent setting – At least one process can make progress if the configuration is well-typed

    • Preservation [currently in progress] – Session fidelity in concurrent setting – Processes obey session-types

    12May 4, 2016

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.