200
FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos University of Lisbon 1

FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

FUNDAMENTALS OFSESSION TYPES

Formal Methods for the Design ofComputer, Communication and Software Systems

Bertinoro, June 4, 2009

Vasco T. VasconcelosUniversity of Lisbon

1

Page 2: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHALLENGE

• Among the many problems faced in developing web-service based applications, there is a little one that this talk addresses:

• Formally describing the protocol between a service provider a client

• Making sure, at compile time, that a program follows the protocol

2

Page 3: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BINARY PROTOCOLS ONLY

• We concentrate on binary protocols, involving exactly one service provider and one client (at a time)

• Protocols demanding three or more partners are the topic of the next talk

3

Page 4: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

OUTLINE

Part I _ The practice

Where, based on an example, we describe a simple service and program it

Part 2 _ The theory

Where we discusss the technology behind a compiler that makes sure programs conform to service descriptions

4

Page 5: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PART ITHE PRACTICE

5

Page 6: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

1.PROTOCOL DESCRIPTION

6

Page 7: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

OUR RUNNING EXAMPLE

• A simplified distributed auction system with three kinds of players:

• Sellers that want to sell items

• Auctioneers that sell items on their behalf

• Bidders that bid for an item being auctioned

7

Page 8: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

8

Page 9: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling:

8

Page 10: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling:

Select option selling on the auctioneer

8

Page 11: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling:

8

Page 12: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item

8

Page 13: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item

Send the item to be sold

8

Page 14: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item

8

Page 15: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

8

Page 16: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

Send its price

8

Page 17: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

8

Page 18: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold:

8

Page 19: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

If the item was sold...

&{sold:

8

Page 20: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold:

8

Page 21: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price

8

Page 22: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

Read the price

&{sold: ?Price

8

Page 23: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price

8

Page 24: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price.end,

8

Page 25: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

... and terminate

&{sold: ?Price.end,

8

Page 26: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price.end,

8

Page 27: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price.end,

notSold: end}}

8

Page 28: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.

If not sold terminate

&{sold: ?Price.end,

notSold: end}}

8

Page 29: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SELLER’S PROTOCOL

!{selling: !Item.!Price.&{sold: ?Price.end,

notSold: end}}

8

Page 30: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE TYPE CONSTRUCTORS

!Item Send a value

?Price Receive a value

!{selling: ...} Select an option

&{sold: ..., notSold: ...} Offer a set of options

end Terminate

9

Page 31: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

10

Page 32: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling:

10

Page 33: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling:

Offer option selling to sellers

10

Page 34: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling:

10

Page 35: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.

10

Page 36: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.

Receive the item to be sold

10

Page 37: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.

10

Page 38: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.

10

Page 39: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.

Receive its price

10

Page 40: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.

10

Page 41: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold:

10

Page 42: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold:

Inform that the item was sold...

10

Page 43: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold:

10

Page 44: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price

10

Page 45: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price

Send the selling price

10

Page 46: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price

10

Page 47: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

10

Page 48: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

... and terminate

10

Page 49: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

10

Page 50: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

notSold: end}}

10

Page 51: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

notSold: end}}

Or inform the item was not sold and

terminate

10

Page 52: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER INTERACTING WITH A SELLER

&{selling: ?Item.?Price.!{sold: !Price.end,

notSold: end}}

10

Page 53: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SELLING AND BUYING...

• ... are complementary activities

• And so are the types that govern them:

• We call them dual

11

Page 54: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SELLING AND BUYING...

• ... are complementary activities

• And so are the types that govern them:

• We call them dual

!{selling: !Item.!Price.&{sold: ?Price.end, notSold: end}}

11

Page 55: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SELLING AND BUYING...

• ... are complementary activities

• And so are the types that govern them:

• We call them dual

!{selling: !Item.!Price.&{sold: ?Price.end, notSold: end}}

The protocol for the seller

11

Page 56: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SELLING AND BUYING...

• ... are complementary activities

• And so are the types that govern them:

• We call them dual

!{selling: !Item.!Price.&{sold: ?Price.end, notSold: end}}

