• Nenhum resultado encontrado

The Concurrent Programming Language CLASS

6.3 Progress

In the previous section we proved type preservation. We will now prove thatCLASSenjoys the progress property (Theorem2), namely that all closed live processes reduce. Progress is a liveness property: it guarantees that closed live processes will never get stuck.

We start by defining what means for a process to be live (Definition 16) and then we introduce an observability predicate (Definition17) which characterises the potential interactions of an open typed processes and which is instrumental to prove progress compositionally.

Definition 16(Live Process). A process𝑃 is live if𝑃 = 𝒞[𝒜]or𝑃 = 𝒞[fwd 𝑥 𝑦]for some static context𝒞and action𝒜.

Intuitively, a process is live if it presents an unguarded action or forwarder waiting to interact, that action lies only under the scope of a static construct (mix, linear or unrestricted cut, share, sum). As a consequence of our linear typing discipline, all the typed processes 𝑃 ⊢𝜂 Δ;Γ that (i) type with a nonempty linear context Δ and (ii) with an empty map 𝜂 are necessarily live, as established by the following lemma. The latter condition (ii) is necessary so as to exclude processes variables 𝑋( ®𝑦)since they offer no structure for interaction, they are not live.

Lemma 1. If𝑃⊢Δ;ΓandΔ ≠∅, then𝑃is live.

Proof. By induction on a derivation of𝑃 ⊢ Δ;Γ. Case [T0] holds vacuously because it types inaction 0with an empty linear context. Case [Tvar] holds vacuously because it types a variable with a nonempty recursion map𝜂.

Cases which introduce the forwarder construct or an action hold trivially since𝑃can be written as−[fwd𝑥 𝑦]or−[𝒜], where−is the empty static process context and𝒜is an action.

The remaining cases are [Tmix], [Tcut], [Tcut!], [Tsh], [TshL], [TshR] and [Tsum]. In these cases, from the fact that the conclusion types with a nonempty linear context we can infer that at least one of the premises types with a nonempty linear context as well, so that we can apply the inductive hypotheses to infer liveness of one of the arguments of𝑃, which then implies liveness of𝑃. We illustrate with cases [Tmix] and [Tsh].

Case [Tmix]

We have

... 𝑃1⊢Δ1

... 𝑃2⊢Δ2

[Tmix]

par{𝑃1 | |𝑃2} ⊢Δ12;Γ where𝑃=par{𝑃1 | |𝑃2}andΔ = Δ12.

SinceΔ ≠∅, then eitherΔ1≠∅orΔ2≠∅. Assume w.l.o.g. thatΔ1≠∅.

By applying the i.h. to𝑃1 ⊢Δ1;Γwe conclude that𝑃1 =𝒞1[𝒳], where𝒞 is a static context and𝒳is either an action or a forwarder.

Let𝒞=par{𝒞1| | 𝑃2}. Then,𝒞is static and𝑃=𝒞[𝒳].

[fwd]

fwd𝑥 𝑦↓𝑥

:fwd

𝑠(𝒜)=𝑥 [act]

𝒜 ↓𝑥:act 𝑃↓𝑥:𝜎

[mix]

(par{𝑃| | 𝑄}) ↓𝑥:𝜎

𝑃↓𝑦:𝜎 𝑦≠𝑥

[cut]

(cut{𝑃 |𝑥| 𝑄}) ↓𝑦:𝜎

𝑄↓𝑧:𝜎 𝑧 ≠𝑥

[cut!]

(cut!{𝑦.𝑃 |𝑥|𝑄}) ↓𝑧:𝜎 𝑃↓𝑦:𝜎 𝑦≠𝑥

[share]

(share𝑥 {𝑃 | |𝑄}) ↓𝑦:𝜎

𝑃↓𝑥:𝜎

[sum]

(𝑃+𝑄) ↓𝑥:𝜎

𝑃≡𝑄 𝑄↓𝑥:𝜎 [≡] 𝑃↓𝑥:𝜎

Figure 6.3: Observability predicate𝑃↓𝑥:𝜎, 𝜎∈ {fwd,act} Case [Tsh].

We have

...

