• Nenhum resultado encontrado

Process Calculus and Operational Semantics

The Concurrent Programming Language CLASS

2.2 Process Calculus and Operational Semantics

In this section, we define the process syntax and the reduction-based operational semantics of𝜇CLL.

Types and Duality

Since in𝜇CLLprocesses depend on types, we start by presenting types and defining type duality.

Definition 1(Types). The types of𝜇CLLare defined by

𝐴, 𝐵::= 𝑋(type variable) | 𝑋(dual of type variable)

| 1(one) | ⊥(bottom)

| 𝐴⊗𝐵(tensor) | 𝐴

O𝐵(par)

| 𝐴⊕𝐵(plus) | 𝐴

N𝐵(with)

| !𝐴(bang) | ?𝐴(why not)

| ∃𝑋.𝐴(exists) | ∀𝑋.𝐴(for all)

| 𝜇𝑋. 𝐴(mu) | 𝜈𝑋. 𝐴(nu)

Types are composed from type variables, units (1,⊥), multiplicatives (⊗,O), additives (⊕, N), exponentials (!, ?), second-order type quantifies (∃, ∀) and inductive types (𝜇, 𝜈). The expressions∃𝑋.𝐴, ∀𝑋.𝐴, 𝜇𝑋. 𝐴, 𝜈𝑋. 𝐴all bind the type variable𝑋 in𝐴. The expression{𝐴/𝑋}𝐵denotes capture-avoiding substitution of type variable𝑋by𝐴in𝐵.

We consider that the binary type connectives associate to the right, therefore the type 𝐴⊗𝐵

O𝐶 should be parsed as𝐴⊗ (𝐵

O𝐶). Furthermore, we consider that the unary operators !, ?,∃𝑋,∀𝑋,𝜇𝑋 and𝜈𝑋 have higher precedence that the binary connectives.

Therefore, the type !𝐴⊗𝐵should be parsed as(!𝐴) ⊗𝐵.

Types are structured by an involutive operation𝐴↦→𝐴of duality that corresponds to linear logic negation and captures symmetry in interaction.

Definition 2(Duality on Types𝐴). Duality𝐴is the involution on types defined by 1 𝐴𝐵𝐴O𝐵 𝐴⊕𝐵 ≜ 𝐴 N𝐵

!𝐴 ≜ ?𝐵 ∃𝑋.𝐴∀𝑋.𝐴 𝜇𝑋. 𝐴 ≜ 𝜈𝑋.{𝑋/𝑋}(𝐴)

For convenience, we define the lollipop type constructor by𝐴 ⊸𝐵𝐴O𝐵, using duality and par (O), which types session input.

Type-level duality is explicitly defined for half of the type connectives (1,⊗,⊕, ! and∃, 𝜇). Since it is an involution we can obtain the explicit definition for the other half (⊥,O,N,

?,∀,𝜈). For example, for the connective tensor⊗, Definition2postulates 𝐴⊗𝐵 ≜𝐴O𝐵

By instantiating the metavariables𝐴and𝐵with𝐶and𝐷, respectively, yields 𝐶⊗𝐵=𝐶

O𝐵

By applying duality to both sides of the equation and by using the involution property 𝑋 =𝑋 to simplify the resulting expression, we obtain the explicit expression that gives duality for the connective parO:

𝐶⊗𝐵=𝐶 O𝐵

Duality preserves type substitution {𝐴/𝑋}𝐵 = {𝐴/𝑋}𝐵. As we shall see, duality enforces a pleasant symmetry on process interaction, captured at the proof level by a series of principal cut reductions.

Processes

We will now define processes of𝜇CLL.

Definition 3(Processes). The syntax of process terms for𝜇CLLis defined in Fig.2.1.

𝑥, 𝑦, 𝑧, . . . ∈ 𝒩 (session names) 𝑃, 𝑄 ::= 0(inaction)

| fwd𝑥 𝑦(forwarder)

| 𝒜 (action)

| 𝑋(𝑥,𝑦)® (variable)

| par{𝑃| |𝑄}(mix)

| cut{𝑃 |𝑥 :𝐴| 𝑄}(linear cut)

| cut!{𝑦.𝑃|𝑥:𝐴|𝑄}(unrestricted cut) 𝒜,ℬ ::= close𝑥(close)

| wait𝑥;𝑃(wait)

| 𝑥.inl;𝑃(choose left)

| 𝑥.inr;𝑃(choose right)

| case𝑥 {|inl:𝑃| inr:𝑄}(offer)

| send𝑥(𝑦.𝑃);𝑄(send)

| recv𝑥(𝑦);𝑃(receive)

| !𝑥(𝑦);𝑃(replication)