&{selling: ?Item.?Price.!{sold: !Price.end, notSold: end}}

The protocol for the seller

11

Page 57: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SELLING AND BUYING...

• ... are complementary activities

• And so are the types that govern them:

• We call them dual

!{selling: !Item.!Price.&{sold: ?Price.end, notSold: end}}

&{selling: ?Item.?Price.!{sold: !Price.end, notSold: end}}

The protocol for the seller

The protocol for the auctioneer

11

Page 58: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

12

Page 59: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register:

12

Page 60: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register:

Select option register on the

auctioneer

12

Page 61: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register:

12

Page 62: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name.

12

Page 63: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name.

Send buyer’s name

12

Page 64: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name.

12

Page 65: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.

12

Page 66: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.

Receive an item on sale

12

Page 67: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.

12

Page 68: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

12

Page 69: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

Receive its price

12

Page 70: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

12

Page 71: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy:

12

Page 72: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy:

Decided to buy...

12

Page 73: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy:

12

Page 74: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

12

Page 75: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

... and terminate

12

Page 76: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

12

Page 77: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

notInterested: end}}

12

Page 78: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

notInterested: end}}

Decided not to buy; terminate

12

Page 79: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE BIDDERS PROTOCOL

!{register: !Name. ?Item.?Price.

!{buy: end,

notInterested: end}}

12

Page 80: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER WHILE INTERACTING WITH BIDDERS

• Recall the type when interacting with sellers:

• Two types? one for interacting with sellers, the other for bidders?

&{register: ?Name.!Item.!Price.

&{buy: end, notInterested: end}}

&{selling: ?Item.?Price.

!{sold: !Price.end, notSold: end}}

13

Page 81: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER ITSELF

• The particular types used to interact with sellers and with bidders are subtypes of this type

• Advantages:

• Bidders do not need to know the protocol for sellers

• The code for bidders may be developed before the introduction of (online) sellers in the auction system

&{register: ?Name. !Item. !Price.

&{buy: end, notInterested: end},

selling: ?Item.?Price.

!{sold: !Price. end, notSold: end}}

14

Page 82: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

COMPATIBILITY• The bidder-auctioneer compatibility rest assured. The actual

type for the auctioneer

• is a supertype of

• which is dual of that for the bidder

&{register: ?Name. !Item. !Price.

&{buy: end, notInterested: end},

selling: ...}

&{register: ?Name. !Item. !Price.

&{buy: end, notInterested: end}}

!{register: !Name. ?Item. ?Price.

!{buy: end, notInterested: end}}

15

Page 83: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SYSTEM EVOLUTION

• By far the most common sellers’ complaint is the inability of lowering the initial price after an unsuccessful auction

• The new auctioneer now provides a 3rd choice

“We are very excited

about your item; would you consider lowering

the price?”

&{selling: ?Item.?Price.Selling, register: ...}

Selling = !{sold: !Price. end,

notSold: end,

lowerYourPrice: &{ok: ?Price. Selling,

noWay: end}}

16

Page 84: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

COMPATIBILITY ASSURED?

• The old seller still works, it just does not use the new functionality

• The new type is far more complex than the original: additional

recursion and one more ! choice. Expanding recursion we

see that all there remains is one more choice

&{selling: ?Item. ?Price.

!{sold: !Price. end, notSold: end,

lowerYourPrice&{ok: ?Price. Selling,

noWay: end}}}

17

Page 85: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SUBTYPING

Subtype Supertype Variancy

Branch &

Selection !

Input ?

Output !

Less options offered

More options offered

Covariant

More options taken

Less options taken

Contravariant

Input value is subtype

Input value is supertype

Covariant

Output value is supertype

Output value is supertype

Contravariant

• In all cases continuation are covariant

• Recursion “unfolded away” _ co-inductive definition

18

Page 86: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SESSIONS

• Protocols such as the seller-auctioneer-bidder run between exactly two partners at a time:

• seller-auctioneer, or

• auctioneer-bidder

• Each such run is called a session

19

