Presentation is loading. Please wait.

Presentation is loading. Please wait.

Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07.

Similar presentations


Presentation on theme: "Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07."— Presentation transcript:

1 Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07

2 Types and Programming Languages Lecture 16 - Simon Gay2 Beyond Sequential Programming To illustrate that static type systems can be of use in other contexts, we will move on from sequential programming and look at two areas: concurrent programming and security. First, concurrent programming. There are many ways of formulating concurrent programming. We will look at the pi calculus (  calculus), which is a core concurrent programming language with the following distinctive features: Point-to-point communication between concurrent processes. Channels as first class values. Dynamic creation of channels.

3 2006/07Types and Programming Languages Lecture 16 - Simon Gay3 Pi Calculus Syntax The syntax of processes is defined by this grammar: P ::= stopinactive process | out x(e,...,f)asynchronous output | inp x(y,...,z);Pinput (y,...,z bound with scope P) | new(x);Pchannel creation (x is bound with scope P) | P | Pparallel | repeat Preplication x,y stand for channel names or variables (no need to distinguish) e stands for an expression of SEL (say), so that we have some values and operations (this is useful for examples, although it is possible to encode all computation by means of channels)

4 2006/07Types and Programming Languages Lecture 16 - Simon Gay4 Example: Simple Messages (out a(1) | inp b(x); P(x) ) | (inp a(y); out b(y+1) ) (inp b(x); P(x) ) | out b(1+1) P(2) Abbreviation: write out x(e,...,e); P for out x(e,...,e) | P

5 2006/07Types and Programming Languages Lecture 16 - Simon Gay5 Example: Client/Server Server = repeat inp a(x); inp x(y); out x(y+1) Client1 = new (c); out a(c); out c(2); inp c(x); C(x) Client2 = new (d); out a(d); out d(3); inp d(x); D(x) Server | Client1 | Client2 repeat (inp a(x); inp x(y); out x(y+1)) | new (c); out a(c); out c(2); inp c(x); C(x) | new (d); out a(d); out d(3); inp d(x); D(x) repeat (inp a(x); inp x(y); out x(y+1)) | inp a(x); inp x(y); out x(y+1) | new (c); out a(c); out c(2); inp c(x); C(x) | new (d); out a(d); out d(3); inp d(x); D(x)

6 2006/07Types and Programming Languages Lecture 16 - Simon Gay6 Example: Client/Server repeat (inp a(x); inp x(y); out x(y+1)) | inp a(x); inp x(y); out x(y+1) | new (c); out a(c); out c(2); inp c(x); C(x) | new (d); out a(d); out d(3); inp d(x); D(x) inp c(y); out c(y+1) | out c(2); inp c(x); C(x) (several steps) C(3) repeat (inp a(x); inp x(y); out x(y+1)) | inp a(x); inp x(y); out x(y+1) | new (d); out a(d); out d(3); inp d(x); D(x) | inp c(y);... | out c(2);... reducing inp d(y); out d(y+1) | out d(3); inp d(x); D(x) (several steps) D(4)

7 2006/07Types and Programming Languages Lecture 16 - Simon Gay7 Client/Server: Structure Server (replicated thread) a Client1Client2 Client 1 creates channel c, Server spawns a thread Server thread Client1 c Server (replicated thread) a Client2 Server thread Client1 c Server thread Client2 d

8 2006/07Types and Programming Languages Lecture 16 - Simon Gay8 The Reduction Relation The reduction relation on processes is defined by a few rules: (R-Comm) Values v are channel names or values of SEL. P[v/y,...] is capture-avoiding substitution (rename bound vars if necessary) (R-Par)(R-New) Reduction takes place within parallel combinations and within the scope of new, but not within an input.

9 2006/07Types and Programming Languages Lecture 16 - Simon Gay9 Structural Equivalence To factor out inessential aspects of the way processes are written, introduce the structural equivalence relation. (E-Refl) (E-Symm)(E-Trans) Freely rearrange parallel processes: (E-Com)(E-Assoc) Garbage collection: (E-ParStop)(E-NewStop)

10 2006/07Types and Programming Languages Lecture 16 - Simon Gay10 Structural Equivalence Order of channel creation: (E-NewNew) Scope expansion: (E-NewPar) fn(P) is the set of free names in P Replication: (E-RepPar)

11 2006/07Types and Programming Languages Lecture 16 - Simon Gay11 Structural Equivalence The following rules make structural equivalence into a congruence: equivalence is preserved by all the syntactic constructions. So we refer to structural congruence. (E-Inp)(E-New) (E-Par)(E-Rep)

12 2006/07Types and Programming Languages Lecture 16 - Simon Gay12 Structural Equivalence and Reduction Finally we add a rule which makes the connection between structural equivalence and the reduction relation. (R-Struct) This allows structural equivalence to be used to rewrite a process before or after a reduction step. Structural equivalence allows us to rewrite until an output and a matching input are adjacent; then (R-Comm) gives us a reduction, often inside a parallel collection of processes (using rule (R-Par)) or within the scope of a new channel (using rule (R-New)).

13 2006/07Types and Programming Languages Lecture 16 - Simon Gay13 Example: Client/Server repeat (inp a(x); inp x(y); out x(y+1)) | new (c); out a(c); out c(2); inp c(x); C(x) Server | Client1 =  inp a(x); inp x(y); out x(y+1) | repeat (inp a(x); inp x(y); out x(y+1)) | new (c); out a(c); out c(2); inp c(x); C(x) (E-Rep) (E-Com)  repeat (inp a(x); inp x(y); out x(y+1)) | inp a(x); inp x(y); out x(y+1) | new (c); out a(c); out c(2); inp c(x); C(x)

14 2006/07Types and Programming Languages Lecture 16 - Simon Gay14 Example: Client/Server (E-NewPar)  repeat (inp a(x); inp x(y); out x(y+1)) | new (c); (inp a(x); inp x(y); out x(y+1) | out a(c); out c(2); inp c(x); C(x)) repeat (inp a(x); inp x(y); out x(y+1)) | new (c); (inp c(y); out c(y+1) | out c(2); inp c(x); C(x)) R-Comm, R-New, R-Par repeat (inp a(x); inp x(y); out x(y+1)) | new (c); (out c(2+1) | inp c(x); C(x)) R-Comm, R-New, R-Par

15 2006/07Types and Programming Languages Lecture 16 - Simon Gay15 Example: Client/Server repeat (inp a(x); inp x(y); out x(y+1)) | new (c); (out c(3) | inp c(x); C(x)) reductions in SEL repeat (inp a(x); inp x(y); out x(y+1)) | new (c); C(3) R-Comm, R-New, R-Par  (if c  fn(C)) repeat (inp a(x); inp x(y); out x(y+1)) | C(3)

16 2006/07Types and Programming Languages Lecture 16 - Simon Gay16 Exercise One of the reductions in the example is labelled “reductions in SEL”. How should we formally include reductions in SEL into the definition of reductions in pi calculus?

17 2006/07Types and Programming Languages Lecture 16 - Simon Gay17 Facts about Pi Calculus Even without including SEL (so we just have channel names and pure communication), pi calculus is able to express all computation. Data can be represented by the use of channels. Recursive process definitions can be encoded by using replication (repeat). Theories of behavioural equivalence can be developed, supporting reasoning about correctness of systems. Numerous variations of pi calculus exist, including concepts such as locations and distribution, failure of processes or locations, time, …


Download ppt "Types and Programming Languages Lecture 16 Simon Gay Department of Computing Science University of Glasgow 2006/07."

Similar presentations


Ads by Google