Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/234779166

Linearity and the Pi-Calculus

Article  in  ACM Transactions on Programming Languages and Systems · December 1999


DOI: 10.1145/330249.330251 · Source: DBLP

CITATIONS READS
289 101

3 authors, including:

Naoki Kobayashi Benjamin C. Pierce


The University of Tokyo University of Pennsylvania
176 PUBLICATIONS   3,688 CITATIONS    234 PUBLICATIONS   9,781 CITATIONS   

SEE PROFILE SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Verification of concurrent programs View project

Higher-Order Model Checking View project

All content following this page was uploaded by Benjamin C. Pierce on 20 August 2014.

The user has requested enhancement of the downloaded file.


Linearity and the Pi-Calculus

Naoki Kobayashi Benjamin C. Pierce David N. Turner


University of Tokyo University of Cambridge University of Glasgow
koba@is.s.u-tokyo.ac.jp bcp1000@cl.cam.ac.uk dnt@dcs.gla.ac.uk

Abstract throw away potentially useful information. A common re-


sponse to this observation is to consider larger calculi with,
The economy and exibility of the pi-calculus make it attrac- for example, functions as primitives. This ensures, at some
tive both as an object of theoretical study and as a basis for cost in parsimony, that functions can be compiled eciently
concurrent language design and implementation. However, and that the expected high-level rules for reasoning (either
such generality has a cost: encoding higher-level features like formally or informally) actually apply. A more radical ap-
functional computation in pi-calculus throws away poten- proach | the one we are exploring here | is to avoid adding
tially useful information. We show how a linear type system new primitives and instead recover information about spe-
can be used to recover important static information about cial \modes of usage" from static type information.
a process's behaviour. In particular, we can guarantee that
two processes communicating over a linear channel cannot
interfere with other communicating processes. This enables 1.1 Encoding functional computation
more aggressive optimisation of communications over linear The following example illustrates how one can encode func-
channels and allows useful re nements to the usual notions tions and function application (cf. [Mil90, San93]) in a pure
of process equivalence for pi-calculus. message-passing calculus, and also highlights some of the
After developing standard results such as soundness of pitfalls of such encodings.
typing, we focus on equivalences, adapting the standard no- Suppose that plusone is a communication channel and
tion of barbed bisimulation to the linear setting and showing that there is some running process that repeatedly reads
how reductions on linear channels induce a useful \partial pairs [i; r] from plusone, with i a number and r a channel,
con uence" of process behaviors. and responds in each case by sending the value i + 1 on r.
(Numbers can themselves be implemented using processes
1 Introduction and channels, but that need not concern us here.) We may
speak of the channel plusone as the \location" of the incre-
A long line of formal systems, from Hewitt's Actors [Hew77, menting process, since plusone is the only means by which
Agh86] to modern process calculi like Milner, Parrow, and other processes can refer to it. To build another function us-
Walker's pi-calculus [MPW92, Mil91], have popularized the ing this one, suppose we are given another channel plustwo
idea that a range of concurrent programming idioms can be to serve as the location for the new process. We create a
modeled by simple processes exchanging messages on chan- process that repeatedly reads pairs [j; s] from plustwo and
nels. Besides their immediate applications in speci cation uses plusone twice, returning the nal result, j + 2, along
and veri cation of concurrent systems, these calculi have the channel s:
been used as the basis for concurrency features in numer- plustwo?3 [j; s]:
ous programming languages (e.g. [Car86, GMP89, Rep91]),
as foundations for theoretical study of language features like ( r1 ; r2 )
concurrent objects (e.g. [Jon93, Wal95, HT91, Vas94, KY94, ( plusone![j; r1 ]
KY95]), and more recently as core programming languages j r1 ?[k]:
in their own right [PT95a, PT95b, FG96]. plusone![k; r2 ]
The small set of message-passing primitives used by the j r2 ?[l]: s![l])
pi-calculus makes it attractive both as an object of theoret- The replicated input expression plustwo?3 [j; s]: : : : describes
ical study and as a basis for language design and implemen- a process that, each time it receives a pair [j; s] on the chan-
tation. However, such generality has a cost: the pi-calculus nel plustwo, starts a fresh copy of its body running in par-
is an extremely low-level notation, and encoding higher-level allel with all the other processes in the system. Each copy
features (such as functional computation) in pi-calculus can of the body (i.e., each invocation of the function) creates
Permission to make digital/hard copies of all or part of this two fresh channels, r1 and r2 , using the channel-creation
material for personal or classroom use is granted without fee operator  . Then it sends the message [j; r1 ] on the channel
provided that the copies are not made or distributed for pro t plusone (written plusone![j; r1 ]) and, in parallel, waits to re-
or commercial advantage, the copyright notice, the title of the
publication and its date appear, and notice is given that copyright ceive a response k on the \continuation channel" r1 (written
is by permission of the ACM, Inc. To copy otherwise, to republish, r1 ?[k]: : : : ). When this arrives, it sends the message [k; r2 ]
to post on servers or to redistribute to lists, requires speci c
permission and/or fee. on plusone and waits for the response l along r2 . Finally, it