Page 87: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHANNELS

• An auctioneer must be able to conduct multiple sessions in parallel, with different sellers, with different bidders

• And must not mix the sessions. E.g.,

• Announcing sold to bidder A

• Sending the corresponding Price to bidder B

• Each session is conducted on a different bi-directional communication medium called channel

20

Page 88: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

ESTABLISHING SESSIONS

• How are sessions created?

• On channels known to all participants potentially interested on online auctions, e.g., distributed on the www

• We could distinguish

• linear channels - known by one partner

• shared channels - known by any number of partners...

21

Page 89: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CLASSIFYING OPERATIONS

• ...but we prefer to work with a single kind of channel and

distinguish linear from unrestricted (shared) operations

• This gives us greater flexibility and a simplified theory

• All the operations we have seen so far are linear

lin!{selling: lin!Item. lin!Price.

lin&{sold: lin?Price. un end, notSold: un end}} The

interesting end is unrestricted

22

Page 90: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

23

Page 91: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

S = un?T.S

23

Page 92: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

S = un?T.S

Establish a session

23

Page 93: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

S = un?T.S

23

Page 94: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

S = un?T.SEstablish

more sessions

23

Page 95: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BACK TO SESSION ESTABLISHMENT

• The common knowledge between the three kinds of partners is a shared channel, used to establish linear sessions

• Recall the type of the auctioneer’s session

• The type of the shared channel is

T = lin&{register: ..., selling: ...}

S = un?T.S

23

Page 96: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

2.PROGRAMMING

24

Page 97: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHICH PROGRAMMING LANGUAGE?

• In which language shall we program the protocol?

• Functional?

• Imperative?

• Object-oriented?

• You’ll find all flavours in the literature

• It must incorporate the notion of channels; we shall use a pi-calculus

25

Page 98: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 99: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

c is the name of a channel

26

Page 100: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 101: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

Select option selling on the auctioneer

26

Page 102: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 103: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

Send the item to be sold

26

Page 104: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 105: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

Send its price

26

Page 106: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 107: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

Wait for an option

26

Page 108: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 109: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

If the item was sold...

26

Page 110: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 111: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

Read the price

26

Page 112: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 113: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}If not sold

26

Page 114: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE SELLER

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c?(x).print!(“made “ ^ x ^ “euros!”)

notSold " print!(“next time I’ll ask 99.9!”)

}

26

Page 115: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHANNEL OPERATIONS

c ! “psp” Send value

c?(x) Receive value

c ! selling Select option

c "{sold:..., notSold:...} Branch on option

27

Page 116: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHANNEL OPERATIONS AND TYPES

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c ? (x)...

notSold " ...}

• Collect all operations on channel c

• un qualifier omitted on type end; lin omitted on all other type constructors

28

Page 117: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHANNEL OPERATIONS AND TYPES

c ! selling.

c ! “psp”.

c ! 100.

c "{

sold " c ? (x)...

notSold " ...}

!{selling:

!Item.!Price.&{

sold: ?Price. end,notSold: end}}

• Collect all operations on channel c

• un qualifier omitted on type end; lin omitted on all other type constructors

28

Page 118: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PROGRAMMING THE BIDDER

c ! register.

c ! “Vasco”.

c ? (item).

c ? (price).

if (item = “psp” and price < 100)

then c ! buy

else c ! notInterested

29

Page 119: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE CODE AND THE TYPE FOR THE BIDDER

c ! register.

c ! “Vasco”.

c ? (item).

c ? (price).

if (...)

then c ! buy

else c ! notInterested

• Collect all operations on channel c

• Qualifiers omitted on all type constructors as before

30

Page 120: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE CODE AND THE TYPE FOR THE BIDDER

c ! register.

c ! “Vasco”.

c ? (item).

c ? (price).

if (...)

then c ! buy

else c ! notInterested

!{register:

!Name.?Item.?Price.

!{buy: end,notInterested: end}}

• Collect all operations on channel c

• Qualifiers omitted on all type constructors as before

30

Page 121: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE AUCTIONEER

• The most sophisticated piece of code