𝑃1 ⊢Δ1, 𝑥:U𝑓 𝐴;Γ

...

𝑃2 ⊢Δ2, 𝑥:U𝑓 𝐴;Γ [Tsh]

share𝑥 {𝑃1 | |𝑃2} ⊢Δ12, 𝑥 :U𝑓 𝐴;Γ where𝑃=share𝑥{𝑃1 | |𝑃2}andΔ = Δ12, 𝑥:U𝑓 𝐴.

By applying the i.h. to𝑃1 ⊢Δ1, 𝑥:U𝑓 𝐴;Γwe conclude that𝑃1 =𝒞1[𝒴], where𝒞is a static context and𝒴is either an action or a forwarder.

Let𝒞=share𝑥{𝒞1| | 𝑃2}. Then,𝒞is static and𝑃=𝒞[𝒴].

Notice that in this case both premises type with a nonempty linear context, indepen-dently of the conclusion, and so the hypothesis thatΔis nonempty is superfluous.

We could have opted to establish liveness ofshare𝑥 {𝑃1 | | 𝑃2}by applying the i.h.

to𝑃2⊢Δ2, 𝑥:U𝑓 𝐴;Γinstead. A similar situation happens for [Tcut].

The progress Theorem2states that a closed, i.e. typed with an empty typing context 𝑃⊢ ∅;∅and empty map𝜂, and live process𝑃reduces. If one tries to prove this statement by induction on a typing derivation for𝑃⊢ ∅;∅one soon realises, when analysing the case [Tcut], that we need to say something about open processes. That is, to compositionally prove progress we need to characterise the potential interactions of (possibly open) typed processes, for which we define the following observability predicate, which is akin to 𝜋-calculus observability (cf. [137]). Our proof is along the lines of [23], but here we rely in an observability predicated, whereas in [23] progress is established by relying on a labelled transition system instead.

Definition 17(Observability Predicate). The relation𝑃 ↓𝑥:𝜎, where𝜎 = fwd or 𝜎 = act, is defined by the rules of Figure6.3. We say that𝑥is an observable of𝑃or that we can observe𝑥in 𝑃, written𝑃↓𝑥, if either𝑃↓𝑥:fwdor𝑃↓𝑥:act. If𝑃↓𝑥:act, we say that𝑥is an observable action of𝑃. If𝑃↓𝑥:fwd, we say that𝑥is an observable forwarder of𝑃.

The definition of𝑃↓𝑥is explicitly closed under≡(rule [≡]) and propagates observations on the various static operators. For example, 𝑥 is an observable of a mixpar{𝑃 | | 𝑄}, provided 𝑥is an observable of one of its arguments𝑃or𝑄. The same principle applies to the cut construct with the proviso that we can never observe the name 𝑥 in a cut cut{𝑃 |𝑥| 𝑄}since it is kept private to the interacting processes𝑃and𝑄.

We can always observe the subject of an action (rule [act]) and we can observe the constituent names𝑥, 𝑦of a forwarderfwd𝑥 𝑦: observation of𝑥 is direct from rule [fwd], whereas observation of𝑦follows because of the≡commuting rule [fwd]fwd𝑥 𝑦≡fwd𝑦 𝑥

fwd𝑥 𝑦 ≡fwd𝑦 𝑥 [fwd]

fwd𝑦 𝑥↓𝑦 [≡] fwd𝑥 𝑦↓𝑥

In a shareshare𝑥{𝑃| |𝑄}, processes𝑃and𝑄run concurrently freely communicating with the external context and sharing memory cell𝑥. As a consequence, and similar to the cut construct, the share constructshare𝑥{𝑃 | |𝑄}propagates all the observations𝑦 for which 𝑦≠𝑥(rule [share]).

Intuitively,𝑥 is an observable of a process𝑃iff we can rewrite𝑃 in an≡-equivalent form𝑄so as to expose an action with subject𝑥or forwarderfwd𝑥 𝑦 and, furthermore, that action or forwarder in 𝑄 is not under the scope of a sharing construct on 𝑥. The following Definition18and Lemma2formalise this intuition