POPL '96, St. Petersburg FLA USA
c 1996 ACM 0-89791-769-3/95/01
sends l back along the continuation channel s to the original plusone is used just once. Without this information, we are
caller. not justi ed in replacing our plustwo example with a more
In this example, we used the convention that a function ecient \tail-call optimized" form:
is a process reading messages from some channel f , while
callers of the function are processes that send messages on f . plustwo?3 [j; s]:
Unfortunately, there is nothing in the pi-calculus' notation ( r) (plusone![j; r] j r?[k]: plusone![k; s])
that prevents another process from disrupting this protocol, To see that this version does not have the same behavior as
either maliciously or accidentally, by reading from f instead the original in all contexts, imagine that the increment pro-
of writing to it. The asymmetry of roles between function cess actually signals twice on its result channel. The tail-call
and caller has been lost. This lack of structure can lead to optimized implementation above makes this fact visible to
errors in more complex programs, and blocks many useful its own caller, generating two messages on the result chan-
optimizations and program transformations. nel s, whereas the original implementation sends just one
message on s.
1.2 Arities and polarities
The simplest type systems for the pi-calculus [Mil91] just 1.3 Linear types
track the arities of channels, in order to prevent situations We propose here a more re ned pi-calculus type system, in
where the tuple of arguments provided by a sender is not the which channel types have not only polarities, which deter-
same width as the tuple of bound variables in the receiver, as mine the directions in which they can be used, but also mul-
in x![y; z] j x?[a; b; c]: P . Each channel x is assigned a type of tiplicities, which control how many times they can be used.
the form l[T1 ; : : : ; Tn ], read \channel carrying T1 ; : : : ; Tn ," For example, the type !1 [Num] describes a channel that can
describing the number of values in each message sent along be used exactly once to send a message containing a num-
x, as well as their types. For example, the channel plustwo ber, while !! [Num] describes a channel that can be used
would be given the type l[Num; l[Num]], since it is used to any number of times. In a pi-calculus with linear channel
communicate pairs where the rst element is a number and types, we can take the type of plusone and plustwo, from
the second is a channel that is used to send a single number. the point of view of callers, to be !! [Num; !1 [Num]], captur-
This type system can be extended in many ways, for ing the fact that each of them can be invoked any number
instance by adding polymorphism [Gay93, VH93, Tur95, of times but that the result channel in each invocation is
LW95b]. Of more interest here, however, is the possibil- only used once. Under this more accurate typing, the orig-
ity of re ning it so that the types of channels carry more inal and tail-call optimized versions of our plustwo example
information about how they are used. For example, we can are provably equivalent in the sense that they behave the
straightforwardly capture the polarity (or directionality) of same in all well-typed contexts, as we show in Section 6.2.
communications on channels like plustwo by introducing two Actually, the re ned typings of plusone and plustwo are in-
new channel types: ![T1 ; : : : ; Tn ] for channels that (in a given stances of a general observation: using techniques similar to
context) can only be used to send tuples of type [T1 ; : : : ; Tn ], those in [Tur95, PS93], it is easy to show that every result
and ?[T1 ; : : : ; Tn ] for channels that can only be used to re- channel used in the pi-calculus encoding of a lambda-term
ceive [T1 ; : : : ; Tn ]-tuples [PS93, Ode95]. From the point of can be assigned a linear type.
view of the process implementing the increment function, Not only are some useful equivalences gained in the pres-
the type of plusone now becomes ?[Num; ![Num]] | that is, ence of linear types; even the mechanics of reasoning about
it can only be used to read messages, where each message processes can be augmented, since (in the absence of non-
must consist of a number and a channel that can be used to local operators like choice) two processes communicating
send a response. From the point of view of the users of this over a linear channel can neither interfere with nor be af-
function, plusone has type ![Num; ![Num]]: it can only be fected by other communicating processes. This stands in
used to send messages, and each message must again con- sharp contrast to the usual situation in the pi-calculus, where
sist of a number and a channel that can be used for sending the possibility that two senders can be in competition for
numbers. one receiver or vice versa introduces an essential element of
This re nement is not only useful for preventing pro- non-determinism. The expression x![y ] j x![z ] j x?[a]: a![ ] can
gramming mistakes; it also yields more powerful techniques reduce either to x![z] j y![ ] or to x![y ] j z ![ ], and these cannot
for reasoning about programs. For example, in an early be reduced further so as to reach a common point. On the
draft of [Mil90], Milner had proposed two encodings of the other hand, there can never be two senders or two receivers
call-by-value lambda-calculus into the pi-calculus. Unfor- on a linear channel, and so such race conditions can never
tunately, the simpler of the two encodings turned out not arise. Indeed, linear communications exhibit a partial con-
to preserve beta-equivalence, because of the possibility that uence property reminiscent of the Church-Rosser property
the external environment might use channels generated by of the lambda-calculus, as we show in Section 4.4.
the encoding in the wrong direction [San92]. Pierce and Linear typing potentially enables a variety of compiler
Sangiorgi [PS93] showed how the validity of beta-reduction optimizations. The impact of these optimizations in prac-
could be established by typing the encoding using input- tice is not yet clear, but work is underway on evaluating
only and output-only channels. In essence, re ning the type several in a compiler for a linear variant of Pict, a program-
system reduces the number of contexts in which a given pro- ming language based on the pi-calculus [PT95a, PT95b]. For
cess can correctly be placed, thus making it easier for two example, the implementation of communication on a linear
processes to be equivalent. channel can be simpli ed from the current Pict implementa-
However, some useful information cannot be captured tion, since a linear channel can only be in one of two states
by simple polarized channel types. For example, we cannot when a communication occurs: there may be either zero or
express the fact that the result channel that is passed to one processes of opposite polarity waiting to communicate,
but never more than one and never another one of the same studied in later sections are sensitive to the exact choice of
polarity. In addition, the heap space allocated to a linear calculus; in particular, partial con uence of linear communi-
channel can immediately be re-used by the receiver after a cations fails in the presence of a general choice operator.) We
communication, instead of being reclaimed by garbage col- also provide booleans and conditional expressions as primi-
lection. tives, since their typing behavior interacts with linearity in
Linear channel types can also help detect common pro- a slightly special way.
gramming mistakes. For example, it is often the case that
a process must signal on some channel to indicate that it is 2.1 Syntax
leaving a \critical section." Suppose c is the channel upon on
which we are supposed to signal completion. If the critical The metavariable m ranges over the multiplicities 1 and ! .
section is complex, it is easy to forget to signal completion The metavariable p ranges over polarities. Formally, these
on c, or to signal twice on c. However, if c is given a linear are subsets of the set of capabilities fi; og, but for readability
type, our typing rules will ensure that c is used exactly once. we use the abbreviations l = fi; og, ! = fog, ? = fig, and
Note that we must be slightly careful about what \ex- j = fg. The set of types is:
actly once" means here: typing is preserved by reduction
(cf. Section 4.3), so a process containing exactly one use of T ::= pm [T~] channel types
c must either communicate on c and evolve to a process that Bool booleans
cannot use c, or else make some other step and become a For example, the type ! [Bool] (i.e. fog1 [Bool]) describes
1
process that still contains one use of c, or else do nothing at a channel that can be used exactly once to send a message
all. This guarantees that c will never be used twice, but not containing a boolean, while l1 [Bool] describes a channel that
that c will eventually be used, since the subprocess in which can be used once for input and once for output. For brevity,
c occurs might diverge or deadlock before it actually com- sequences of types, etc. are written T~ instead of T1 ; : : : ; Tn .
municates on c. For example, the process (z : l! [ ]) z?[ ]: c![ ]
creates a fresh channel z , reads from it, and then sends on c. A type of the form p1 [T~], where p 6= j, is called limited. All
Since z is fresh, there can never be any sender on z , and the other types are unlimited. An example of an unlimited type
send on c will never be reached. This possibility of partial is !! [Bool; !1 [Bool]], which describes a channel upon which
deadlock or divergence in the pi-calculus gives linear typing we can send any number of messages, but where the compo-
a slightly di erent force than in lambda-calculus, where a nents of each message must be a boolean and a linear output
linear value must be used unless the whole program fails to channel.
yield any result. The set of process expressions is:
P ::= P j Q parallel composition
1.4 Overview x![~y] output atom
x?[~y]: P input pre x
Our goals in this paper are (1) a precise de nition of a pi- x?3 [~y]: P replicated input
calculus with linear types and (2) formal justi cations of (x : T ) P channel creation
the claims sketched here about typing and program equiva- if x then P else Q conditional
lences. The novel aspects of this development are the techni- To avoid writing too many parentheses, we give  a higher
cal treatment of linear channel types (which, since they have precedence than j and make the bodies of inputs extend as
both input and output ends, actually comprise two linear far to the right as possible, so that x?3 [ ]: (y : l! [ ]) x![ ] j y![ ]
capabilities) and, more importantly, the study of behavioral means x?3 [ ]: (((y : l! [ ]) x![ ]) j y![ ]). The \inert process" is
equivalences in the presence of linear types. de ned as 0 = (x : l! ) x![ ].
After introducing some notational conventions in Sec- The free and bound variables of a process expression are
tion 2, we de ne the typing relation (Section 3) and show de ned in the usual way, with x having scope P in (x : T ) P
that it is preserved by reduction (Section 4); along the way, and y~ having scope P in x?[~y]: P and x?3 [~y]: P .
we remark on properties such as con uence. In Section 5,
we adapt the standard notion of barbed congruence to the
present setting. Section 6 extends the results on strong 2.2 Type environments
barbed congruence to the more useful weak case, which is A type environment 0 is a set of bindings of distinct vari-
used to prove the two versions of plustwo equivalent. Sec- ables to types, containing at least the bindings true : Bool
tion 7 discusses related work and Section 8 sketches several and false : Bool. By convention, we write type environments
variations on the system studied here. Proofs omitted in as x1 : T1 ; : : : ; xn : Tn or just x~:T~, omitting the bindings of
this summary can be found in an accompanying technical the booleans. The domain of a type environment, writ-
report [KPT95]. ten dom(0), is the set of variables it binds. Type envi-
ronments are extended with bindings for new variables by
2 Notational Preliminaries writing 0; x : T or 0; x~:T~. We write 0(x) = T to mean that
0 = 01 ; x : T for some 01 . A type environment is unlimited
The operators introduced in the examples above constitute if each of its bindings is.
a fragment of the polyadic pi-calculus [Mil91], omitting the We always consider a process relative to a particular type
choice and matching operators (as in Milner's mini pi-calculus environment, whose domain must contain all the free vari-
[Mil90]) and using only asynchronous communication (as in ables of the process. We regard names of bound variables
Honda and Tokoro's  -calculus [HT91]). We have argued as inessential and perform silent alpha-conversion as neces-
elsewhere for the pragmatic virtues of this calculus [PT95a], sary to ensure that the name of a bound variable is always
but many of the techniques we develop should be applicable di erent from the names of free variables and other bound
to any similar system. (Of course, the behavioral properties variables.
2.3 Operations on types so that typing P j Q consumes the sum of the resources used
in the proofs that P and Q are well typed. (We only consider
The combination of two types T1 and T2 , written T1 + T2 , is instances of this rule scheme where 01 + 02 is well de ned.)
de ned as follows (in all cases other than those mentioned The typing judgement 0 ` P thus acquires additional force:
below, T1 + T2 is unde ned): \P is well typed under the typing assumptions in 0 and,
Bool + Bool = Bool moreover, uses each linear capability in 0 just once."
Like some linear type systems, we omit the rule of dere-
p! [T~] + q! [T~] = (p [ q )! [T~] liction from linear logic, which allows an unlimited chan-
p1 [T~] + q1 [T~] = (p [ q )1 [T~] if p \ q = ; nel to be coerced to a linear one. If our type system had
a subtyping relation, we would similarly ban the coercion
Similarly, the di erence of two types T1 and T2 , written pw [T~]  p1 [T~]. The worlds of linear and unlimited values
T1 0 T2 , is: are never allowed to mix.
Bool 0 Bool = Bool Our typing rules di er in one other technical detail from
p! [T~] 0 q! [T~] = p! [T~] if q  p the usual formulations of linear logics and type systems.
Normally, when a type environment is \split," only those
p1 [T~] 0 q1 [T~] = (p n q)1 [T~] if q  p variable bindings that are actually used in the right and
left subderivations are included in the respective \halves"
Note that T 0 T is not necessarily a type with j polarity: of 0. For example, to check x : !1 [ ]; y : !1 [ ] ` x![ ] j y![ ], we
we use 0 to remove a single instance of a capability; if the check x : !1 [ ] ` x![ ] and y : !1 [ ] ` y ![ ]. We nd it clearer to
capability can be used an unlimited number of times | i.e., split type environments by removing just capabilities, leav-
if the type is Bool or an unlimited channel type | then it ing variable bindings in place, so that the combination op-
is unchanged by the operation. erator + is always applied to environments with equal do-
The + operator is extended pointwise to type environ- mains. To type x![ ] j y ![ ] in the environment x : !1 [ ]; y : !1 [ ],
ments with equal domains: we check x![ ] in x : !1 [ ]; y : j1 [ ] and y![ ] in x : j1 [ ]; y : !1 [ ].
(01 ; x : T1 ) + (02 ; x : T2 ) = (01 + 02 ); x : (T1 + T2 ) To ensure that all the linear bindings in the environment
get used somewhere, we check at all the leaves of the typ-
We also use + and 0 to \add and remove capabilities" from ing derivation | i.e., at all instances of the typing rule for
a single existing binding in an environment. When 0 = output expressions | that all the remaining bindings in the
00 ; x : U , we write 0+ x : T to mean 0; x : (U +T ) and 00 x : T current environment have either multiplicity ! or polarity j:
to mean 0; x : (U 0T ). To account for the e ect of \using up"
a value of type T , we write T 0 T for the remnant of T . The 0 unlimited
set of remnants of a type environment 1, written Rems (1), (E-Out)
comprises all the type environments that can be obtained 0 + x : !m [T~] + y~:T~ ` x![~y]
from 1 by replacing some subset x1 : T1 ; : : : ; xn : Tn of its
bindings by their remnants x1 : T1 0 T1 ; : : : ; xn : Tn 0 Tn . That is, if all the bindings in 0 are unlimited, then x![~y]
is well typed in 0 augmented (in case x or any of the y~
are linear) with the capabilities consumed by the output
3 Typing itself. Note that the capabilities expressed by the types T~
are consumed by the output, since the arguments y~ are being
Our linear channel types are inspired by Girard's linear passed to the receiver of the communication.
logic [Gir87, GLT89], a \resource conscious" re nement of Conversely, an input expression is well typed if its body
classical logic, and by numerous proposals for functional lan- is well typed in an environment where the capability to input
guages based on linear logic (e.g. [Abr93, Wad91, Bak92, from x has been removed (if it is linear) and the capabilities
Mac94, TWM95]). A crucial element in these systems is the associated with the values z~ to be read from x have been
careful treatment of the typing environments under which added.
expressions are judged to be well typed. For example, to
form a pair of two values v and w under some type environ- 0; z~:T~ ` P
ment 0 in a linear lambda-calculus, we do not simply check (E-In)
that v and w are well typed in 0: 0 + x : ?m [T~] ` x?[~z]: P
0`v2V 0`w2W The rule for replicated input is nearly the same, except that
0 ` hv; wi 2 V 2 W the type of x must be unlimited and, since the body may be
instantiated many times, we must ensure that the common
Instead, we split the type environment in the conclusion into part of the type environment does not contain any linear
two parts, representing the resources consumed by v and w bindings.
separately:
01 ` v 2 V 02 ` w 2 W 0; z~:T~ ` P 0 unlimited
01 + 02 ` hv; wi 2 V 2 W (E-RIn)
0 + x : ?! [T~] ` x?3 [~z]: P
Similarly, in a linear type system for the pi-calculus, we must
split the type environment in the rule for parallel composi- The rule for  -expressions adds the given type for x to the
tion, type environment. The side-condition veri es that the sup-
plied type is a reasonable one for a channel declaration (i.e.
01 ` P 02 ` Q not Bool and not a type that would allow only input or only
(E-Par)
01 + 0 2 ` P j Q output, which would be silly).
0; x : pm [T~] ` P p = j or l Informally, it says that the scope of the channel x, which
(E-New)
0 ` (x : p [T ]) P
m ~ starts out private to the process P , can be extended to in-
clude Q. The side-condition ensures that Q does not already
The rule for checking conditional expressions is a little dif- have a free channel named x. (This condition can always be
ferent from the others (it corresponds to one of the additive satis ed by renaming x, if necessary, before applying the
operators of linear logic, while the rest of our operators be- scope extrusion rule.) For example, the process
long to the multiplicative part). We know that the \then" ((x : l! [ ]) w![x]) j w?[z]: z![ ]
and \else" parts of an if-clause will never both be executed,
so any linear bindings in the environment should be used up may be transformed to
by both parts, instead of being allocated to one part or the
other. (x : l! [ ]) (w![x] j w?[z]: z![ ])
0 ` P1 0 ` P2 Finally, for technical convenience, we allow adjacent channel
(E-If) bindings to be switched:
0 + b : Bool ` if b then P1 else P2
The typing relation 0 ` P , then, is the least relation closed (x : T ) (y : U ) P  (y : U ) (x : T ) P x 6= y (S-Switch)
under the foregoing rules. A process well typed under 0 is
called a 0-process. Formally, the relation  is the least congruence closed under
Although we are not concerned with algorithmic issues these four rules, meaning that P  Q if Q can be obtained by
in this paper, it is worth noting that these rules give rise applying the rules any number of times, in either direction,
to a typechecking algorithm in a fairly straightforward way. to arbitrary subexpressions of P .
Instead of \guessing" how to split the capabilities in the 4.1.1 Lemma: If P  Q, then 0 ` P i 0 ` Q.
environment in rules like E-Par, we pass the whole envi-
ronment to the lefthand premise, crossing o capabilities as 4.1.2 De nition: A process ( x~ :T~) (P1 j 1 1 1 j Pn ) is in nor-
they are used up and passing whatever is left to the right- mal form if P1 ; : : : ; Pn are guarded processes, where a pro-
hand premise. There is some cost associated with checking cess is guarded if it is an input, output, replicated input, or
the \0 unlimited" side conditions, but a few simple tricks conditional.
keep this small in practice.
4.1.3 Lemma: For any process P there is some Q in nor-
4 Operational Semantics mal form such that P  Q.
Following [Mil91], the operational semantics of processes is Proof: By the associativity and commutativity of j and
presented in two steps. First, we de ne a structural congru- the fact that any ( x~ :T~) not guarded by an input can be
ence relation P  Q, capturing the fact that, for example, moved to the outside of the expression using S-Extr. 3
the order of the branches in a parallel composition has no
e ect on its behavior. Then we de ne a reduction relation
0 ` P 0! Q, specifying how processes evolve through com- 4.1.4 Lemma: If the processes ( x~:T~) (P1 j 1 1 1 j Pn ) and
munications between their subprocesses. ( y~:U~ ) (Q1 j 1 1 1 j Qm ) are normal forms that are both struc-
turally congruent to P , then x~ :T~ is a permutation of y~:U~ ,
m = n, and, for some permutation Q01 ; : : : ; Q0n of Q1 ; : : : ; Qn ,
4.1 Structural congruence Pi  Q0i for 1  i  n.
Structural congruence plays an important technical role in
simplifying the de nition of the reduction relation. For ex- Proof: Structural congruence neither introduces nor elim-
ample, we intend that both the process x![ ] j x?[ ]: P and the inates guarded subexpressions or  -bindings, and does not
process x?[ ]: P j x![ ] reduce to P . Since these two will be move subexpressions across input pre xes. 3
structurally congruent, it suces to write the reduction rule
only for the rst case and to stipulate, in general, that if 4.2 Reduction
P contains some possibility of communication, then so does
any expression structurally congruent to P . For experts, our The pi-calculus reduction relation is usually written P 0!
structural congruence relation is identical to the usual one, Q, meaning that P can evolve to Q by making a single,
except that we drop some \garbage collection" rules. atomic step of communication. We use the same basic rela-
The rst two structural congruence rules state that j is tion, but annotate it with some extra information that we
commutative and associative. need later for stating properties of the semantics. We write
m;
0 ` P 0000! Q, where 0 is a type environment (to remind
P jQ  QjP (S-Commut) ourselves that we are interested in reduction of well-typed
processes, and so that we can see the way communication
(P j Q) j R  P j (Q j R) (S-Assoc) uses up capabilities of linear channels), m is a multiplicity
tag (recording whether the communication that leads from
P to Q occurs on a linear or an unlimited channel), and
The third rule is called scope extrusion in the pi-calculus can be either the name of a channel, indicating where
literature: the communication occurs, or else the special tag  , indicat-
ing that the channel on which the communication occurs is
(x : T ) P j Q  (x : T ) (P j Q) x not free in Q (S-Extr) bound by a  that is not in scope at this point.
The most important reduction rule is the one for com- When we want to be explicit about the typing environ-
munication. In an environment where x has a channel type ment in force after a reduction has occurred, we write 0 `
m;
of multiplicity m, the parallel composition of an output and P 0000! P 0 a 00 , where
an input on x can evolve to the body of the input-process 
with the arguments to the output substituted for the formal 0 if = 
parameters. We record m and x on the arrow. 00 = 0 0 x : 0(x) if = x:
m;x That is, if the label on the arrow is  , then the binder of the
0; x : lm [T~] ` x![~y] j x?[~z]: P 000! [~y=z~]P (R-Com)
channel x on which the communication occurred is within
P and there is nothing to do; on the other hand, if the label
Similarly, an output in parallel with a replicated input can is x, then we must remove an instance of the type of x from
reduce to the appropriate instance of the body of the in- the capabilities in 0.
put plus a fresh copy of the replicated input itself, ready to As usual, we write 0 ` P 0!3 Q or 0 ` P 0!3 Q a 00
consume further outputs on x. to show that P reduces to Q in zero or more steps.
m;x
0; x : lm [T~] ` x![~y] j x?3 [~z]: P 000! [~y=z~]P j x?3 [~z]: P 4.3 Type soundness
(R-RCom)
The sine qua non of an operational semantics for a typed
If P can reduce to Q in isolation, then it can still do so when language is that well-typedness must be preserved under re-
it is placed in parallel with some other process R: duction.
4.3.1 Theorem [Subject Reduction]: If 0 ` P and 0 `
m; m;
01 ` P 0000! Q P 0000! P 0 a 00 , then 00 ` P 0 .
m; (R-Par)
01 + 02 ` P j R 0000! QjR Because our operational semantics is careful to \cross
out" linear capabilities as it uses them, the subject reduc-
Similarly, if P reduces to Q, then it can still do so when tion theorem together with the following theorem implies
placed under a  . However, because of our extra annota- that linear channels are used at most once (in addition to
tions, we must divide this rule into two cases. If the channel the standard observation that there can never be any arity
bound by the  is the very channel x on which the communi- mismatch during the execution of a well-typed program).
cation in P has occurred, then we change the label x on the We use the shorthand f j Qg to stand for either nothing
arrow to  and change the polarity of the type of x in the or a parallel composition with a process Q.
 -binding to its \remainder"; this has the e ect of changing
its polarity to j if its multiplicity is linear, and has no e ect 4.3.2 Theorem [Run-time safety]: A well-typed process
if its multiplicity is unlimited. contains no immediate possibilities for communication fail-
ure or misuse of capabilities. More formally, if 0 ` P and
m;x P  ( w~ :U~ ) (Qf j Rg) then:
0; x : T ` P 000! Q
m; (R-New1) 1. If Q is an input x![y1 ; : : : ; ym ] j x?[z1 ; : : : ; zn ]: Q1 or
0 ` (x : T ) P 000! (x : T 0 T ) Q a replicated input x![y1 ; : : : ; ym ] j x?3 [z1 ; : : : ; zn ]: Q1 ,
then m = n and the binding of x (in either P or 0)
On the other hand, if the communication in P occurs on has polarity l.
some other channel, then we simply pass the labels through
the  unaltered. 2. If Q = x![~y], then the binding of x has a polarity in-
cluding !.
m;
0; x : T ` P 0000 ! Q x 6= 3. If Q = x?[~y]: Q1 , then the binding of x has a polarity
m; (R-New2) including ?.
0 ` (x : T ) P 0000! (x : T ) Q
4. If Q = x![~y] j x![~z], then the binding of x has multiplic-
An if-expression reduces to either its then-branch or its else- ity !.
branch, depending on its guard. 5. If Q = (x?[~y]: Q1 ) j (x?[~z]: Q2 ), then the binding of x
has multiplicity !.
1;
0 ` if true then P else Q 000!P (R-IfT) 6. If Q = x?3 [~y]: Q1 , then the binding of x has multiplic-
ity !.
1;
0 ` if false then P else Q 000!Q (R-IfF) Finally, it is worth mentioning that the type annota-
tions and other labels in this semantics are used just for
Finally, if P can be rearranged to some P 0 using the struc- bookkeeping, and do not play any role in determining the
tural congruence laws so that a communication is possible possible behaviors of well-typed process expressions.
in P 0, then the same communication is possible in P .
4.3.3 Theorem: On well-typed processes, our operational
m; semantics allows the same reductions as the standard un-
P P 0
0 ` P 0000! Q
0 0
Q 0
Q (R-Cong) typed semantics (which can be obtained from ours by eras-
m; ing all types, type environments, and labels on arrows).
0 ` P 0000!Q
4.4 Partial con uence are normal forms, because otherwise we can obtain normal
forms of P2 ; P20 and then move the  to the outside. By
We now come to the rst results that show how linearity Lemma 4.1.4, w~ :W ~ is a permutation of w~ 0 :W ~ 0 . Moreover, let
a ects reasoning about program behavior. The rst the- P20 = R1 j 1 1 1 j Rn for guarded processes R1 ; : : : ; Rn . Then
orem below says that communication on a linear channel either x?[~z]: P1  x?[~z]: P10 or x?[~z]: P1  Ri for some i. The
is deterministic. The second says: If P is a process that latter case cannot happen; Ri must be in the form x?[~u]: Ri0 ,
contains two possible communications, one of which is on but this contradicts the fact that
a linear channel, then they may be performed in either or-
der to reach the same result. In a word, linear reduction is 0 ` ( w~ 0 :W
~ 0 ) (x![y~0 ] j x?[z~0 ]: P10 j P20 )
con uent with respect to all other reductions.
and 0(x) = l1 [T~]. Therefore, we obtain x?[~z]: P1  x?[z~0 ]: P10 .
1;x 1;x
4.4.1 Theorem: If 0 ` P 000! Q and 0 ` P 000! R, Similarly, we have x![~y]  x![y~0 ], which implies
then Q  R.
Q  ( w~ :W ~ ) ([~y=z~]P1 f j P2 g)
4.4.2 Theorem [Partial con uence]: If 0 ` P and 0 `  ( w~0 :W~ 0 ) ([y~0 =z~0 ]P10 f j P20 g)
1;
P 000! P 0 a 00 , then, for any Q, m, and such that  R;
m;
0 ` P 0000! Q a 1 and P 0 6 Q, there is some R such that as required. 3
1; m;
1 ` Q 000! R and 00 ` P 0 0000! R. 1; m;
Proof of Theorem 4.4.2: Suppose that 000! and 0000!
The proofs of 4.4.1 and 4.4.2, which occupy the rest of both come from communications with unreplicated inputs.
this section, may safely be skipped on a rst reading. We (The cases for replicated input and conditional are similar.)
begin with one technical lemma. From the assumption and Lemma 4.4.3,
4.4.3 Lemma: If 0 ` P 0000 m;
! P 0 , then there are Q, Q0 P  ( w~ :W ~ ) (x![~y] j x?[~z]: P1 j P2 )
such that one of the following holds, P  ( w~ :W
0 ~ 0 ) ([~y=z~]P1 j P2 )
P  ( u~:U~ ) (v![y~0 ] j v ?[z~0 ]: P3 j P4 )
1. Q = ( w~ :W~ ) (x![~z] j x?[~y]: Q1 f j Rg) and Q  ( u~:U~ 0 ) ([y~0 =z~0 ]P3 j P4 )
Q = ( w~ : W~ 0 ) ([~z=y~]Q1 f j Rg),
0
where, if wi = x, then Wi0 = Wi 0 Wi , and otherwise where Wi0 = Wi 0 Wi if wi = x, and otherwise Wi0 = Wi ,
Wi0 = Wi ; and where the binding of x in 0 or w~ :W ~ is l1 [T~]. Also,
Ui0 = Ui 0 Ui if u = v, otherwise Ui0 = Ui . We can assume,
2. Q = ( w~ :W~ ) (x![~z] j x?3 [~y]: Q1 f j Rg) and without loss of generality, both
Q = ( w~ :W
0 ~ ) ([~z=y~]Q1 j x?3 [~y]: Q1 f j Rg); ( w~ :W~ ) (x![~y] j x?[~z]: P1 j P2 ) and
( u~:U~ ) (v ![y~0 ] j v?[z~0 ]: P3 j P4 ) are in normal forms. From the
3. Q = ( w~ :W~ ) (if true then Q1 else Q2 f j Rg) and assumption P 0 6 Q, we have x 6= v, because otherwise
Q0 = ( w~ :W~ ) (Q1 f j Rg); or by Lemma 4.1.4 and the linearity of x, we have x![~y] 
~ ) (if false then Q1 else Q2 f j Rg) and v![y~0 ]; x?[~z]: P1  x?[z~0 ]: P3 ; P2  P4 , from which we obtain
4. Q = ( w~ :W P 0  Q.
Q = ( w~ :W
0 ~ ) (Q2 f j Rg); By Lemma 4.1.4,
and such that P  Q, P 0  Q0 , and 0
m;
` Q 000! Q0 is P2  v![y~0 ] j v?[z~0 ]: P30 j R1 j 1 1 1 j Rn
derivable without using R-Cong. P4  x![~y] j x?[~z]: P10 j R01 j 1 1 1 j R0n
P1  P10 ; P3  P30 ; Ri  R0i (1  i  n)
Proof: From the fact that R-Cong and R-New2 can be ~ is a permutation of u~:U~ . Let
permuted after the other rules and successive applications and w~ :W
of R-Cong can be combined into one R-Cong. 3 R = ( w~ :W ~ 00 ) ([~y=z~]P1 j [y~0 =z~0 ]P3 j R1 j 1 1 1 j Rn );
Proof of Theorem 4.4.1: By the reduction rules, 0(x) =
1;x
where Wi00 = Wi 0 Wi if wi = x or wi = v, and otherwise
l1 [T~]. From 0 ` P 000 ! Q and Lemma 4.4.3, 1;
Wi00 = Wi . Then, 1 ` Q 000! m;
R, and 00 ` P 0 0000! R.
3
P  ( w~ :W~ ) (x![~y] j x?[~z]: P1 f j P2 g)
and 5 Strong Bisimilarity
Q  ( w~ :W
~ ) ([~y=z~]P1 f j P2 g):
1;x Our nal task is to formalize process equivalence in the
Also, from 0 ` P 000 ! R and Lemma 4.4.3, presence of linear types, so that we can check that equiv-
alences like those claimed in the introduction really hold.
P  ( w~ 0 :W
~ 0 ) (x![y~0 ] j x?[z~0 ]: P10 f j P20 g) We adapt Milner and Sangiorgi's notion of barbed bisimilu-
lation [MS92, San92], which is suited to the job for several
and reasons. First, it is naturally a relation on typed processes,
R  ( w~ 0 :W~ 0 ) ([y~0 =z~0 ]P10 f j P20 g): which is crucial here. Second, it is a fairly \modular" de ni-
We can assume, without loss of generality, that tion, in the sense that barbed bisimilarities for many di er-
ent calculi can be formulated almost identically; this facili-
( w~ :W~ ) (x![~y] j x?[~z]: P1 f j P2 g) tates comparison and helps give con dence that the de ni-
and ( w~ 0 :W~ 0 ) (x![y~0 ] j x?[z~0 ]: P10 f j P20 g) tion is natural. And nally, like all varieties of bisimilarity,
it comes with a coinductive proof technique. We begin by 5.1.2 De nition [Strong barbed bisimulation]: A rela-
establishing the basic theory of strong bisimilarity in this tion
section; Section 6 extends the results developed here to the R  f ((1P ; P ); (1Q ; Q))
more useful case of weak bisimilarity. j 1P ; 1Q 2 Rems (1)
^ 1P ` P
^ 1Q ` Q g
5.1 Basic de nitions
We begin by de ning what \tests" can be made of a process is a 1-bisimulation if, whenever ((1P ; P ); (1Q ; Q)) 2 R,
by an external observer, relative to a certain type environ-
ment 0. 1. P +1
a i Q +a ;
1

5.1.1 De nition: We say that P exhibits the barb a under 2. 1P ` P 0! P 0 a 10P implies 1Q ` Q 0! Q0 a 10Q
type environment 0, written P +0a , if P has the immediate and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some Q0 ; and
possibility of performing an input or output action on the
channel a and if the type of a in 0 is such that the observer 3. 1Q ` Q 0! Q0 a 10Q implies 1P ` P 0! P 0 a 10P
can supply the other side of the communication | i.e., if it and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some P 0 .
is not the case that a is linear and both its input and output
capabilities are used by P . Formally, P +a0;a : T i one of the Two 1-remnant processes P and Q are 1-bisimilar, written
following holds P  1 Q, if ((1P ; P ); (1Q ; Q)) 2 R for some 1P ; 1Q 2
Rems (1) and some 1-bisimulation R.
1. P  ( x~ :U~ ) (a![~y]f j Qg) and either T = p! [T~] or T =
!1 [T~]; or By itself, barbed bisimulation is a rather weak relation.
In order to make it interesting, we need to close it under
2. P  ( x~ :U~ ) ((a?[~y]: R)f j Qg) and either T = p! [T~] or substitution and parallel composition. The resulting rela-
T = ?1 [T~]; or tion, called barbed congruence, will later be seen to be a
full congruence for all of the other process constructors.
3. P  ( x~:U~ ) ((a?3 [~y]: R)f j Qg).
5.1.3 De nition: Given two type environments 1 and 0,
In each case, our assumption that all bound variables have a 1-0-substitution  is a function from dom(1) to dom(0)
distinct names ensures that the channel a cannot be one of such that, for each y 2 dom(0), the type 0(y) can be written
the x~ . as (6x2dom(1)^(x)=y 1(x)) + U for some unlimited U .
Experts should note that this de nition of barbs agrees
with the standard one for the full pi-calculus. Since we are Intuitively, a 1-0 substitution is one that, whenever it maps
working with an asynchronous fragment here, with output some channels x1 ; : : : ; xn 2 dom(1) to the same channel
atoms instead of output pre xes, we do not actually need to y 2 dom(0), ensures that y has at least the combination of
allow observation of inputs: we could drop clauses 2 and 3 the capabilities of the x~.
of the de nition and obtain a notion of observation closer to
\what processes can see about each other." We conjecture
that the theory developed in the rest of the paper would not 5.2 Congruence
be a ected by this change.
5.2.1 De nition: P and Q are 1-precongruent, written
Next, we say that two processes are bisimilar if they have P p1 Q, if, for any 1-0 substitution  and 2 ` R such
the same sets of observable actions and if, for each step that that 2 + 0 is well-de ned, R j P  2+0 R j Q. That is, p1
one can make, the other can make a step and reach a state is the largest bisimulation closed under well-typed substi-
that is again bisimilar. tutions and parallel composition. Two 1-processes P and
The only slight complication is that we cannot require Q are 1-congruent, written P 1 Q, if P p1 Q. That is,
that the two processes be well typed in exactly the same two processes are congruent if they are precongruent and
type environment, since each linear communication removes are well typed in the same type environment.
capabilities from the type environment and we want to allow
the possibility that two processes are bisimilar even though As a simple example, it is easy to check that the pro-
they may use up their linear resources in di erent orders. cesses x![] j y ![] j x?[]:y ?[]:0 and x![] j y ![] j y?[]:x?[]:0 are con-
We deal with this by allowing the two to be typed in dif-
ferent environments, provided that both environments can gruent under the environment 1 = x : l1 []; y : l1 []. (And
be obtained by removing capabilities from some common that they are not congruent under the environment 1 =
environment. x : l! []; y : l! [].)
Formally, we rst de ne what it means for an arbitrary Fortunately, closing under parallel composition and sub-
relation on pairs of processes (and associated type environ- stitution is enough: if two processes are congruent, then
ments) to be a bisimulation. Two processes are then said to placing them in any process context again yields congruent
be bisimilar if they are related by some bisimulation. Re- processes.
call that Rems (1) is the set of environments obtained from
1 by changing some bindings in 1 of the form x : p1 [T~] to 5.2.2 Theorem [Congruence]: The relation 1 is pre-
x : j1 [T~]. served by all the process constructors.
6 Weak Bisimilarity 2. 1P ` P 0! P 0 a 10P implies 1Q ` Q 0!3 Q0 a 10Q ,
with P 0  P 00 , Q0  Q00 , and ((10P ; P 00 ); (10Q ; Q00 )) 2
As usual, the de nitions of strong barbed bisimulation and R for some P 00; Q0 ; Q00; and
congruence have a more useful, but somewhat more com-
plex, counterpart, called weak bisimulation, where we drop 3. 1Q ` Q 0! Q0 a 10Q implies 1P ` P 0!3 P 0 a 10P ,
the requirement that the two processes being compared must with P 0  P 00 , Q0  Q00 , and ((10P ; P 00 ); (10Q ; Q00 )) 2
proceed in lock-step and instead allow each to take zero or R for some P 0 ; P 00; Q00 .
many steps to match a single step of the other. The main
result in this section is Example 6.2.3, which formalizes the Two 1-remnant processes P and Q are weak 1-bisimilar
claim in the introduction that the two versions of the plus- up to , if 1P ; 1Q 2 Rems (1) and ((1P ; P ); (1Q ; Q)) 2 R
two process are behaviorally equivalent. where R is a weak 1-bisimulation up to .
6.1.4 Lemma: P and Q are weakly 1-bisimilar i they are
6.1 De nitions weakly 1-bisimilar up to .
The de nitions of weak barbs, weak bisimulation, and weak When we prove that the given two processes are weakly
congruence are obtained from the strong ones in the stan-
dard way. The weak barbs of a process are the strong barbs barbed bisimilar, it is often hard to compare weak barbs
 since we need to consider all the possible reduction sequences.
of all of its derivatives. Weak bisimulation (P 1 Q) is The following theorem allows us to compare strong barbs in-
obtained by replacing the second 0! in clauses (2) and (3) stead of weak barbs, which substantially simpli es proofs of
of De nition 5.1.1 with its re exive, transitive closure, 0!3 . weak barbed bisimilarity. Let Barbs1(P ) be the set of strong
Weak precongruence (P p1 Q) and congruence (P 1 Q) barbs of P , andWBarbs1 (P ) the set of weak barbs of P .
are formed by closing under substitution and parallel com-
position. The re ned de nitions read as follows: 6.1.5 Theorem: A relation
6.1.1 De nition [Weak barbed bisimulation]: A rela- R  f ((1P ; P ); (1Q ; Q))
tion j 1P ; 1Q 2 Rems (1)
R  f ((1P ; P ); (1Q ; Q)) ^ 1P ` P
j 1P ; 1Q 2 Rems (1) ^ 1Q ` Q g
^ 1P ` P
^ 1Q ` Q g is a weak 1-bisimulation if, whenever ((1P ; P ); (1Q ; Q)) 2
is a weak 1-bisimulation if, whenever ((1P ; P ); (1Q ; Q)) 2 R,
R, 1. Barbs1(P )  WBarbs1 (Q) and
1. 1P ` P 0!3 P 0 +1 Barbs1(Q)  WBarbs1 (P )
a i 1Q ` Q 0! Q +a ;
3 0 1

2. 1P ` P 0! P 0 a 10P implies 1Q ` Q 0!3 Q0 a 10Q 2. 1P ` P 0! P 0 a 10P implies 1Q ` Q 0!3 Q0 a 10Q


and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some Q0 ; and and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some Q0 ; and
3. 1Q ` Q 0! Q0 a 10Q implies 1P ` P 0!3 P 0 a 10P 3. 1Q ` Q 0! Q0 a 10Q implies 1P ` P 0!3 P 0 a 10P
and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some P 0 . and ((10P ; P 0 ); (10Q ; Q0 )) 2 R for some P 0 .
Two 1-remnant processes P and Q are weakly 1-bisimilar, Proof: It suces to show that if ((1P ; P ); (1Q ; Q)) 2

written P 1 Q, if the pair ((1P ; P ); (1Q ; Q)) 2 R for R, then WBarbs1 (P ) = WBarbs1 (0 Q). Suppose that a 23
some 1P ; 1Q 2 Rems (1) and weak 1-bisimulation R. WBarbs1 (P ). Then there is some P such that 1P ` P 0!
P 0 a 10P and a 2 Barbs1 (P 0 ). By condition 2, there is a
6.1.2 De nition: Two 1-remnant processes P and Q are matching reduction sequence 1Q ` Q 0!3 Q0 a 10Q with
weakly 1-precongruent, written P p1 Q, if for any 1-10 ((10P ; P 0 ); (10Q ; Q0 )) 2 R. By condition 1, a 2 WBarbs1 (Q0 ).
substitution  and 0 ` R such that 0 + 10 is well-de ned, Since WBarbs1 (Q0 )  WBarbs1 (Q), we know that a is in

R j P 0+10 R j Q. Two 1-processesp P and Q are weakly WBarbs1 (Q), and so WBarbs1 (P )  WBarbs1 (Q). Simi-
1-congruent, written P 1 Q, if P 1 Q. larly, WBarbs1 (P )  WBarbs1 (Q). 3
In the arguments that follow, it is convenient to use 6.1.6 Theorem: 1 is a congruence.
\weak bisimulation up to " to prove that two processes Now the partial con uence of linear reduction (Theo-

are bisimilar, instead of using 1 directly. rem 4.4.2) can be expressed in a more useful way:
6.1.3 De nition [Weak Bisimulation up to ]: 6.1.7 Theorem: If 1 ` P 1;
000! Q, then P p1 Q.
A relation
R  f ((1P ; P ); (1Q ; Q)) This theorem essentially says that linear reduction does not
j 1P ; 1Q 2 Rems (1) ^ 1P ` P ^ 1Q ` Q g change the weak precongruence class of a process, so that,
to show that P 1 Q, it suces to show that P and Q are
is a weak 1-bisimulation up to  if, both well typed in 1 and P 0 p1 Q for some linear reduct
whenever ((1P ; P ); (1Q ; Q)) 2 R, P 0 of P . (In the case of a linear  -reduction, we just need to
show that P 0 and Q are congruent.) We use the next lemma
1. 1P ` P 0!3 P 0 +1a i 1Q ` Q 0!3 Q0 +1a ; to prove the theorem.
1;
6.1.8 Lemma: If 0 ` P , 0 ` P 000! P 0 , 0 2 Rems (1), Proof: Let
and P +1
a , then P +a .
0 1
1 = plusone : !! [Num; !1 [Num]]; s : !1 [Num]; k : Num:
Proof of Theorem 6.1.7: Suppose that  is a 1-10 sub- By Theorem 6.1.6, it suces to show that
stitution and 0 ` R, with 0+10 well-de ned. Then 0+10 `
1;(;= )
R j P 00000000! R j Q. Therefore, we must show that if (r : l1 [Num]) (plusone![k; r] j r?[l]: s![l]) 1 plusone![k; s]:
1 ` P 0001;
! Q, then P  1 Q. Let Because both side of processes are well-typed under 1, it
R = f((1 ; Q ); (1
0 0 0
; Q ))
00 suces to show that
j 1 `0 Q 00!3 Q00 0 a010 ^ Q0  Q00 g (r : l1 [Num]) (plusone![k; r] j r?[l]: s![l]) p1 plusone![k; s]:
[ f((1 ; P ); (1 ; Q ))
j 1 ` P 0!3 P 0 a 10 Moreover, because substitution can only rename variables
1;
^10 ` P 0 000! Q0 a 100 g (note that all bindings in 1 are incompatible with each
other), it suces to show that if 2 ` Q and 2 + 1 is well
We show that R is a weak 1-bisimulation. Since the rst de ned, then
set in the de nition of R is itself a weak 1-bisimulation,
it suces to check only the case ((10P ; P 0 ); (10Q ; Q0 )) 2 Q j (r : l1 [Num]) (plusone![k; r] j r?[l]: s![l])
f((1 0
; P 0 ); (100 ; Q0 )) j 1 ` P 0!3 P 0 a 10 and 10 ` P 0 000! 1;  2+1 Q j plusone![k; s]:
Q a 1 g.
0 00
We show that
1. We must show that Barbs1 (P 0 )  WBarbs1 (Q0 ) and R = f((20 + 1; 1
Barbs1(Q0 )  WBarbs1 (P 0 ). Suppose that Q0 +1 a. Q0 j (r : l [Num]) (plusone![k; r] j r?[l]: s![l]));
0 0 1;
Then, 1 ` P 000! Q +a . Conversely, if P +a ,
0 1 0 1 (20 + 1; Q0 j plusone![k; s]))
then Q0 +1 a by Lemma 6.1.8 and 1 ` P 000! Q .
0 0 1; 0 j 2 ` Q 0!3 Q0 a 20 g
m;
[  2+1
2. Consider any reduction 10P ` P 0 0000 ! P 00. If P 00 
Q , then it is matched by 1Q ` Q 0! Q . Otherwise,
0 0 0 3 0 is a weak (2 + 1)-bisimulation up to , from which the
by Theorem 4.4.2, there is some Q00 such that 100P ` desired result follows, since
1; m;
P 00 000! Q00 a 100Q and 10Q ` Q0 0000 ! Q00 . There- ((2 + 1; Q j (r : l1 [Num]) (plusone![k; r] j r?[l]:s![l]));
fore, the reduction is matched by 10Q ` Q0 0000! Q00
m; (2 + 1; Q j plusone![k; s])) 2 R:
and ((1P ; P ); (1Q ; Q )) 2 R.
00 00 00 00
Take the pair
3. If 10Q ` Q0 0! Q00 a 100Q , then 10P ` P 0 000! Q0 0!
1; ((20 + 1; Q0 j (r : l1 [Num]) (plusone![k; r] j r?[l]: s![l]));
Q00 a 100Q and ((100Q ; Q00 ); (100Q ; Q00 )) appears in R. 3 (20 + 1; Q0 j plusone![k; s]))
from the rst part of R. We check the three conditions in
6.2 Application Theorem 6.1.5.
We now apply the foregoing theory to show that the two ver- 1. Barbs2+1 (Q0 j (r : l1 [Num]) (plusone![k; r ] j r?[l]:s![l]))
sions of the plus-two process presented in the introduction = Barbs2+1 (Q0 ) [ fplusoneg
are weakly congruent. These processes are nontrivial, and = Barbs2+1 (Q0 j plusone![k; s])
the proof of their equivalence requires some care; we begin
by introducing two technical lemmas to help structure the 2. Consider any reduction from
argument. Q0 j (r : l1 [Num]) (plusone![k; r] j r?[l]: s![l]))
6.2.1 Lemma: If P  1 Q and 1 2 Rems (0), then P  0 to R. There are two possibilities: either the reduction
Q. occurs inside Q0 , or an interaction occurs between Q0
and (r : l1 [Num]) (plusone![k; r] j r ?[l]: s![l]).
We write 0 ++ x : T to mean either 0; x : T if x 2= dom(0)
or 0 + x : T if x 2 dom(0). In the former case,
6.2.2 Lemma: If 1; y : !1 [T~] ` P and 1 ++ x : !1 [T~] is well R  Q00 j (r : l1 [Num]) (plusone![k; r] j r?[l]:s![l])
de ned, then 20 ` Q0 0! Q00 :
This reduction is matched by
[x=y]P  1++x : !1 [T~] (y : l1 [T~]) (P j y ?[~z]: x![~z]):
20 + 1 ` Q0 j plusone![k; s] 0! Q00 j plusone![k; s]:
6.2.3 Example: Let
In the latter case, reduction occurs on the channel
0 = plustwo : ?! [Num; !1 [Num]]; plusone:
plusone : !! [Num; !1 [Num]]:
Q0  ( w~ :W~ ) (plusone?[n; t]:P j O)
Then the two versions of the plus-two process given in the R  ( w~ :W ) (r : l1 [Num])
~
introduction are weakly congruent. ([k=n; r=t]P j O j r?[l]: s![l])
Then the reduction is matched by usage information it is given. On the other hand, in ap-
proaches based on e ect analysis, channel usage is analyzed
2 + 1 ` Q j plusone![k; s]
0 0
with respect to \regions," which may be aliased to an in-
0! ( w~:W~ ) ([k=n; s=t]P j O) nite number of channels, degrading the accuracy of the
~ ) ([k=n; r=t]P j O)
= [s=r]( w~ :W analysis. Although Kobayashi et al. tried to overcome this
defect to some degree, the resulting analysis is dicult, and
because some algorithmic aspects (especially time complexity) are
left open.
~ ) (r : l1 [Num]) ([k=n; r=t]P j O j r?[l]:s[l])
( w~ :W Abramsky, Gay, and Nagarajan [AGN94, GN95] describe
 a typed calculus of synchronous processes. Although their
20 +10plusone ( w~:W~ ) ([k=n; s=t]P j O)
calculus ensures deadlock-freedom, its expressive power is
by Lemma 6.2.2, which implies much more limited than ours in the sense that there must
be exactly one sender and receiver for each channel, and
~ ) (r : l1 [Num]) ([k=n; r=t]P j O j r?[l]:s[l])
( w~ :W mobility (passing channels as data along channels) cannot
 be expressed.
2+1 ( w~:W~ ) ([k=n; s=t]P j O) Finally, a type system reminiscent of ours | though not
by Lemma 6.2.1. explicitly incorporating the notion of linearity | has been
developed by Ste en and Nestmann [SN95] for the purpose
3. Consider any reduction 20 + 1 ` Q0 j plusone![k; s] 0! of analyzing con uence in pi-calculus processes arising in
R. There are again two cases: either reduction oc- the semantics of concurrent object-oriented programs. (The
curs inside Q0 , or interaction occurs between Q0 and same problem has been tackled by Liu and Walker using
plusone![k; s]. In the former case, R  Q00 j plusone![k; s] purely semantic techniques [LW95a].) Our analysis is also
and 20 ` Q0 0! Q00 . This is matched by: related to the one used by Niehren [Nie96] to guarantee \uni-
form con uence" in a pi-calculus fragment with only repli-
20 + 1 ` Q0 j (r : l1 [Num]) (plusone![k; r] cated inputs.
j r?[l]: s![l])
0! Q00 j (r : l1 [Num]) (plusone![k; r] 8 Variants and Extensions
j r?[l]: s![l]):
We have focused here on a fragment of the original polyadic
The argument for the latter case is similar to part (2). -calculus of [Mil91], omitting output guards (processes of
These three conditions imply that R is a weak (2+1)- the form x![~y]:P ), and the choice operator +. Although our
bisimulation up to . 3 type system and reduction semantics can easily be extended
to the full -calculus, some of the results we developed must
be treated carefully. For example, in the presence of output
7 Related Work guards, Example 6.2.3 is not valid. (However, if we allow
output guards only with nonlinear channels, the example
The spur for our work came from a paper by Takeuchi, does remain valid.) Similarly, if we add choice to our cal-
Honda, and Kubo [THK94] describing a modi ed pi-calculus culus, Theorems 4.4.2 and 6.1.7 do not hold, but we can
whose syntax guarantees that certain channels are shared recover them by allowing choice only on processes guarded
between just two processes. The motivating intuitions be- by nonlinear communications.
hind this calculus have the avor of a type system, suggest- A great variety of other \resource-aware" type systems,
ing that one might achieve the same e ect in a standard tracking di erent kinds of usage information, can be formu-
pi-calculus by introducing a re ned type system instead of lated using similar techniques. Indeed, many of these sys-
altering the syntax. (In fact, earlier work by Honda [Hon93] tems can actually be encoded in our simple system of linear
did adopt a type-theoretic perspective related to ours.) types.
Our type system shares a good deal with linear type One trivial variant of the present system is obtained by
systems for lambda-calculi and related programming lan- replacing linear by ane channels, which must be used at
guages [Abr93, Wad91, Hod92, Bak92, Mac94, TWM95]. In most once instead of exactly once. Since, as we have seen,
particular, linear typing has recently been proposed as a it is actually possible to throw away linear channels without
framework for syntactic control of interference in sequential using them (by placing them in a deadlocked subprocess),
programming languages (cf. [OTPT95]). the linear and ane variants of the system have nearly iden-
In the world of process calculi, there have been sev- tical properties. One advantage of the ane variant is that it
eral papers on analyzing channel usage using e ect sys- allows garbage collection: if the process (x : l! [T~]) x?[~y]: Q
tems. Nielson and Nielson [NN95] proposed a method for is well typed in some context 0, then 0 is well typed in the
inferring the maximum usages of channels by applying the same context.
e ect system for CML [NN94], while Kobayashi, Nakade, A more interesting variant introduces a type of replicated
and Yonezawa [KNY95] proposed a method for approxi- channels, which can be used arbitrarily often for output but
mating the number of receivers that can ever try to read only allow a single, replicated input. Communication on
from a channel simultaneously, which in particular can be replicated channels enjoys the same partial con uence prop-
used to detect channels whose maximum queue length is erty as linear communication. We conjecture that this prop-
1. Our type-based analysis and these e ect-based analy- erty can be used to show, for example, that -reduction pre-
ses both seem to have advantages and disadvantages. The serves weak congruence in the encoding of the call-by-value
e ect-based methods can infer usage information, whereas -calculus. To handle replicated channels formally, we in-
currently our type system only checks consistency of the troduce a new multiplicity r (either replacing or augmenting
the linear multiplicity 1). We de ne the operator + for the without cluttering the language with extra distinctions that
new multiplicity by the programmer must explicitly bear in mind. Work is un-
derway on exploring these issues in a linear variant of Pict.
pr [T~] + qr [T~] = (p [ q)r [T~] if i 62 p \ q
and modify the side conditions of the rules E-In and E-RIn
as follows: Acknowledgements
0; z~:T~ ` P m 6= r Kobayashi is partially supported by Grant-in-Aid for Scien-
(E-In) ti c Research of Japan No. 06452389 and 07780232. Pierce
0 + x : ? [T ] ` x?[~z]: P
m ~ is supported by EPSRC grant GR/K 38403. Turner is sup-
ported by EPSRC grant GR/J 527099 (\Save space with
0; z~:T~ ` P 0 unlimited m = r or ! linear types"). We have pro ted from lively discussions with
(E-RIn)
0 + x : ?m [T~] ` x?3 [~z]: P Robin Milner, Phil Wadler, and the Monday \Interruption
Club" at Cambridge. Cedric Fournet gave us useful com-
Another variation on linear channels is linearized chan- ments on an earlier draft.
nels, which can be used multiple times but only in a sequen-
tial manner: an output x![~y]:P can reuse x again for output
in P , while an input x?[~y]:P can reuse x for input in P . References
Linearized channels can be encoded using linear channels
and recursive types. Write l3 [T~] for the type of linearized [Abr93] Samson Abramsky. Computational interpreta-
tions of linear logic. Theoretical Computer Sci-
channels repeatedly carrying tuples of type T~. This type is ence, 111(1{2):3{57, April 12 1993.
encoded as follows in terms of linear types:
[[l3 [T~]]] = l1 [T~; !1 [ ]; (X: ?1 [T~; !1 [ ]; X ])] [Agh86] Gul A. Agha. Actors: a Model of Concurrent
Computation in Distributed Systems. MIT Press,
That is, a linearized channel is encoded as a linear chan- Cambridge, MA, 1986.
nel carrying tuples with types T~ plus two extra parameters:
a channel used to trigger the continuation of the output [AGN94] Samson Abramsky, Simon J. Gay, and R. Na-
(needed because we are translating from a language with garajan. Interaction categories and the founda-
output guards to one without) and another channel of nearly tions of typed concurrent programming. In De-
the same type as the original linearized channel (more pre- ductive Program Design: Proceedings of the 1994
cisely, of the type of the \input end" of the original linearized Marktoberdorf Summer School, NATO ASI Se-
channel), which replaces the original in the continuation of ries F. Springer-Verlag, 1994.
both sender and receiver. Input and output expressions on [Bak92] Henry G. Baker. Lively linear lisp { look ma,
a linearized channel x 2 l3 [T~] are encoded as follows: no garbage! ACM Sigplan Notices, 27(8):89{98,
[[x![~y]: P ] = (x0 : [ l3 [T~]]]) (c : l1 [ ]) 1992.
x![~y; c; x0 ] j c?[ ]: [ [x0 =x]P ] [Car86] Luca Cardelli. Amber. In Guy Cousineau,
[[x?[~y]: P ] = x?[~y; c; x0 ]: (c![ ] j [[[x0 =x]P ] ) Pierre-Louis Curien, and Bernard Robinet, ed-
Linearized channel types can be viewed as a variant on a itors, Combinators and Functional Programming
fragment of Honda's \types for dyadic interaction" [Hon93]. Languages, pages 21{47. Springer-Verlag, 1986.
Combining the intuitions behind replicated and linearized Lecture Notes in Computer Science No. 242.
channel types yields another important usage analysis, which
Milner calls \unique handling" [Mil91]: a channel is uniquely [FG96] Cedric Fournet and Georges Gonthier. The re-
handled if it has a single replicated receiver and, at any given exive chemical abstract machine and the join-
moment, at most one sender. That is, the capability to send calculus. In Principles of Programming Lan-
must be explicitly passed from one \client" to another, so guages, January 1996.
there can never be any contention between clients for access [Gay93] Simon J. Gay. A sort inference algorithm for the
to the service provided by the receiver. polyadic -calculus. In Proceedings of the Twen-
Of course, there is no reason in principle why our analy- tieth ACM Symposium on Principles of Program-
ses should distinguish only between zero, one, and arbitrar- ming Languages, January 1993.
ily many uses of a channel: we could just as well introduce
the additional multiplicities 2, 3, etc. But, at least in our [Gir87] Jean-Yves Girard. Linear logic. Theoretical
present experimental testbed (the Pict language), there are Computer Science, 50:1{102, 1987.
few bene ts to be gained from this re nement: pro ling of
Pict programs indicates that the great majority of channels [GLT89] Jean-Yves Girard, Yves Lafont, and Paul Tay-
are either used unboundedly or linearly. This is largely due lor. Proofs and Types, volume 7 of Cambridge
to the fact that functions are literally compiled as processes Tracts in Theoretical Computer Science. Cam-
in Pict, so a very large number of channels are used either bridge University Press, Cambridge, 1989.
as locations of functions or as result channels.
Applying any of these type systems to a full-scale pro- [GMP89] Alessandro Giacalone, Prateek Mishra, and San-
gramming language raises a number of pragmatic issues. Al- jiva Prasad. Facile: A Symmetric Integration of
though typechecking (even, with some help from program- Concurrent and Functional Programming. In-
mer annotations, partial type inference) is relatively unprob- ternational Journal of Parallel Programming,
lematic, it is quite dicult to add linear type information 18(2):121{160, 1989.
[GN95] Simon Gay and Rajagopal Nagarajan. A typed [Mac94] Ian Mackie. Lilac: A functional programming
calculus of synchronous processes. In Proceed- language based on linear logic. Journal of
ings of IEEE Symposium on Logic in Computer Functional Programming, 4(4):395{433, October
Science, 1995. 1994.
[Hew77] C. Hewitt. Viewing control structures as pat- [Mil90] Robin Milner. Functions as processes. Research
terns of passing messages. Arti cial Intelligence, Report 1154, INRIA, So a Antipolis, 1990. Final
8:323{364, 1977. version in Journal of Mathematical Structures in
Computer Science 2(2):119{141, 1992.
[Hod92] J. S. Hodas. Lolli: An extension of Prolog with
linear context management. In D. Miller, edi- [Mil91] Robin Milner. The polyadic  -calculus: a tuto-
tor, Workshop on the Prolog Programming Lan- rial. Technical Report ECS{LFCS{91{180, Lab-
guage, pages 159{168, Philadelphia, Pennsylva- oratory for Foundations of Computer Science,
nia, August 1992. Department of Computer Science, University of
Edinburgh, UK, October 1991. Proceedings of
[Hon93] Kohei Honda. Types for dydadic interaction. In the International Summer School on Logic and
CONCUR'93, volume 715 of Lecture Notes in Algebra of Speci cation, Marktoberdorf, August
Computer Science, pages 509{523, 1993. 1991. Reprinted in Logic and Algebra of Spec-
[HT91] Kohei Honda and Mario Tokoro. An object i cation, ed. F. L. Bauer, W. Brauer, and H.
calculus for asynchronous communication. In Schwichtenberg, Springer-Verlag, 1993.
Pierre America, editor, Proceedings of the Eu- [MPW92] R. Milner, J. Parrow, and D. Walker. A calculus
ropean Conference on Object-Oriented Program- of mobile processes (Parts I and II). Information
ming (ECOOP), volume 512 of Lecture Notes in and Computation, 100:1{77, 1992.
Computer Science, Geneva CH, 1991. Springer-
Verlag , Berlin, Heidelberg, New York, Tokyo. [MS92] R. Milner and D. Sangiorgi. Barbed bisimula-
[Jon93] Cli B. Jones. A pi-calculus semantics for an tion. In W. Kuich, editor, 19th ICALP, volume
object-based design notation. In E. Best, editor, 623 of Lecture Notes in Computer Science, pages
Proceedings of CONCUR'93, LNCS 715, pages 685{695. Springer Verlag, 1992.
158{172. Springer-Verlag, 1993. [Nie96] Joachim Niehren. Functional computation as
[KNY95] Naoki Kobayashi, Motoki Nakade, and Akinori concurrent computation. In Principles of Pro-
Yonezawa. Static analysis of communication gramming Languages, January 1996.
for asynchronous concurrent programming lan- [NN94] Hanne Riis Nielson and Flemming Nielson.
guages. In Second International Static Anal- Higher-order concurrent programs with nite
ysis Symposium (SAS'95), volume 983 of Lec- communication topology. In Proceedings of
ture Notes in Computer Science, pages 225{242. POPL '94: 21st ACM SIGPLAN-SIGACT Sym-
Springer-Verlag, 1995. posium on Principles of Programming Lan-
[KPT95] Naoki Kobayashi, Benjamin C. Pierce, and guages, Portland, Oregon, pages 84{97, January
David N. Turner. Linearity and the pi-calculus, 1994.
1995. Technical report, Department of Informa- [NN95] Hanne Riis Nielson and Flemming Nielson.
tion Science, University of Tokyo and Computer Static and dynamic processor allocation for
Laboratory, University of Cambridge.
higher-order concurrent languages. In TAP-
[KY94] Naoki Kobayashi and Akinori Yonezawa. Type- SOFT'95: Theory and Practice of Software De-
theoretic foundations for concurrent object- velopment, volume 915 of Lecture Notes in Com-
oriented programming. In Proceedings of ACM puter Science, pages 590{604. Springer-Verlag,
SIGPLAN Conference on Object-Oriented Pro- 1995.
gramming Systems, Languages, and Applications
(OOPSLA'94), pages 31{45, 1994. [Ode95] Martin Odersky. Polarized name passing. In
Proc. FST & TCS, LNCS. Springer Verlag, De-
[KY95] Naoki Kobayashi and Akinori Yonezawa. To- cember 1995.
wards foundations for concurrent object-oriented
programming { types and language design {. [OTPT95] P. W. O'Hearn, M. Takayama, A. J. Power, and
Theory and Practice of Object Systems, John R. D. Tennent. Syntactic control of interference
Wiley & Sons, 1995. to appear. revisited. In MFPS XI, conference on Mathe-
matical Foundations of Program Semantics, vol-
[LW95a] Xinxin Liu and David Walker. Con uence of pro- ume 1 of Electronic Notes in Theoretical Com-
cesses and systems of objects. In Proceedings of puter Science. Elsevier, March 1995.
CAAP'95, pages 217{231. Springer, 1995.
[PS93] Benjamin Pierce and Davide Sangiorgi. Typing
[LW95b] Xinxin Liu and David Walker. A polymorphic and subtyping for mobile processes. In Logic
type system for the polyadic -calculus. In CON- in Computer Science, 1993. Full version to ap-
CUR'95: Concurrency Theory, pages 103{116. pear in Mathematical Structures in Computer
Springer, 1995. Science.
[PT95a] Benjamin C. Pierce and David N. Turner. Con-
current objects in a process calculus. In Takayasu
Ito and Akinori Yonezawa, editors, Theory
and Practice of Parallel Programming (TPPP),
Sendai, Japan (Nov. 1994), number 907 in Lec-
ture Notes in Computer Science, pages 187{215.
Springer-Verlag, April 1995.
[PT95b] Benjamin C. Pierce and David N. Turner. Pict:
A programming language based on the pi-
calculus. To appear, 1995.
[Rep91] John Reppy. CML: A higher-order concurrent
language. In Programming Language Design
and Implementation, pages 293{259. SIGPLAN,
ACM, June 1991.
[San92] Davide Sangiorgi. Expressing Mobility in Pro-
cess Algebras: First-Order and Higher-Order
Paradigms. PhD thesis, Department of Com-
puter Science, University of Edinburgh, 1992.
[San93] Davide Sangiorgi. An investigation into func-
tions as processes. In Proc. Ninth Interna-
tional Conference on the Mathematical Foun-
dations of Programming Semantics (MFPS'93),
volume 802 of Lecture Notes in Computer Sci-
ence, pages 143{159. Springer Verlag, 1993.
[SN95] Martin Ste en and Uwe Nestmann. Typing
con uence. Interner Bericht IMMD7-xx/95, In-
formatik VII, Universitat Erlangen-Nurnberg,
1995.
[THK94] Kaku Takeuchi, Kohei Honda, and Makoto
Kubo. An interaction-based language and its
typing system. In Proceedings of PARLE'94,
pages 398{413. Springer-Verlag, 1994. Lecture
Notes in Computer Science number 817.
[Tur95] David N. Turner. The -calulus: Types, poly-
morphism and implementation, 1995. Forthcom-
ing Ph.D. thesis, LFCS, University of Edinburgh.
[TWM95] David N Turner, Philip Wadler, and Christian
Mossin. Once upon a type. In Functional Pro-
gramming Languages and Computer Architec-
ture, San Diego, California, 1995.
[Vas94] Vasco T. Vasconcelos. Typed concurrent ob-
jects. In Proceedings of the Eighth Euro-
pean Conference on Object-Oriented Program-
ming (ECOOP), volume 821 of Lecture Notes
in Computer Science, pages 100{117. Springer-
Verlag, July 1994.
[VH93] Vasco T. Vasconcelos and Kohei Honda. Princi-
pal typing schemes in a polyadic pi-calculus. In
Proceedings of CONCUR '93, July 1993. Also
available as Keio University Report CS-92-004.
[Wad91] Philip Wadler. Is there a use for linear logic? In
Proceedings of ACM Symposium on Partial Eval-
uation and Semantics-Based Program Manipula-
tion, pages 255{273, 1991.
[Wal95] David Walker. Objects in the  -calculus. Infor-
mation and Computation, 116:253{271, 1995.

View publication stats

You might also like