| ?𝑥;𝑃(unrestrict)

| call𝑥(𝑦);𝑃(call)

| sendty𝑥 𝐴;𝑃(send type)

| recvty𝑥(𝑋);𝑃(receive type)

| corec𝑋(𝑧,𝑤)® ;𝑃[𝑥,𝑦]® (corecursion

| unfold𝜇𝑥;𝑃 (unfold𝜇)

| unfold𝜈 𝑥;𝑃(unfold𝜈)

Figure 2.1: Processes𝑃of𝜇CLL(extended by Fig.3.1).

Processes depend on session names𝑥, 𝑦, 𝑧, . . . and on variables 𝑋(𝑥,𝑦)® . The static part of the syntax comprises inaction, mix, cut and cut!; the dynamic part includes actions 𝒜,ℬ, and forwarder. An action is typically a process𝛼;𝑃, where𝛼is an action-prefix and 𝑃is the continuation. In these cases, the subject𝑠(𝒜)of an action𝒜is the leftmost name occurrence of𝒜. For example, the subject of the actionsend𝑥(𝑦.𝑃);𝑄is𝑥. The subject of corec𝑋(𝑧,𝑤)® ;𝑃[𝑥,𝑦]® is𝑥.

For convenience, we equip𝜇CLLwith𝑛-ary cut which is right-associative, encoded using binary cuts as:

cut{𝑃1|𝑥1 :𝐴1| . . . 𝑃𝑛−1 |𝑥𝑛−1:𝐴𝑛−1|𝑃𝑛} ≜ cut{𝑃1 |𝑥1 :𝐴1| . . .cut{𝑃𝑛−1 |𝑥𝑛−1:𝐴𝑛−1| 𝑃𝑛}}

Similarly, we also equip𝜇CLLwith𝑛-ary mix

par{𝑃1 | | . . . 𝑃𝑛−1 | |𝑃𝑛}

The expressioncut{𝑃 |𝑥 :𝐴| 𝑄}binds the name𝑥on processes𝑃and𝑄.cut!{𝑦.𝑃|𝑥: 𝐴| 𝑄}binds𝑦in𝑃and𝑥in𝑄. Actionssend𝑥(𝑦.𝑃);𝑄,recv𝑥(𝑦);𝑃,!𝑥(𝑦);𝑃,call𝑥(𝑦);𝑃 bind 𝑦 on 𝑃. Action corec 𝑋(𝑧,𝑤)® ;𝑃 [𝑥,𝑦]® binds names 𝑧,𝑤® in 𝑃. All other name occurrences are free. The set of free names of𝑃is denoted byfn(𝑃); iffn(𝑃)=∅, we say𝑃 is closed.

The expressionsrecvty𝑥(𝑋);𝑃binds the type variable𝑋on process𝑃. All the other type variable occurrences are free. Capture-avoiding substitution and𝛼-conversion are defined as usual. We denote by {𝑥/𝑦}𝑃 the process obtained by replacing the name 𝑦 by𝑥on𝑃. Similarly, we denote by{𝐴/𝑋}𝑃the process term obtained by replacing type variable𝑋 by type expression𝐴in process term𝑃. If𝑥®and𝑦®are arrays of names with the same length𝑛we let{ ®𝑥/ ®𝑦}𝑃denote the substitution{ ®𝑥[0]/ ®𝑦[0]}(. . .{ ®𝑥[𝑛]/ ®𝑦[𝑛]}𝑃). Operational Semantics

We will now present the reduction-based operational of 𝜇CLL , which is defined by specifying a structural congruence relation ≡that captures the static laws, essentially rearranging processes, and a a dynamic reduction relation→that captures the evolution of a process as interaction takes place.

Before defining structural congruence, we need to introduce process contexts. A process context 𝒞is a process expression containing a single hole□[137]. For example, the following

cut{|𝑥 :𝐴| 𝑃} wait𝑦;par{cut{𝑄 |𝑥:𝐴| □} | |𝑃}

are both process contexts. We write𝒞[𝑃]for the process obtained by replacing the hole in𝒞by𝑃(notice that in𝒞[𝑃]the context𝒞may bind free names of process𝑃). Similarly, given two process contexts 𝒞1,𝒞2, we write𝒞1[𝒞2]for the context obtained by replacing the hole in 𝒞1by𝒞2. We define context composition by𝒞1◦ 𝒞2𝒞1[𝒞2]. A process𝑃is a subprocess of 𝑃if 𝑃 = 𝒞[𝑃], for some process context𝒞. We say that a relationℛ is a process congruence iff whenever𝑃ℛ𝑄, then𝒞[𝑃]ℛ 𝒞[𝑄].

Definition 4(Structural Congruence𝑃≡𝑄). Structural congruenceis the least relation on processes that includes𝛼-conversion and the rules in Fig.2.2.

The basic rules of≡essentially reflect the expected static laws, along the lines of the structural congruences / conversions in [23,157]. Relation≡is an equivalence relation (rules [refl], [symm] and [trans]) which satisfies the congruence rule [cong]. The binary operators cut, forwarder and mix are commutative (rules [C], [fwd], [M]). Furthermore, mix is associative (rule [MM]) and has the inaction process0as identity (rule [0M]). We can linearly distribute the linear and the unrestricted cuts, where the distributions are

Congruence Rules 𝑃≡𝑃[refl]

𝑃≡𝑄 ⊃ 𝑄≡𝑃[symm]

𝑃≡𝑄and𝑄≡𝑅 ⊃ 𝑃≡𝑅[trans]

𝑃≡𝑄 ⊃ 𝒞[𝑃] ≡ 𝒞[𝑄][cong]

Commutativity Rules

cut{𝑃 |𝑥 :𝐴| 𝑄} ≡cut{𝑄 |𝑥 :𝐴| 𝑃} [C]

fwd𝑥 𝑦 ≡fwd𝑦 𝑥[fwd]

Mix Rules

par{𝑃| |0} ≡𝑃[0M]

par{𝑃| |𝑄} ≡par{𝑄| |𝑃}[M]

par{𝑃| |par{𝑄| |𝑅}} ≡par{par{𝑃| | 𝑄}| |𝑅}[MM]

Linearly Distributive Conversions

cut{𝑃 |𝑥| par{𝑄| |𝑅}} ≡par{cut{𝑃 |𝑥| 𝑄} | |𝑅}, 𝑥∈fn𝑄[CM]

cut{𝑃 |𝑥| cut{𝑄 |𝑦| 𝑅}} ≡cut{cut{𝑃 |𝑥| 𝑄} |𝑦| 𝑅}, 𝑥, 𝑦 ∈fn𝑄[CC]

cut{𝑃 |𝑥| cut!{𝑦.𝑄|𝑧|𝑅}} ≡cut!{𝑦.𝑄 |𝑧|cut{𝑃 |𝑥| 𝑅}}, 𝑧∉fn𝑃[CC!]

cut!{𝑦.𝑃|𝑥|par{𝑄 | |𝑅}} ≡par{cut!{𝑦.𝑃|𝑥|𝑄}| |𝑅}, 𝑥∉fn𝑅[C!M]

cut!{𝑦.𝑃|𝑥|cut!{𝑤.𝑄 |𝑧| 𝑅}}

cut!{𝑤.𝑄 |𝑧|cut!{𝑦.𝑃 |𝑥|𝑅}}, 𝑥∉fn𝑄, 𝑧 ∉fn𝑃[C!C!]

Unrestricted Cut Distributive Conversions

cut!{𝑦.𝑃|𝑥:𝐴|par{𝑄| | 𝑅}} ≡par{cut!{𝑦.𝑃 |𝑥 :𝐴| 𝑄}| |cut!{𝑦.𝑃 |𝑥 :𝐴| 𝑅}}[D-C!M]

cut!{𝑦.𝑃|𝑥:𝐴|cut{𝑄 |𝑧| 𝑅}}

cut{cut!{𝑦.𝑃|𝑥 :𝐴| 𝑄} |𝑧| cut!{𝑦.𝑃|𝑥:𝐴|𝑅}}[D-C!C]

cut!{𝑦.𝑃|𝑥:𝐴|cut!{𝑤.𝑄 |𝑧|𝑅}}

cut!{𝑤.cut!{𝑦.𝑃|𝑥 :𝐴| 𝑄}|𝑧|cut!{𝑦.𝑃 |𝑥 :𝐴|𝑅}}[D-C!C!]

Figure 2.2: Structural congruence𝑃≡𝑄rules of𝜇CLL(extended by Fig.3.2).

guided by the provisos (rules [CM], [CC], [CC!], [C!M], [C!C!]). Finally, we can distribute the unrestricted cut over the static constructs mix, cut and unrestricted cut as expressed by rules [D-C!M], [D-C!C] and [D-C!C!].

Before defining reduction, we introduce static contexts, which are defined by 𝒞 ::=□|par{𝒞| |𝑃} |par{𝑃 | |𝒞} |cut{𝒞 |𝑥| 𝑃} |cut{𝑃 |𝑥| 𝒞} |cut!{𝑦.𝑃 |𝑥| 𝒞}

A static context is therefore a context where the hole is neither guarded by any action nor lies in the server body𝑃of a cut!cut!{𝑦.𝑃|𝑥|𝑄}.

cut{fwd𝑥 𝑦 |𝑦| 𝑃} → {𝑥/𝑦}𝑃 [fwd]

cut{close𝑥 |𝑥| wait𝑥;𝑃} →𝑃 [1⊥]

cut{send𝑥(𝑦.𝑃);𝑄 |𝑥| recv𝑥(𝑧);𝑅} →cut{𝑄 |𝑥| cut{𝑃 |𝑦| {𝑦/𝑧}𝑅}} [⊗O]

cut{case𝑥 {|inl:𝑃|inr:𝑄} |𝑥| 𝑥.inl;𝑅} →cut{𝑃 |𝑥| 𝑅} [N⊕𝑙] cut{case𝑥 {|inl:𝑃|inr:𝑄} |𝑥| 𝑥.inr;𝑅} →cut{𝑄 |𝑥| 𝑅} [N⊕𝑟] cut{!𝑥(𝑦);𝑃 |𝑥| ?𝑥;𝑄} →cut!{𝑦.𝑃|𝑥|𝑄} [!?]

cut!{𝑦.𝑃|𝑥|call𝑥(𝑧);𝑄} →cut{{𝑧/𝑦}𝑃 |𝑧| cut!{𝑦.𝑃|𝑥|𝑄}} [call]

cut{sendty𝑥 𝐴;𝑃 |𝑥| recvty𝑥(𝑋);𝑄} →cut{𝑃 |𝑥| {𝐴/𝑋}𝑄} [∃∀] cut{unfold𝜇 𝑥;𝑃 |𝑥| unfold𝜈 𝑥;𝑄} →cut{𝑃 |𝑥| 𝑄} [𝜇𝜈]

cut{unfold𝜇 𝑥;𝑃 |𝑥| corec𝑌(𝑧,𝑤)® ;𝑄[𝑥,𝑦]}®

cut{𝑃 |𝑥| {𝑥/𝑧}{ ®𝑦/ ®𝑤}{corec𝑌(𝑧,𝑤)® ;𝑄/𝑌}𝑄} [corec]

𝑃≡𝑃and𝑃→𝑄and𝑄 ≡𝑄 ⊃ 𝑃 →𝑄 []

𝑃→𝑄 ⊃ 𝒞[𝑃] → 𝒞[𝑄] [cong]

Figure 2.3: Reduction𝑃 →𝑄rules of𝜇CLL(extended by Fig.3.3).

We need also to define substitution of a process variable by a corecursive process, which will be used when modelling the one-step unfold of a corecursive process definition. The base cases are defined by

{corec𝑋(𝑧,𝑤)® ;𝑃/𝑋}𝑋(𝑥,𝑦)® ≜ corec𝑋(𝑧,𝑤)® ;𝑃[𝑥,𝑦]® {corec𝑋(𝑧,𝑤)® ;𝑃/𝑋}𝑌(𝑥,𝑦)® ≜ 𝑌(𝑥,𝑦), 𝑌® 𝑋

and the substitution is propagated without surprises to the remaining cases.

Definition 5(Reduction𝑃 →𝑄). Reductionis the least relation on processes that includes the rules in Fig.2.3. N.B.: In [cong],𝒞is an arbitrary static context.

Reduction includes a set of principal cut conversions, it is closed by structural congru-ence ([≡]) and defined on the nose, so in rule [cong] we consider that𝒞is a static context.

Operationally, the forwarding behaviour is implemented by name substitution [30] ([fwd]).

All the other conversions apply to a cut between two dual actions. For example, rule [⊗O]

applies to a cut on session𝑥 :𝐴⊗𝐵between send and receive and reduces to a process expression with two cuts. The inner cut on𝑦 :𝐴connects the continuation{𝑦/𝑧}𝑅of the receiver with the provider𝑃of the sent channel, whereas the outer cut on𝑥 :𝐵connects {𝑦/𝑧}𝑅 with the continuation𝑄 of the send process.The principal cut conversions are type-annotated for convenience, but types play no role in reduction. We let→−+ stand for the transitive closure of→, and→− be the reflexive-transitive closure of→. We postpone detailed comments on the operational model for the next section.

In the following guided tour, we will often appeal to notions such ascommunication channelsand later tomemory cells, for the sake of conveying intuition about the operational model. However, we would like to stress that, in our approach, process reduction is explained solely by pure algebraic manipulations on process terms that contain variables and variable binding operators, as usual in computational interpretations of logic, therefore communication channelsandmemory cellsare nothing but standard variables in proof terms.

In our practical interpreter implementation (Chapter 5), we naturally resort to actual channels and memory locations, but that is a different realm.