Definition 18. We say that a hole in a static context𝒞is guarded by a share on𝑥iff there are static contexts𝒞1,𝒞2and a process𝑃s.t. 𝒞=𝒞1[share𝑥 {𝒞2| |𝑃}]or 𝒞 =𝒞1[share𝑥{𝑃| | 𝒞2}]. Lemma 2. Let𝑃be a typed process. The following two propositions are equivalent

(1) 𝑃↓𝑥.

(2) 𝑃≡ 𝒞[𝒜]or𝑃≡ 𝒞[fwd𝑥 𝑦], where𝑠(𝒜)=𝑥,𝑥 ∈fn(𝑃), for some static context𝒞where the hole is not guarded by a share on𝑥.

Proof. Proof of (1) =⇒ (2): By induction on a derivation tree for𝑃↓𝑥 and case analysis on the root rule. We illustrate with some cases

Case: [fwd].

We have𝑃 =fwd𝑥 𝑦. Let𝒞be the empty context−. A similar analysis for case [act].

Case: [share].

We have

...

𝑃1𝑥 𝑦 ≠𝑥

[share]

share𝑦 {𝑃1 | |𝑃2} ↓𝑥 where𝑃 =share𝑦{𝑃1| |𝑃2}.

By applying the i.h. to𝑃1𝑥 we infer the existence of a static context 𝒞1 for which (2) is true of𝑃1.

Let 𝒞 =share 𝑦 {𝒞1 | | 𝑃2}. Notice that the hole in𝒞 is still no guarded by a share on𝑥 since𝑦≠𝑥.

Case: [≡].

We have

𝑃≡𝑃 ... 𝑃𝑥

[≡] 𝑃↓𝑥

Follows by applying i.h. to𝑃𝑥 and by transitivity of≡(≡rule [trans]).

Proof of (2) =⇒ (1): We prove by induction on the static context𝒞that𝒞[𝒳] ↓𝑥, where 𝒳stand for the action𝒜or the forwarderfwd𝑥 𝑦. Then, by applying rule [≡] we conclude that𝑃↓𝑥. We illustrate with some cases

Case: 𝒞=−.

Follows by applying either [fwd] or [act].

Case: 𝒞 =cut{𝒞 |𝑦| 𝑄}.

Applying i.h. to𝒞[𝒳]yields𝒞[𝒳] ↓𝑥.

Since 𝑥 ∈ fn(𝒞[𝒳])(as𝑥 ∈ fn(𝑃), 𝑃 ≡ 𝒞[𝒳] and≡preserves free names) we conclude that𝑦 ≠𝑥.

Hence, we can apply rule [cut] to obtaincut{𝒞[𝒳] |𝑦| 𝑄} ↓𝑥. Case: 𝒞 =share𝑦 {𝒞 | |𝑄}.

Applying i.h. to𝒞[𝒳]yields𝒞[𝒳] ↓𝑥.

Since the hole in𝒞is not guarded by a share on𝑥, we conclude that𝑦 ≠𝑥. Hence, we can apply rule [share] to obtainshare𝑦 {𝒞[𝒳]| |𝑄} ↓𝑥.

We will now present some properties (Lemma3) concerning the observability predicate, which will play a key role to derive progress.

Lemma 3(Properties of𝑃↓𝑥). The following properties hold

(1) Let𝑃⊢𝜂 Δ, 𝑥:U𝑓 𝐴;Γand𝑄⊢𝜂 Δ, 𝑥:U𝑓 𝐴;Γbe processes for which𝑃↓𝑥:actand𝑄↓𝑥:act. Then,share𝑥{𝑃| | 𝑄} ↓𝑥:act.

(2) Let𝑃⊢𝜂 Δ, 𝑥:U𝑒𝐴;Γ,𝑄⊢𝜂 Δ, 𝑥 :U𝑓 𝐴;Γ. If𝑃↓𝑥:𝑎𝑐𝑡, thenshare𝑥{𝑃| |𝑄} ↓𝑥:𝑎𝑐𝑡. (3) Let𝑃⊢𝜂 Δ, 𝑥:U𝑓 𝐴;Γ,𝑄⊢𝜂 Δ, 𝑥:U𝑒𝐴;Γ. If𝑄↓𝑥:𝑎𝑐𝑡, thenshare𝑥{𝑃| |𝑄} ↓𝑥:𝑎𝑐𝑡. (4) Let𝑃 ⊢𝜂 Δ, 𝑥 :𝐴;Γand𝑄⊢𝜂 Δ, 𝑥:𝐴;Γbe processes for which𝑃↓𝑥:actand𝑄↓𝑥:act. Then,

