Modular Session Types for Distributed Object-Oriented Programming - - PowerPoint PPT Presentation

modular session types for distributed object oriented
SMART_READER_LITE
LIVE PREVIEW

Modular Session Types for Distributed Object-Oriented Programming - - PowerPoint PPT Presentation

Modular Session Types for Distributed Object-Oriented Programming Simon J. Gay Antnio Ravara Vasco T. Vasconcelos Nils Gesbert Alexandre Z. Caldeira New University of Lisbon Formerly Technical University University of Glasgow University


slide-1
SLIDE 1

Modular Session Types for Distributed Object-Oriented Programming

Simon J. Gay Nils Gesbert

University of Glasgow

António Ravara

New University of Lisbon Formerly Technical University

  • f Lisbon

Vasco T. Vasconcelos Alexandre Z. Caldeira

University of Lisbon

POPL, 21st January 2010

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 1 / 12

slide-2
SLIDE 2

Running Example: Mail Reader

enum ErrorStatus { OK, ERR } interface MailReader { ErrorStatus login (String user, String pass); int getNumberOfMessages(); ErrorStatus fetchAndDelete (int index); String getMessageContent(); void logout(); }

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 2 / 12

slide-3
SLIDE 3

Constraints

Cannot fetch messages before (successful) login or after logout Cannot get the content of a message before it is fetched successfully Should not fetch a new message before the previous one is read or saved

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 3 / 12

slide-4
SLIDE 4

Constraints

Cannot fetch messages before (successful) login or after logout Cannot get the content of a message before it is fetched successfully Should not fetch a new message before the previous one is read or saved Not any method can be safely called at any time; the interface (set of available methods) changes depending of what is done. We propose to represent that fact at the type level.

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 3 / 12

slide-5
SLIDE 5

Session Types for Objects

Several methods available: external choice {fetchAndDelete: S, logout: S’}

Object branches / Client selects by calling a method

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 4 / 12

slide-6
SLIDE 6

Session Types for Objects

Several methods available: external choice {fetchAndDelete: S, logout: S’}

Object branches / Client selects by calling a method

Dependency on a method result: internal choice <OK: S, ERR: S’>

Object selects by returning a label / Client branches

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 4 / 12

slide-7
SLIDE 7

Session Types for Objects

Several methods available: external choice {fetchAndDelete: S, logout: S’}

Object branches / Client selects by calling a method

Dependency on a method result: internal choice <OK: S, ERR: S’>

Object selects by returning a label / Client branches

Session Init = {login: <OK: NoMsg, ERR: Init>} where NoMsg = {fetchAndDelete: <OK: MsgRead, ERR: NoMsg>, getNumberOfMessages: NoMsg, logout: {} } and MsgRead = {getMessageContent: NoMsg, getNumberOfMessages: MsgRead, logout: {getMessageContent: {}} }

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 4 / 12

slide-8
SLIDE 8

How it works

Calling a method advances the session type of the object If the continuation is an internal choice, client must switch on the result to resolve it

✵ ✵

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 5 / 12

slide-9
SLIDE 9

How it works

Calling a method advances the session type of the object If the continuation is an internal choice, client must switch on the result to resolve it Objects are linear but may be stored in fields of other objects

✵ ✵

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 5 / 12

slide-10
SLIDE 10

How it works

Calling a method advances the session type of the object If the continuation is an internal choice, client must switch on the result to resolve it Objects are linear but may be stored in fields of other objects External type of an object: session type, C[S]

✵ ✵

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 5 / 12

slide-11
SLIDE 11

How it works

Calling a method advances the session type of the object If the continuation is an internal choice, client must switch on the result to resolve it Objects are linear but may be stored in fields of other objects External type of an object: session type, C[S] Internal state of an object: type of its fields, C[F]

✵ ✵

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 5 / 12

slide-12
SLIDE 12

How it works

Calling a method advances the session type of the object If the continuation is an internal choice, client must switch on the result to resolve it Objects are linear but may be stored in fields of other objects External type of an object: session type, C[S] Internal state of an object: type of its fields, C[F] Judgements: Expressions: Γ ⊲ e : T ⊳ Γ✵ For a method body: this : C[F] ⊲ e : T ⊳ this : C[F ✵] Internal/External state compatibility: F ❵ C : S Coinductively checks method bodies in order

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 5 / 12

slide-13
SLIDE 13

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

✵ ✵

✿ ❢ ❣ ✿ ❢ ❣ ❢ ❣ ✷ ❢ ❤ ✐ ✷ ❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-14
SLIDE 14

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... ✟

✵ ✵

✿ ❢ ❣ ✿ ❢ ❣ ❢ ❣ ✷ ❢ ❤ ✐ ✷ ❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-15
SLIDE 15

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... Choice: ✟{validate: Σ, cancel: Σ✵} Allows a selection by sending one of the labels

✿ ❢ ❣ ✿ ❢ ❣ ❢ ❣ ✷ ❢ ❤ ✐ ✷ ❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-16
SLIDE 16

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... Choice: ✟{validate: Σ, cancel: Σ✵} Allows a selection by sending one of the labels Branching: &{ok: Σ, error: Σ✵} May receive any of the labels

✿ ❢ ❣ ✿ ❢ ❣ ❢ ❣ ✷ ❢ ❤ ✐ ✷ ❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-17
SLIDE 17

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... Choice: ✟{validate: Σ, cancel: Σ✵} Allows a selection by sending one of the labels Branching: &{ok: Σ, error: Σ✵} May receive any of the labels