• More later...

c " {

selling " -- handle sellers’ requests

register " -- handle bidders’ requests

}

31

Page 122: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do sellers and bidders start sessions?

• By requesting such a session on a, the auctioneer’s public, shared, name:

• The auctioneer’s public name is a shared channel of type

32

Page 123: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do sellers and bidders start sessions?

• By requesting such a session on a, the auctioneer’s public, shared, name:

• The auctioneer’s public name is a shared channel of type

Seller = a?(c). c ! selling.c ! “psp”...

32

Page 124: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do sellers and bidders start sessions?

• By requesting such a session on a, the auctioneer’s public, shared, name:

• The auctioneer’s public name is a shared channel of type

Seller = a?(c). c ! selling.c ! “psp”...

Bidder = a?(c). c ! register. c ! “Vasco”...

32

Page 125: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do sellers and bidders start sessions?

• By requesting such a session on a, the auctioneer’s public, shared, name:

• The auctioneer’s public name is a shared channel of type

Seller = a?(c). c ! selling.c ! “psp”...

Bidder = a?(c). c ! register. c ! “Vasco”...

S = un?T.S

32

Page 126: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

33

Page 127: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

Create the two ends of a channel

33

Page 128: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

33

Page 129: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

Send one end to the client

33

Page 130: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

33

Page 131: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)Interact on the

other end

33

Page 132: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

BOOTSTRAPPING

• How do auctioneers start sessions?

• By creating a fresh channel and sending it to clients

• We shall distinguish the two ends of a channel

Auctioneer = (!cc’)(

a!c’ |

c " {selling " ... register " ...} |

Auctioneer)

33

Page 133: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

MORE PROCESS CONSTRUCTORS

P | Q Parallel composition

(!cc’) Channel creation

if v then P else Q Conditional

34

Page 134: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

REFINING THE AUCTIONEER

• Concentrate on the selling option; some pseudo-code first

• Assume a shared repository with operations put, sold, price

c?(item). c?(price). put(item, price)

if sold(item)

then c ! sold. c!price(item)

else c ! notSold

35

Page 135: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SHARED AUCTION DATA REPOSITORY

• If shared, it must be accessed by a protocol

• Operation put(item, price) becomes

• where r is the shared name for the repository

r?(d). d ! put. d!item. d!price

36

Page 136: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SHARED AUCTION DATA REPOSITORY

• Operations sold(item)/price(item) must be dealt together

• Sessions c and e are now mixed...

• ... but the types remain apart. The type of e is

37

Page 137: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SHARED AUCTION DATA REPOSITORY

• Operations sold(item)/price(item) must be dealt together

• Sessions c and e are now mixed...

• ... but the types remain apart. The type of e is

r?(e). e ! wasItSold. e!item.

e " {sold " c !sold. e?(price). c!price,

notSold " c !notSold}

37

Page 138: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SHARED AUCTION DATA REPOSITORY

• Operations sold(item)/price(item) must be dealt together

• Sessions c and e are now mixed...

• ... but the types remain apart. The type of e is

r?(e). e ! wasItSold. e!item.

e " {sold " c !sold. e?(price). c!price,

notSold " c !notSold}

!{wasItSold: !Item. &{sold: ?Price.end, notSold: end}}

37

Page 139: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SESSION DELEGATION

• Noticed the copy-cat?

• Why not trust the seller’s channel to the repository? The repository takes care of replying directly to the client

e " {sold " c !sold. e?(price). c!price

notSold " c !notSold}

38

Page 140: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SESSION DELEGATION

• Noticed the copy-cat?

• Why not trust the seller’s channel to the repository? The repository takes care of replying directly to the client

e " {sold " c !sold. e?(price). c!price

notSold " c !notSold}

r?(e). e!wasItSold. e?(item). e!c

38

Page 141: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SESSION DELEGATION

• Noticed the copy-cat?

• Why not trust the seller’s channel to the repository? The repository takes care of replying directly to the client

e " {sold " c !sold. e?(price). c!price

notSold " c !notSold}

