YOU ARE DOWNLOADING DOCUMENT

Please tick the box to continue:

Transcript
Page 1: Refinements for Session-typed Concurrency · Refinements for Session-typed Concurrency Josh Acay & Frank Pfenning May 4, 2016 1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

TypeSafety

• Progress– Deadlockfreedominconcurrentsetting– Atleastoneprocesscanmakeprogressiftheconfigurationiswell-typed

• Preservation[currentlyinprogress]– Sessionfidelityinconcurrentsetting– Processesobeysession-types

12May4,2016


Related Documents