cut{𝑃 |𝑥| 𝑄}reduces.

(5) Let𝑃⊢𝜂 Δ, 𝑥:𝐴;Γ,𝑄 ⊢𝜂Δ, 𝑥:𝐴;Γbe processes for which𝑃↓𝑥:fwd. Then,cut{𝑃 |𝑥| 𝑄} reduces.

(6) Let𝑃 ⊢𝜂 𝑦 :𝐴;Γand𝑄⊢𝜂 Δ;Γ, 𝑥:𝐴be processes for which𝑄↓𝑥. Then,cut!{𝑦.𝑃 |𝑥|𝑄} reduces.

(7) Let𝑃 ⊢𝜂 Δ, 𝑥 : 𝐴;Γand suppose that 𝐴 ≠S𝑓 𝐵and𝐴 ≠ S𝑒 𝐵. If 𝑃 ↓𝑥:fwd, then either (i) 𝑃 ↓𝑦:fwdfor some𝑦:𝐴∈Δor (ii)𝑃reduces.

Proof. We give a proof sketch. Complete proofs for all properties ca be found in AppendixB.

(1) By double induction on derivation trees for𝑃↓𝑥:actand𝑄↓𝑥:act. For the base cases we apply either one of≡rules [RSh] or [TSh] in order to expose an observable action. For the inductive cases we consider that we are given a derivation tree for𝑃↓𝑥. This is w.l.o.g. sinceshare𝑥{𝑃| |𝑄} ≡share𝑥{𝑄| |𝑃}. In cases [mix], [cut], [cut!], [share]

we commute the share on𝑥with the principal form of𝑃by applying either≡rule [ShM], [CSh], [ShC!], [ShSh] or [ShSm]. The inductive case [≡] follows immediately because the relation≡is a congruence, i.e. satisfies≡rule [cong].

(2) By induction on the structure of a derivation for𝑃↓𝑥:𝑎𝑐𝑡 and case analysis on the root rule. The base case [act] follows by applying≡rule [PSh] in order to expose the put action. The inductive cases [mix], [cut], [cut!], [share], [sum] and [≡] are handled in the same way as (1).

(3) Follows by (2) and because share is commutative: share𝑥{𝑃| |𝑄} ≡share𝑥{𝑄| |𝑃}. (4) By double induction on derivation trees for𝑃 ↓𝑥:act and𝑄 ↓𝑥:act. For the base cases

we apply one of the principal cut conversions. For the inductive cases we consider that we are given a derivation tree for𝑃 ↓𝑥. This is w.l.o.g. sincecut{𝑃 |𝑥| 𝑄} ≡ cut{𝑄 |𝑥| 𝑃}. For cases [mix], [cut], [cut!], [share] we commute the cut on𝑥with the principal form of𝑃by applying either≡rule [CM], [CC], [CC!], [CSh] or [CSm]. The inductive case𝑃 ↓𝑥 rule [≡] follows immediately because the relation→is closed by structural congruence.

(5) By induction on a derivation trees for𝑃↓𝑥:fwd. The base case [fwd] follows by applying reduction rule→[fwd]. The inductive cases [mix], [cut], [cut!], [share], [sum] and [≡] are handled in the same way as (4).

(6) By induction on a derivation tree for𝑄↓𝑥 and case analysis on the root rule. The base case [act] follows by applying reduction rule →[call]. The inductive cases [mix], [cut], [cut!], [share] and [sum] follow by distributing the unrestricted cut over the arguments of𝑄(with≡rules [D-C!M], [D-C!C], [D-C!C!], [D-C!Sh] or [C!Sm]) and then apply the inductive hypothesis. The inductive case [≡] follows because reduction→is closed by structural congruence.