r?(e). e!wasItSold. e?(item). e!c

Sending a channel on a channel

38

Page 142: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A TYPE FOR THE REPOSITORY

• The type for the shared channel...

• ... and that for the session it establishes

• The seller is not aware of the delegation; it needs not change its type or its code

39

Page 143: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A TYPE FOR THE REPOSITORY

• The type for the shared channel...

• ... and that for the session it establishes

• The seller is not aware of the delegation; it needs not change its type or its code

S = un ?T.S

39

Page 144: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A TYPE FOR THE REPOSITORY

• The type for the shared channel...

• ... and that for the session it establishes

• The seller is not aware of the delegation; it needs not change its type or its code

S = un ?T.S

T = !{put: !Item. !Price. end,

wasItSold: !Item. !U. end}

U = &{sold: ?Price. end, notSold: end}

39

Page 145: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A TYPE FOR THE REPOSITORY

• The type for the shared channel...

• ... and that for the session it establishes

• The seller is not aware of the delegation; it needs not change its type or its code

S = un ?T.S

T = !{put: !Item. !Price. end,

wasItSold: !Item. !U. end}

U = &{sold: ?Price. end, notSold: end}

The type of the delegated

session

39

Page 146: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

PART IITHE THEORY

40

Page 147: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE PROGRAMME

• The language

• Its typing system and

• Its operational semantics

• What is an error?

• Main result: Typable processes do not reduce to errors

41

Page 148: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE PROGRAMME

• The language

• Its typing system and

• Its operational semantics

• What is an error?

• Main result: Typable processes do not reduce to errors

Very much standard!

41

Page 149: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

1.THE LANGUAGE

42

Page 150: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHANNEL CREATION

• Variables come in pairs, called co-variables

• Each represents one end of a communication channel

• Interacting threads do not share variables for communication; instead, each thread owns its variable

• This mechanism allows a precise control of resources via a linear type system

43

Page 151: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SYNTAX OF PROCESSES, TO START WITH

P ::= Processes:x v.P outputx(x).P inputP | P parallel compositionif v then P else P conditional0 inaction(!xx)P scope restriction

v ::= Values:x variabletrue | false boolean values

44

Page 152: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

2.TYPING SYSTEM

45

Page 153: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

LINEAR AND UNRESTRICTED TYPES

• Lin (linear) qualified types describe variables that occur in exactly one thread

• Un (unrestricted, shared) qualifier indicates a value that can occur in multiple threads

• Type lin ! (lin bool). un end represents a channel-end that can be used once to output a boolean value (that can be used once) and then behaves as shared channel on which no further operation is possible

46

Page 154: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

THE SYNTAX OF TYPESq ::= Qualifiers:

lin linearun unrestricted

p ::= Pretypes:bool booleansend termination?T.T receive!T.T send

T ::= Types:q p qualified pretype

! ::= Contexts:" empty context!, x : T assumption

47

Page 155: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

EXAMPLE: VALID AND INVALID PROCESSES

• x is a variable of an arbitrarily qualified type

• a is a variable of an unrestricted type, and

• c a variable of a linear type

x true.x(y)a true | a true | a false

c true | c false

Omit the

trailing 0

48

Page 156: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

DUALITY

q ?T.U = q !T.U q !T.U = q ?T.U q end = q end

x1 true | x2(z)x1 true.x1(w) | x2(z).x2 false

x1 true | x2 false

x1 true.x1(w) | x2(z).x2(t)

and are two co-variables

x1 x2

No rule for bool

49

Page 157: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CONTEXT SPLITTING

• An operation central to linear typing systems

• When type checking processes with two sub-processes we pass the unrestricted part of the context to both processes, while splitting the linear part in two and passing a different part to each process

! · ! = !" = "1 · "2 un(T)

", x : T = ("1, x : T) · ("2, x : T)" = "1 · "2 lin(T)

", x : T = ("1, x : T) · "2

" = "1 · "2 lin(T)", x : T = "1 · ("2, x : T)

50

Page 158: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPE SYSTEM: INVARIANTS

• Linear channels occur in exactly one thread

