A concurrent programming language with refined session types - - PowerPoint PPT Presentation

a concurrent programming language with refined session
SMART_READER_LITE
LIVE PREVIEW

A concurrent programming language with refined session types - - PowerPoint PPT Presentation

Introduction Donation Server The SePi language Final remarks and Future work A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos LaSIGE, University of Lisbon, Portugal September 23, 2013 A


slide-1
SLIDE 1

Introduction Donation Server The SePi language Final remarks and Future work

A concurrent programming language with refined session types

Juliana Franco and Vasco T. Vasconcelos

LaSIGE, University of Lisbon, Portugal

September 23, 2013

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 1 / 23

slide-2
SLIDE 2

Introduction Donation Server The SePi language Final remarks and Future work

Motivation

  • Session types are by now a well-established methodology for

typed, message-passing concurrent computations

  • Session types were originally proposed for the pi-calculus
  • There is no pi-based implementation on which one may
  • exercise examples
  • test program idioms
  • experiment with type systems

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 2 / 23

slide-3
SLIDE 3

Introduction Donation Server The SePi language Final remarks and Future work

SePi SEssions on PI

  • An exercise in the design and implementation of a concurrent

programming language based on the pi calculus, where process interaction is governed by linearly refined session types

  • Allows to explore the practical applicability of new (and old)

works on session-based type systems

  • Provides a tool where new program idioms and type

developments may be tested and eventually incorporated

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 3 / 23

slide-4
SLIDE 4

Introduction Donation Server The SePi language Final remarks and Future work

Running example An online donation service

  • Four sorts of participants: bank, server, clients and

benefactors

  • Clients create donation campaigns and send the campaign

link to benefactors

  • Benefactors donate by providing a credit card number and an

amount to be charged

  • The server provides for the creation of campaigns and

forwards the donations to the bank

  • The bank charges the donations on credit cards

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 4 / 23

slide-5
SLIDE 5

Introduction Donation Server The SePi language Final remarks and Future work

SePi communication channels

  • Bi-directional synchronous channels
  • Each channel is defined by two end-points: one to write, the
  • ther to read
  • Each end-point is governed by a session type

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 5 / 23

slide-6
SLIDE 6

Introduction Donation Server The SePi language Final remarks and Future work

Types input/output and termination

?integer.T

represents a channel end ready to receive an integer; continues as prescribed by T.

!integer.T

sends an integer and continues as T.

end

a channel where no further interaction is possible.

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 6 / 23

slide-7
SLIDE 7

Introduction Donation Server The SePi language Final remarks and Future work

SePi channel creation

new r w: ?integer.end

  • r has type ?integer.end
  • w has type !integer.end
  • dualof ?integer.end is !integer.end
  • Equivalent: new w r: !integer.end

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 7 / 23

slide-8
SLIDE 8

Introduction Donation Server The SePi language Final remarks and Future work

SePi channel read/write

new w r : ! integer . end w!2013 | r ?x . p r i n t I n t e g e r ! x

  • The output process, !, writes the value 2013 on the newly

created channel

  • The input process, ?, reads from the channel and stores the

value on x

  • printInteger is a builtin channel end
  • The vertical bar, |, denotes parallel composition

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 8 / 23

slide-9
SLIDE 9

Introduction Donation Server The SePi language Final remarks and Future work

Reduction

  • The process

new w r : ! integer . end w!2013 | r ?x . p r i n t I n t e g e r ! x

  • reduces in one step to

new w r : end p r i n t I n t e g e r !2013

  • which (prints 2013 on the console and) reduces in one step to

new w r : end {}

  • The terminated process is denoted by {}, the parallel

composition of zero processes

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 9 / 23

slide-10
SLIDE 10

Introduction Donation Server The SePi language Final remarks and Future work

Types choice

  • Type

&{setDate:T1, commit:T2}

represents a channel end offering two choices: setDate and

  • commit. If setDate is chosen then behaves as T1; if commit is

chosen then behaves as T2.

  • Type

+{setDate:T3, commit:T4}

selects one of the choices.

  • dualof &{setDate: end, commit: end} is +{setDate: end, commit: end}

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 10 / 23

slide-11
SLIDE 11

Introduction Donation Server The SePi language Final remarks and Future work

SePi select and case processes

new w r : +{setDate : end , commit : end} w s e l e c t setDate | case r

  • f

setDate → p r i n t S t r i n g ! ”Got setDate ” commit → p r i n t S t r i n g ! ”Got commit”

  • select chooses an option on a menu
  • case offers a menu of options

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 11 / 23

slide-12
SLIDE 12

Introduction Donation Server The SePi language Final remarks and Future work

Exchanging an unbounded number of messages

  • Clients want to upload the campaign information (setDate)

until satisfied and then press the commit button.

  • We would like to write:

+{setDate: !integer.go−back−to−the−begin, commit: end}

  • After the setDate choice is taken the whole menu is again
  • available. Use a recursive type:

rec a. +{setDate: !integer.a, commit: end}

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 12 / 23

slide-13
SLIDE 13

Introduction Donation Server The SePi language Final remarks and Future work

SePi Type abbreviations

  • Declare

type Donation = {setDate: !integer.Donation, commit: end}

  • and use the type name Donation in place of

rec a. +{setDate: !integer.a, commit: end}

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 13 / 23

slide-14
SLIDE 14

Introduction Donation Server The SePi language Final remarks and Future work

SePi unbounded behaviour

w select setDate. w!2012. w select setDate. w!2013. w select commit

  • The client may now upload the date two times before

committing.

def setup r : Donation = case r

  • f

setDate → r ?x . setup ! r commit → . . .

  • The server recurs after serving the setDate option

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 14 / 23

slide-15
SLIDE 15

Introduction Donation Server The SePi language Final remarks and Future work

SePi process definitions

def setup r : Donation = P RestOfTheProgram

  • is short for

new setup setupReader : ∗! Donation setupReader ∗? r .P | RestOfTheProgram

  • where setupReader∗?r.P is a replicated input: reduces against

zero or more output processes

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 15 / 23

slide-16
SLIDE 16

Introduction Donation Server The SePi language Final remarks and Future work

Types linear and unrestricted

  • Donation is a linear type: during the setup phase only one

client may share the communication channel. Donation in its full glory:

rec a . l i n +{setDate : l i n ! integer . a , commit : end}

  • But channel setup may be shared by multiple processes in
  • parallel. Type

rec b . un ! Donation . b

abbreviated to ∗!Donation

  • Type abbreviations allow to omit the lin/un qualifiers in most

cases

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 16 / 23

slide-17
SLIDE 17

Introduction Donation Server The SePi language Final remarks and Future work

Honest servers

  • Benefactors donate by providing the server with a credit card

number and a donation amount

  • The donation server forwards these values to the bank
  • A session with bank process has the following type

!CreditCard .! integer.end

  • What guarantees that

1 the server forwards the correct amount? 2 the server charges the right amount only once?

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 17 / 23

slide-18
SLIDE 18

Introduction Donation Server The SePi language Final remarks and Future work

Types refinements

  • The idea is that the bank is not interested in arbitrary

(ccard,amount) pairs but else on pairs for which a charge(ccard,amount) capability has been granted

  • We may refine type

!CreditCard. !integer.end

into

!ccard:CreditCard. !amount:{x: integer|charge(ccard, x)}. end

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 18 / 23

slide-19
SLIDE 19

Introduction Donation Server The SePi language Final remarks and Future work

SePi assuming and asserting capabilities

  • The capability of charging a given amount on a specific credit

card is usually granted by the benefactor, by assuming an instance of the charge predicate:

assume charge(”2345”, 10) | w!”2345”. w!10

  • In turn, the bank makes sure the capability to charge the card

was granted by the client, by asserting the same predicate:

r?ccard. r?amount. assert charge(ccard, amount)

  • The server must forward the values received, exactly once

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 19 / 23

slide-20
SLIDE 20

Introduction Donation Server The SePi language Final remarks and Future work

SePI Formulae are treated linearly

  • Formulae:
  • Uninterpreted predicates: charge(ccard, amount)
  • Joining: charge(ccard, amount)∗charge(ccard, amount)
  • Unit: unit
  • In a valid program
  • each assumption is asserted exactly once and
  • each assert is assumed exactly once

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 20 / 23

slide-21
SLIDE 21

Introduction Donation Server The SePi language Final remarks and Future work

Demo Eclipse plugin

  • Syntax highlight
  • Validation (type checking)
  • Run, interpreter based on Turner’s abstract machine
  • Code completion, refactoring, . . .

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 21 / 23

slide-22
SLIDE 22

Introduction Donation Server The SePi language Final remarks and Future work

Summing up

  • SePi is a new concurrent programming language based on the

monadic pi-calculus where

  • communication between processes is governed by session types
  • refinement types allow the specification of properties about the

values exchanged.

  • SePi includes a few abbreviations and derived constructs, such

as

  • the dualof operator
  • input/output of multiples values
  • mutually recursive process definitions and type declarations.
  • An Eclipse plugin for SePi facilitates code development. Try it

at http://gloss.di.fc.ul.pt/sepi

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 22 / 23

slide-23
SLIDE 23

Introduction Donation Server The SePi language Final remarks and Future work

Future work

  • New constructs:
  • an import clause
  • an abbreviation for session initiation
  • Predicates over expressions, using a SMT solver
  • What about your future work on top of SePi?
  • Type systems for progress
  • Polymorphism
  • Subtyping
  • . . .

A concurrent programming language with refined session types Juliana Franco and Vasco T. Vasconcelos 23 / 23