Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay &...
Transcript of Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay &...
RefinementsforSession-typedConcurrency
JoshAcay&FrankPfenning
1May4,2016
Message-passingConcurrency
• Processesrepresentedasnodes• Channelsbetweenprocessesasedges• Eachchannelis“provided”byaspecificprocess(Pprovidesc,Qprovidesdetc.)
Pc
Qd
Re
2May4,2016
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3May4,2016
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
3May4,2016
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
“aaa”
3May4,2016
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
Re
3
“aaa”
end
3May4,2016
Message-passingConcurrency
• Processescomputeinternally• Exchangemessagesalongchannels
Pc
Qd
3
“aaa”
3May4,2016
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
Re
4May4,2016
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
Re
e
4May4,2016
Message-passingConcurrency
• Processescanalsosendchannelstheyown
Pc
Qd
e
Re
4May4,2016
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Qd:int⊃string∧A
Re:1
5May4,2016
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
Re:1d:string∧A
5May4,2016
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”
Re:1d:A
5May4,2016
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”end
Re:1d:A
5May4,2016
LinearSession-types
• Don’twanttosendintifexpectingstring• Don’ttrytoreceiveifotherprocessisnotsending
• Assigntypestoeachchannelfromprovider’sperspective
Pc:B
Q3
“aaa”
d:A
5May4,2016
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
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
IntersectionsandUnions
• Allowsdescribingmoreinterestingbehavior• Intersectionoftwotypes:A⊓B– c:A⊓Bifchannelcoffersbothbehaviors
• Unionoftwotypes:A⊔B– c:A⊔Bifchannelcofferseitherbehavior
8May4,2016
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
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
DecidabilityofType-checking
• Algorithmicsystemthatiseasytotranslatetocode
• Provesoundandcompletewithrespecttotheoriginalsystem
• PartialimplementationinHaskell
11May4,2016
TypeSafety
• Progress– Deadlockfreedominconcurrentsetting– Atleastoneprocesscanmakeprogressiftheconfigurationiswell-typed
• Preservation[currentlyinprogress]– Sessionfidelityinconcurrentsetting– Processesobeysession-types
12May4,2016