• Co-variables have dual types

51

Page 159: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING RULES FOR VALUES

• The rules make sure that linear variables are not discarded without being used

• The base cases of the type system check that there is no linear variable in the context

un(!)! ! false : bool

un(!1, !2)!1, x : T, !2 ! x : T

52

Page 160: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING RULES FOR PROCESSES (1/3)

• The base case checks that there is no linear variable in the context

• Parallel composition crucially takes advantage of context splitting

un(!)! ! 0

!1 ! P !2 ! Q!1 · !2 ! P | Q

53

Page 161: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING RULES FOR PROCESSES (2/3)

• No context splitting for the two branches in the conditional

• The rule for scope restriction captures the essence of co-variables: they must have dual types

!1 ! v : q bool !2 ! P !2 ! Q!1 · !2 ! if v then P else Q

!, x : T, y : T ! P! ! (!xy)P

54

Page 162: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING RULES FOR PROCESSES (3/3)

• The rule for input splits the context into two parts: one to

type check x, the other to type check continuation P

• If x: q?T.U in x(y).P then we use y:T to type check P

• x(y).P uses x at type q?T.U, whereas P may use the same

variable this time at type U

!1 ! x : q ?T.U (!2, y : T) · x : U ! P!1 · !2 ! x(y).P

!1 ! x : q !T.U !2 ! v : T !3 · x : U ! P!1 · !2 · !3 ! x v.P

55

Page 163: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING RULES FOR PROCESSES (SUMMARY)

un(!)! ! 0

!1 ! P !2 ! Q!1 · !2 ! P | Q

!1 ! v : q bool !2 ! P !2 ! Q!1 · !2 ! if v then P else Q

!, x1 : T, x2 : T ! P! ! (!x1x2)P

!1 ! x : q ?T.U (!2, y : T) · x : U ! P!1 · !2 ! x(y).P

!1 ! x : q !T.U !2 ! v : T !3 · x : U ! P!1 · !2 · !3 ! x v.P

56

Page 164: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A SIMPLE SESSION

Unrestricted environment

Unrestricted qualifiers omitted

x : T ! x : T " ! true : bool

x : T ! ! x : T ! x : end, y : bool ! 0

x : T ! =?bool.end ! x(y).0

x : T = lin!bool.?bool.end ! x true.x(y).0

57

Page 165: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

LINEAR VALUES ARE CONSUMED

Not unrestricted

Process not typable

x : T ! x : T " ! true : bool

x : T ! ! x : T ! x : end, y : lin bool ! 0

x : T ! =?(lin bool).end ! x(y).0

x : T = lin!bool.?(lin bool).end ! x true.x(y).0

58

Page 166: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

A LANGUAGE OF LINEAR CHANNELS ONLY

Process not typable; to be

fixed!

Context splitting not

defined

Parallel composition

! ! x : !(bool).end ! ! true : bool ! · (x : end) ! 0

! ! x true ! ! x true

! = x : !(bool).end ! x true | x true

59

Page 167: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

3.OPERATION SEMANTICS

60

Page 168: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

STRUCTURAL CONGRUNECE

• Factor out a on processes allowing the syntactic rearrangement of these

• Contribute for a more concise presentation of the reduction relation

P | Q ! Q | P (P | Q) | R ! P | (Q | R) P | 0 ! P

(!xy)P | Q ! (!xy)(P | Q) (!xy)0 ! 0 (!wz)(!xy)P ! (!xy)(!wz)P

61

Page 169: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

REDUCTION

(!xy)(x v.P | y(z).Q | R) ! (!xy)(P | Q[v/z] | R)if true then P else Q ! P

if false then P else Q ! Q

P ! Q

(!xy)P ! (!xy)QP ! Q

P | R ! Q | R

P " P ! P ! ! Q! Q! " Q

P ! Q

62

Page 170: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHAT CAN GO WRONG?

• An obvious case: in a conditional process the value in the condition is neither true nor false

• More interesting:

• Notice: no mention of types or lin/un channel nature