(7) By induction on a derivation tree 𝑃 ↓𝑥:fwd. In the inductive cases we propagate either the observable action on name 𝑦 or the reduction. In the action on name𝑦 occurs with a cutcut{− |𝑦| −}we trigger a reduction by applying (5). The typing constraints 𝐴≠ S𝑓 𝐵and𝐴≠ S𝑒 𝐵ensures that we can propagate the observable action on𝑦in case of a share.

Properties Lemma3(1)-(3) describe sufficient conditions to propagate observations𝑥 on a shareshare𝑥{𝑃 | |𝑄}.

Lemma3(1) states that we can observe a full usage on𝑥in ashare𝑥{𝑃| |𝑄}provided we can observe a full usage 𝑥 on both 𝑃 and 𝑄. This full usage on 𝑥 is propagated by applying either≡rule [RSh] or≡rule [TSh]. For example, by rule≡[RSh] we have share𝑥 {release𝑥 | |take𝑥(𝑦);𝑃} ≡take𝑥(𝑦);𝑃. Then

share𝑥 {release𝑥 | |take𝑥(𝑦);𝑃} ≡take𝑥(𝑦);𝑃

𝑠(take𝑥(𝑦);𝑃)=𝑥 [act]

take𝑥(𝑦);𝑃↓𝑥 [≡] share𝑥{release𝑥 | |take𝑥(𝑦);𝑃} ↓𝑥

Additionally, we can observe an empty usage 𝑥 onshare 𝑥 {𝑃 | | 𝑄} provided we can observe an empty usage𝑥on either𝑃or𝑄, as stated by Lemma3(2)-(3). The empty usage corresponds to a put action which can always be propagated to the top by applying≡rule [PSh].

Properties Lemma 3(4)-(6) describe sufficient conditions for obtaining a reduction:

either by observing two dual actions with subject 𝑥 in a linear cut cut {𝑃 |𝑥| 𝑄} (Lemma3(4)), by observing a forwarder𝑥on a linear cutcut{𝑃 |𝑥| 𝑄}(Lemma3(5)) or by observing a single action𝑥in the right argument𝑄of an unrestricted cutcut!{𝑦.𝑃|𝑥|𝑄} (Lemma3(6)).

Lemma3(7) characterises the potential observation or reduction of a process that𝑃 for which𝑃↓𝑥:fwd. Either name𝑦occurs free, and𝑃also offers a forwarder interaction at 𝑦, or lies in the scope of a cutcut{− |𝑦| −}, in which case a reduction can be triggered (Lemma 3(5)). The typing constraints 𝐴 ≠ S𝑓 𝐵 and 𝐴 ≠ S𝑒 𝐵 exclude processes like share𝑦{fwd𝑥 𝑦| |𝑄}, that neither reduce nor offer an interaction at𝑦. Intuitively, in this case, the share is suspended on the availability of cell usages at name𝑦. We will see later, when studying cut normalisation, in Chapter8, that this kind of processes will play a key role in defining normal forms.

We now state our liveness Lemma4which says that a live open process either reduces or offers an interaction at some session 𝑥. This lemma implies our main progress result (Theorem2), with which we conclude this section.

Lemma 4(Liveness). Let𝑃⊢Δ;Γbe such that𝑃is live. Either𝑃↓𝑥, for some𝑥, or𝑃reduces.

Proof. By induction on a typing derivation for𝑃 ⊢ Δ;Γ. We illustrate with some cases.

The complete proof can be found in AppendixB.

Case [T0]

We have

0⊢ ∅;Γ [T0]

where𝑃 =0. Holds vacuously because0is not live.

Case [Tvar]

We have 𝜂=𝜂, 𝑋( ®𝑦) ↦→Δ

[Tvar]

𝑋( ®𝑥) ⊢𝜂 { ®𝑥/ ®𝑦}(Δ) where 𝑃 = 𝑋( ®𝑥). Holds vacuously because assumes a nonempty𝜂context.

Case [T1]

Since𝑃=close𝑥is an action:

𝑠(close𝑥)=𝑥 [act]

close𝑥 ↓𝑥

Similarly for [Tfwd] and the other typing rules which introduce an action.

Case [Tcut]

We have