Channels can be treated like objects ?T ✿ Σ = ❢receiveT : Σ❣ !T ✿ Σ = ❢sendT : Σ❣ ❢ ❣ ✷ ❢ ❤ ✐ ✷ ❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-18
SLIDE 18

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... Choice: ✟{validate: Σ, cancel: Σ✵} Allows a selection by sending one of the labels Branching: &{ok: Σ, error: Σ✵} May receive any of the labels

Channels can be treated like objects ?T ✿ Σ = ❢receiveT : Σ❣ !T ✿ Σ = ❢sendT : Σ❣ &❢l : Σl❣l✷E = ❢receiveE : ❤l : Σl✐l✷E❣ ✟❢ ❣ ✷ ❢ ❣ ✷

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-19
SLIDE 19

Session Types for Channels

Honda et al., 1993-present Originally meant for typing communication channels in the ✙-calculus: describes a protocol

Sequence, send, receive: !String.?Bool... Choice: ✟{validate: Σ, cancel: Σ✵} Allows a selection by sending one of the labels Branching: &{ok: Σ, error: Σ✵} May receive any of the labels

Channels can be treated like objects ?T ✿ Σ = ❢receiveT : Σ❣ !T ✿ Σ = ❢sendT : Σ❣ &❢l : Σl❣l✷E = ❢receiveE : ❤l : Σl✐l✷E❣ ✟❢l : Σl❣l✷E = ❢sendl : Σl❣l✷E

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 6 / 12

slide-20
SLIDE 20

Example: simplified POP3 Protocol

Type POP3 = !String.!String.&{OK: Trans, ERR: POP3} where Trans = ✟{ STAT: ?int.Trans, DELE: !int.Trans, QUIT: End, RETR: !int.&{OK: ?String.Trans, ERR: Trans} }

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 7 / 12

slide-21
SLIDE 21

A POP3 Client Class (implements MailReader)

class POP3Client implements MailReader { Chan[POP3] c; Null n, m; // fields ErrorStatus login (String user, String pass) { c.send (user); c.send (pass); switch (c.receive()) { case OK: c.send (STAT); n = c.receive(); return OK; case ERR: return ERR; }} ErrorStatus fetchAndDelete (int index) { c.send (RETR); c.send (index); switch (c.receive()) { case OK: m = c.receive(); c.send (DELE); return OK; case ERR: return ERR; }} int getNumberOfMessages() {return n;} String getMessageContent() {return m;} void logout() {c.send (QUIT);} }

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 8 / 12

slide-22
SLIDE 22

Relation between internal and external states

{Chan[POP3] c; Null n; Null m} ❵ POP3Client : Init

❵ ❵

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 9 / 12

slide-23
SLIDE 23

Relation between internal and external states

{Chan[POP3] c; Null n; Null m} ❵ POP3Client : Init <OK: {Chan[Trans] c; int n; Null m}, ERR: {Chan[POP3] c; Null n; Null m}>

POP3Client : <OK: NoMsg, ERR: Init>

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 9 / 12

slide-24
SLIDE 24

Relation between internal and external states

{Chan[POP3] c; Null n; Null m} ❵ POP3Client : Init <OK: {Chan[Trans] c; int n; Null m}, ERR: {Chan[POP3] c; Null n; Null m}>

POP3Client : <OK: NoMsg, ERR: Init> {Chan[Trans] c; int n; Null m} ❵ POP3Client : NoMsg etc.

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 9 / 12

slide-25
SLIDE 25

Subtyping

An object with more methods can be safely used in place of an object with less methods e.g. add fetch(); add getNumberOfMessages() at the end An object with less internal choice (more deterministic) can be safely used in place of an object with more internal choice

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 10 / 12

slide-26
SLIDE 26

Implementation: Bica

A type-checker has been implemented on top of Java, using Polyglot: Bica Implements several extensions wrt the formal system: Shared objects along with linear ones While loops Inheritance Standard Java semantics. Uses Java annotations for session types. http://gloss.di.fc.ul.pt/bica/

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 11 / 12

slide-27
SLIDE 27

Conclusion

Results: Type safety:

Conformance: sequence of method calls on an object always follows its declared session Communication safety in a distributed setting

Typechecking algorithm and prototype implementation

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 12 / 12

slide-28
SLIDE 28

Conclusion

Results: Type safety:

Conformance: sequence of method calls on an object always follows its declared session Communication safety in a distributed setting

Typechecking algorithm and prototype implementation Related to (mainly): Session types for OO languages: Dezani-Ciancaglini et al. Typestates for objects: Bierhoff and Aldrich

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 12 / 12

slide-29
SLIDE 29

Conclusion

Results: Type safety:

Conformance: sequence of method calls on an object always follows its declared session Communication safety in a distributed setting

Typechecking algorithm and prototype implementation Related to (mainly): Session types for OO languages: Dezani-Ciancaglini et al. Typestates for objects: Bierhoff and Aldrich Missing: Aliasing control Can we use existing work? How does it relate with subtyping?

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 12 / 12

slide-30
SLIDE 30

Conclusion

Results: Type safety:

Conformance: sequence of method calls on an object always follows its declared session Communication safety in a distributed setting

Typechecking algorithm and prototype implementation Related to (mainly): Session types for OO languages: Dezani-Ciancaglini et al. Typestates for objects: Bierhoff and Aldrich Missing: Aliasing control Can we use existing work? How does it relate with subtyping? Full version with proofs: technical report available at http://gloss.di.fc.ul.pt/bica/

Gay, Gesbert, Ravara, Vasconcelos and Caldeira Modular session types for objects 12 / 12