a true | a(z)(!x1x2)(x1 true | x2 true)(!x1x2)(x1(z) | x2(w))

63

Page 171: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHAT CAN GO WRONG?

• An obvious case: in a conditional process the value in the condition is neither true nor false

• More interesting:

• Notice: no mention of types or lin/un channel nature

a true | a(z)(!x1x2)(x1 true | x2 true)(!x1x2)(x1(z) | x2(w))

Different communication

patterns on the same channel end

63

Page 172: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHAT CAN GO WRONG?

• An obvious case: in a conditional process the value in the condition is neither true nor false

• More interesting:

• Notice: no mention of types or lin/un channel nature

a true | a(z)(!x1x2)(x1 true | x2 true)(!x1x2)(x1(z) | x2(w))

63

Page 173: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHAT CAN GO WRONG?

• An obvious case: in a conditional process the value in the condition is neither true nor false

• More interesting:

• Notice: no mention of types or lin/un channel nature

a true | a(z)(!x1x2)(x1 true | x2 true)(!x1x2)(x1(z) | x2(w))

Channels ends with incompatible communication

patterns

63

Page 174: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WHAT CAN GO WRONG?

• An obvious case: in a conditional process the value in the condition is neither true nor false

• More interesting:

• Notice: no mention of types or lin/un channel nature

a true | a(z)(!x1x2)(x1 true | x2 true)(!x1x2)(x1(z) | x2(w))

63

Page 175: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WELL TYPED PROGRAMS DO NOT GO WRONG

• Outline of the proof

1. Type preservation

2. Type safety

3. Compose and done! (details in the book)

If ! ! P and P " Q then ! ! Q

If ! P then P is well formed

64

Page 176: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

4.RECURSIVE TYPES

65

Page 177: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

RECURSIVE TYPES

• Context splitting not defined...

• ... unless there is type T such that

• Use a finite notation for the solution of the equation

µa.!bool.a

!bool.T = T

x : !bool.T ! x : !bool.T x : !bool.T ! true : bool (x : !bool.T ) · (x : end) ! 0

x : !bool.T ! x true

66

Page 178: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

• Shared output channels are of types !a.!T.a which we

abbreviate to *!T

• Unfold/fold recursive types as needed: equi-recursive notion of types

TYPES FOR SHARED CHANNELS

!!bool = !bool.!!bool

! ! x : "!bool ! ! true : bool ! · (x : "!bool) ! 0

! = x : !bool."!bool ! x true

67

Page 179: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

EXAMPLE _ TUPLE PASSING ON SHARED CHANNELS

• If x is is shared then there is a risk of interference

• Use the standard encoding...

• ... which is typable

x !u, v".P = xu.x v.Pok if x is

linear

x1 !u, v".P = (!y1y2)x1 y2.y1 u.y1 v.P

x2(w, t).P = x2(z).z(w).z(t).P

x1 : !!(lin?T.lin?U)x2 : !?(lin!T.lin!U)

68

Page 180: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

LINEAR CHANNELS THAT BECOME UNRESTRICTED

• Suppose that

• Then

x1 true.(x1(y) | x1(z)) | x2(x).(x2 true | x2 false | x2 true)

x1 : lin!bool.!?bool

x2 : lin?bool.!!bool

69

Page 181: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

5.REPLICATION

70

Page 182: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

UNBOUNDED BEHAVIOR

• Up until now our language is strongly normalizing

• Providing for unbounded behavior

• Recursion (as in the auctioneer example)

• Replication

• Replication is conceptually simpler ; we go for it

71

Page 183: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

SYNTAX AND REDUCTION

• New syntax

• New reduction rule

P ::= . . . Processes:! x(x).P replication

(!xy)(x v.P | !y(z).Q | R) " (!xy)(P | Q[v/z] | !y(z).Q | R)(!xy)(x v.P | y(z).Q | R) " (!xy)(P | Q[v/z] | R)

The replicated process survives reduction

72

Page 184: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING

! ! P un(!)! ! "P

73

Page 185: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING

P can be used multiple times

! ! P un(!)! ! "P

73

