refinements for session-typed concurrency · refinements for session-typed concurrency josh acay...
TRANSCRIPT
![Page 1: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/1.jpg)
RefinementsforSession-typedConcurrency
JoshAcay&FrankPfenning
1May4,2016
![Page 2: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/2.jpg)
Message-passingConcurrency
• Processesrepresentedasnodes• Channelsbetweenprocessesasedges• Eachchannelis“provided”byaspecificprocess(Pprovidesc,Qprovidesdetc.)
Pc
Qd
Re
2May4,2016
![Page 3: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/3.jpg)
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3May4,2016
![Page 4: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/4.jpg)
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
3May4,2016
![Page 5: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/5.jpg)
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
“aaa”
3May4,2016
![Page 6: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/6.jpg)
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
“aaa”
end
3May4,2016
![Page 7: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/7.jpg)
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
3
“aaa”
3May4,2016
![Page 8: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/8.jpg)
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
Re
4May4,2016
![Page 9: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/9.jpg)
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
Re
e
4May4,2016
![Page 10: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/10.jpg)
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
e
Re
4May4,2016
![Page 11: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/11.jpg)
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Qd:int⊃string∧A
Re:1
5May4,2016
![Page 12: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/12.jpg)
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
Re:1d:string∧A
5May4,2016
![Page 13: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/13.jpg)
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”
Re:1d:A
5May4,2016
![Page 14: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/14.jpg)
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”end
Re:1d:A
5May4,2016
![Page 15: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/15.jpg)
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”
d:A
5May4,2016
![Page 16: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/16.jpg)
LinearSessionTypes
• Exampleinterfacespecification:
1 Terminate&{labi:Ai}i Externalchoice(receive)betweenlabi,continueasAi
A –o B ReceivechanneloftypeA,continueasBτ ⊃ B Receivevalueoftypeτ,continueasB⊕{labi:Ai}i Internalchoice(send)betweenlabi,continueasAi
A ⊗ B SendchanneloftypeA,continueasBτ ∧ B Sendvalueoftypeτ,continueasB
queue = &{enq: A –o queue, deq: ⊕{none: 1, some: A ⊗ queue}}
* where A is some predetermined type
6May4,2016
![Page 17: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/17.jpg)
ImplementationofQueuesqueue = &{enq: A –o queue, deq: ⊕{none: 1, some: A ⊗ queue}}
empty : queueq ← empty = case q enq " x ← recv q ; e ← empty ; q ← elem x e deq " q.none ; close q
elem : A –o queue –o queueq ← 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
7May4,2016
![Page 18: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/18.jpg)
IntersectionsandUnions
• Allowsdescribingmoreinterestingbehavior• Intersectionoftwotypes:A⊓B– c:A⊓Bifchannelcoffersbothbehaviors
• Unionoftwotypes:A⊔B– c:A⊔Bifchannelcofferseitherbehavior
8May4,2016
![Page 19: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/19.jpg)
RefinementTypes
• Whatifwewanttotrackmorepropertiesofqueues?Empty,non-empty,evenlength?
• Wecandefinetheminthebasesystem:
empty-queue = &{enq: A –o nonempty-queue, deq: ⊕{none: 1}}
nonempty-queue = &{enq: A –o nonempty-queue, deq: ⊕{some: A ⊗ queue}}
9May4,2016
![Page 20: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/20.jpg)
RefinementTypes
• Butweneedintersectionsandunionstowriteinterestingprograms
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)
10May4,2016
![Page 21: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/21.jpg)
DecidabilityofType-checking
• Algorithmicsystemthatiseasytotranslatetocode
• Provesoundandcompletewithrespecttotheoriginalsystem
• PartialimplementationinHaskell
11May4,2016
![Page 22: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1](https://reader034.vdocuments.us/reader034/viewer/2022042612/5f862cc8970fe87b302e9ebb/html5/thumbnails/22.jpg)
TypeSafety
• Progress– Deadlockfreedominconcurrentsetting– Atleastoneprocesscanmakeprogressiftheconfigurationiswell-typed
• Preservation[currentlyinprogress]– Sessionfidelityinconcurrentsetting– Processesobeysession-types
12May4,2016