𝑃1 Δ1, 𝑥:𝐴;Γ 𝑃2 Δ2, 𝑥:𝐴;Γ [cut]

cut{𝑃1 |𝑥| 𝑃2} ⊢Δ12;Γ where𝑃 =cut{𝑃1 |𝑥| 𝑃2}andΔ = Δ12.

Since both𝑃1and𝑃2type with nonempty linear typing context and with an empty map𝜂, we conclude that both𝑃1and𝑃2are live (Lemma1).

By applying the i.h. to𝑃1Δ1, 𝑥:𝐴;Γand𝑃2 Δ2, 𝑥:𝐴;Γwe conclude that

• 𝑃1𝑦 or𝑃1reduces, and

• 𝑃2𝑧 or𝑃2reduces

We have the following cases to consider Case (𝑃1𝑦and𝑦 ≠𝑥) or (𝑃2𝑧 and𝑧 ≠𝑥)

Suppose w.l.o.g. that𝑃1𝑦and𝑦≠𝑥. Then

𝑃1𝑦 𝑦≠𝑥

[cut]

(cut{𝑃1 |𝑥| 𝑃2}) ↓𝑦 Case 𝑃1𝑥and𝑃2𝑥

We have the following two cases

Case 𝑃1𝑥:fwd or𝑃2𝑥:fwd

Suppose w.l.o.g. that𝑃1𝑥:fwd.

Then, by Lemma3(5), we conclude thatcut{𝑃1 |𝑥| 𝑃2}reduces.

Case 𝑃1𝑥:actand𝑃2𝑥:act

Then, by Lemma3(4), we conclude thatcut{𝑃1 |𝑥| 𝑃2}reduces.

Case 𝑃1reduces or𝑃2reduces

Because of→rule [cong],cut{𝑃1 |𝑥| 𝑃2}reduces.

Case [Tsh]

We have

𝑃1Δ1, 𝑥:U𝑓 𝐴;Γ 𝑃2Δ2, 𝑥:U𝑓 𝐴;Γ [Tsh]

share𝑥 {𝑃1 | |𝑃2} ⊢Δ12, 𝑥 :U𝑓 𝐴;Γ where𝑃 =share𝑥{𝑃1| |𝑃2}andΔ = Δ12, 𝑥:U𝑓 𝐴.

Since both𝑃1and𝑃2type with nonempty linear context and an empty map𝜂, then both𝑃1and𝑃2are live (Lemma1).

By applying the i.h. to𝑃1 Δ1, 𝑥 : U𝑓 𝐴;Γand𝑃2 Δ2, 𝑥: U𝑓 𝐴;Γwe conclude that

• 𝑃1𝑦 or𝑃1reduces, and

• 𝑃2𝑧 or𝑃2reduces.

We have the following cases to consider.

Case A (𝑃1𝑦and𝑦≠𝑥) or (𝑃2𝑧and𝑧≠𝑥) Suppose w.l.o.g. that𝑃1𝑦and𝑦≠𝑥. Then

𝑃1𝑦 𝑦≠𝑥

[share]

(share𝑥 {𝑃1 | |𝑃2}) ↓𝑦 Case B 𝑃1𝑥and𝑃2𝑥

We have the following two cases.

Case B1 𝑃1𝑥:fwdor𝑃2𝑥:fwd Suppose w.l.o.g. that𝑃1𝑥:fwd.

Observe that 𝑥 occurs typed by U𝑓 𝐴in the linear typing context of 𝑃1. Hence, we can apply Lemma3(7) in order to conclude that either (i)𝑃1𝑦 for𝑦 ≠𝑥or (ii)𝑃1reduces. If (i) go to case A. If (ii), go to case C.

Case B2 𝑃1𝑥:actand𝑃2𝑥:act.

Then(share𝑥{𝑃1| |𝑃2}) ↓𝑥 (Lemma3(1)).

Case C 𝑃1reduces or𝑃2reduces

Because of→rule [cong],share𝑥 {𝑃1 | |𝑃2}reduces.

Theorem 2(Progress). Let𝑃⊢∅;∅be a live process. Then,𝑃reduces.

Proof. Follows from Lemma4sincefn(𝑃)=∅.