Page 186: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

TYPING

! ! P un(!)! ! "P

73

Page 187: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

“PROCEDURES”

• A procedure that sends a boolean value on a fixed channel c

• c cannot be linear for the body of the procedure must be un

• What if we pass c as parameter?

• The type system controls the linearity of the arguments

• Linear values in procedures must be passed as parameters

p2 : !?end, c : lin!bool "# ! p2(z).c true

!p2(z).c true | p1 x | p1 x " " !p2(z).c true | c true | c true

p2 : ?(lin!bool) ! " p2(z).z true

. . . , p2 : ?(lin!bool) !" # p2(z).z true | p1 c | p1 c

74

Page 188: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

6.CHOICE

75

Page 189: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHOICE _ SYNTAX

P ::= . . . Processes:x ! l.P selectionx " {li : Pi}i!I branching

p ::= . . . Pretypes:!{li : Ti}i!I select&{li : Ti}i!I branch

76

Page 190: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHOICE _ REDUCTION

j ! I

(!xy)(x ! lj .P | y " {li : Qi}i!I | R) " (!xy)(P | Qj | R)

77

Page 191: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

CHOICE _ TYPING

• Duality

• Typing

q !{li : Ti}i!I = q &{li : Ti}i!I q &{li : Ti}i!I = q ! {li : Ti}i!I

!2 ! x : q "{li : Ti}i!I !2 · x : Tj ! P j # I

!1 · !2 ! x ! lj .P

!1 ! x : q &{li : Ti}i!I !2 · x : Ti ! Pi $i # I

!1 · !2 ! x " {li : Pi}i!I

78

Page 192: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

7.SUBTYPING

79

Page 193: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

MOTIVATION

• Subtyping brings extra flexibility to our type system

• The insistence that arguments in output processes exactly match input parameters in corresponding receivers leads to the rejection of programs that will never go wrong when executed

• We have seen examples in the first part

80

Page 194: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

INGREDIENTS

• We need

• A notion of subtyping. T <: U means any value of type T can be safely used in a context where U is expected

• A rule to incorporate subtyping in the type system

! ! v : T T <: U

! ! v : U

81

Page 195: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

FINITE SUBTYPING _ CHOICE

• The auctioneer can forget options in order to address sellers or bidders

• Conversely sellers may call more options on the auctioneer (so as to behave as bidders as well)

I ! J Ti <: Ui "i # I

&{li : Ti}i!I <: &{lj : Uj}j!J

I ! J Tj <: Uj "j # J

${li : Ti}i!I <: ${lj : Uj}j!J

82

Page 196: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

FINITE SUBTYPING _ I/O

• Input is co-variant; output is contra-variant

• In summary:

• Input operations (?, &) are co-variant; output operations (!, !) contra-variant

• Continuations are always co-variant

• See book for subtyping recursive types

T ! <: T U <: U !

!T.U <: !T !.U !T <: T ! U <: U !

?T.U <: ?T !.U !

83

Page 197: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

8.CONCLUSION

84

Page 198: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

ALGORITHMIC TYPE CHECKING

• The typing rules cannot be implemented directly for two main reasons. Difficulties

• Implementing the non-deterministic splitting operation

• Guessing the types for nu-bound variables

See book!

85

Page 199: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

WE INTRODUCED...

• A (type) language to describe (the protocol part of) services

• A (programming) language to program protocols

• A decidable type checking system that makes sure that “well typed programs do not go wrong”

86

Page 200: FUNDAMENTALS OF SESSION TYPES · FUNDAMENTALS OF SESSION TYPES Formal Methods for the Design of Computer, Communication and Software Systems Bertinoro, June 4, 2009 Vasco T. Vasconcelos

LOOKING FOR RESEARCH TOPICS?

• Programs can easily deadlock

• Identify conditions / refine the type system so as to ensure progress

• Context splitting for both parallel and sequential composition

x1 true.y1 false | y2(x).x2(w)

!1 ! x : q ?T.U (!2, y : T ) · x : U ! P

!1 · !2 ! x(y).PSequentialParallel

87