• No results found

3 Relating Multiparty and Binary Session Type Theories

p!{liUi.Gir}i∈I if r = p p?{liUi.Gir}i∈I if r = q

i∈IGir otherwise ( as in Definition 3)

• (G1| G2)r =



Gir if r ∈ part(Gi) andr ∈ part(Gj), i = j ∈ {1, 2}

end if r ∈ part(G1) andr ∈ part(G2) When a side condition does not hold, the map is undefined.

Definition 5 (Well-Formed Global Types [12]). Global type G∈ G is well-formed (WF) if for allr ∈ part(G), the projection Gr is defined.

The last notion required in our characterization of multiparty session types as binary sessions is a swapping relation over global types [6], which enables transformations among causally independent communications. Such transfor-mations may represent optimizations that increase parallelism while preserving the intended global behavior.

Definition 6 (Global Swapping). The swapping relationswis the smallest congruence onG which satisfies the rules in Fig.3. (The symmetric of ( sw2) is omitted.)

3 Relating Multiparty and Binary Session Type Theories

Our analysis of multiparty protocols as binary sessions relies on the medium process of a global type. Mediums offer a simple device for analyzing global types using the binary session types of [5]. Mediums uniformly capture the sequencing behavior in a global type, for they take part in all message exchanges between local participants.

After defining mediums (Definition 7), we establish their characterization results (Theorems4and5). We then present a process characterization of global swapping (Definition 6) in terms of context bisimilarity (Theorem 6). Subse-quently, we state operational correspondence results (Theorem 7), exploiting the auxiliary notions of instrumented mediums (Definition 10) and multiparty systems (Definition 11). We use the following conventions.

82 L. Caires and J.A. P´erez

Convention 3 (Indexed/Annotated Names). We consider names indexed by participants p, q, . . ., noted cp, cq, . . . and names annotated by participants, noted kp, kq, . . .. Given p = q, indexed names cp and cq denote two different objects; in contrast, annotated names kp and kq denote the same name k with different annotations. Given a G with part(G) = {p1, . . . ,pn}, we will write npart(G) to denote the set that contains a unique name cpj for every participant pj of G. We will occasionally use npart(G) as an unordered sequence of names.

Definition 7 (Mediums). The medium of G ∈ G, denoted MG, is defined as follows:

• Mend = 0

• MG1| G2 = MG1 | MG2

• Mpq:{liUi.Gi}i∈I = cp

li: cp(u).cqli; cq(v).([u↔v] | MGi)

i∈I

The key case is Mp  q:{liUi.Gi}i∈I: note how the medium uses two prefixes (on name cp) to mediate withp, followed by two prefixes (on name cq) to mediate withq. We illustrate mediums by means of an example:

Example 2. The medium process for global type GBSin Example1is:

MGBS = cB1

send : cB1(v).cSsend ; cS(w).([w↔v] | cS{rep : cS(v).cB1rep; cB1(w).([w↔v] |

cS{rep : cS(v).cB2rep; cB2(w).([w↔v] | cB1{shr : cB1(v).cB2shr ; cB2(w).([w↔v] |

cB2{ ok : cB2(v).cSok ; cS(w).([w↔v] | 0) ,

quit : cB2(v).cSquit ; cS(w).([w↔v] | 0)})})})}) Intuitively, we expect that (well-typed) process implementations forB1, B2, and S should interact with MGBS through channels cB1, cB2, and cS, respectively. We now move on to state our characterization results. We require two auxiliary notions, given next. Below, we sometimes write Γ ; Δ MG instead of Γ ; Δ MG :: z:1, when z ∈ fn(MG).

Definition 8 (Compositional Typing). We say Γ ; Δ MG::z:C is a com-positional typing if: (i) it is a valid typing derivation; (ii) npart(G) ⊆ dom(Δ);

and (iii) C = 1.

A compositional typing says that MG depends on behaviors associated to each participant of G; it also specifies that MG does not offer any behaviors of its own. We relate binary session types and local types: the main difference is that the former do not mention participants. Below, B ranges over base types (bool, nat, . . .) in Definition2.

Definition 9 (Local Types → Binary Types). Mapping · from local types T (Definition 2) into binary types A (Definition 1) is inductively defined asend = B = 1 and

p!{liUi.Ti}i∈I = ⊕{li:Ui ⊗ Ti}i∈I

p?{liUi.Ti}i∈I = {li:Ui Ti}i∈I.

3.1 Characterization Results

Our characterization results relate process MG (well-typed with a composi-tional typing) and G p1, . . . , G pn (i.e., the local types of G transformed into binary session types via Definition 9). Our characterization results are in two directions, given by Theorems 4 and 5. The first direction says that well-formedness of global types (Definition5) ensures compositional typings for medi-ums with (logic based) binary session types:

Theorem 4 (Global Types → Typed Mediums). Let G ∈ G. If G is WF with part(G) = {p1, . . . ,pn} then Γ ; cp1:G p1, . . . , cpn:G pn MG is a compositional typing, for some Γ .

The second direction of the characterization is the converse of Theorem4: com-positional typings for mediums induce global types which are WF. Given local types T1, T2, below we write T1 T2 if there exists a local type T such that T1 T = T2 (cf. Definition 3). This notation allows us to handle the labeled alternatives silently introduced by rule (TL2).

Theorem 5 (Well-Typed Mediums → Global Types). Let G ∈ G. If Γ ; cp1:A1, . . . , cpn:An MG is a compositional typing then ∃T1, . . . , Tn such that GpjTj andTj = Aj, for allpj∈ part(G).

Theorems4and5tightly connect (i) global types, local types and projection, and (ii) medium processes, and logic-based binary session types. They also provide an independent deep justification, through purely logical arguments, to the notion of projection.

3.2 A Behavioral Characterization of Global Swapping

Global swapping (Definition6, Fig.3) can be directly justified from more prim-itive notions, based on the characterizations given by Theorems 4 and 5. By abstracting a global type’s behavior in terms of its medium we may reduce trans-formations on global types to type-preserving transtrans-formations on processes. This is the content of Theorem 6 below, which connects global swapping (sw) and context bisimilarity (≈). Hence, sequentiality of mediums can be relaxed in the case of causally independent exchanges captured by sw.

Theorem 6. Let G1 ∈ G such that MG1 has a compositional typing Γ ; Δ MG1, for some Γ, Δ. If G1swG2 then Γ ; Δ MG1 ≈ MG2.

Since MG is a low-level representation of G, the converse of Theorem6 is less interesting, for type-preserving transformations at the (low) level of mediums do not always correspond to behavior-preserving transformations at the (high) level of global types. That is, since MG implements each communication in G using several prefixes, swapping in G occurs only when all relevant prefixes in MG can be commuted via c.

84 L. Caires and J.A. P´erez

3.3 Operational Correspondence Results

The results given so far focus on the static semantics of multiparty and binary systems, and are already key to justify essential properties such as absence of global deadlock. We now move on to dynamic semantics, and establish oper-ational correspondence results between a global type and its medium process (Theorem7).

We define the instrumented medium of a global type G, denoted MkG, as a natural extension of Definition7. Process MkG exploits fresh sessions (denoted

k), to emit a visible signal for each action of G. We use k as annotated names (cf. Convention3): each action on a ki contains the identity of the participant of G which performs it. Then, using MkG we define the set of systems associated to G (Definition 11), which collects process implementations for G mediated by MkG. Since interactions between local implementations and MkG are unobservable actions, Theorem 7 connects (i) the visible behavior of a system along annotated names k, and (ii) the visible behavior of G, defined by an LTS on global types (a variant of that in [12]). Below, kp.P stands for kp(x).P when x is not relevant in P . Also, kp.P stands for kp(v).(0| P ) for some v.

Definition 10 (Instrumented Mediums). Let k be fresh, annotated names.

The instrumented medium of G∈ G with respect to k, denoted MkG, is defined as follows:

• Mkend = 0

• Mk1,k2G1| G2 = Mk1G1 | Mk2G2

• Mkpq:{liUi.Gi}i∈I = cp

li : kpli; cp(u). kp.

cq li; kq {li: cq(v).([u↔v] | kq.MkGi)}{i}

i∈I

The key case is Mkp  q:{liUi.Gi}i∈I. Each action of the multiparty exchange is “echoed” by an action on annotated name k: the selection of label li byp is followed by prefix kp li; the output fromp (captured by the medium by the input cp(u)) is echoed by prefix kp. This way, the instrumented process MkG induces a fine-grained correspondence with G, exploiting process actions with explicit participant identities.

To state our operational correspondence result, we introduce extended global types and a labeled transition system (LTS) for (extended) global types. The syntax of extended global types is defined as G ::= G

|

G1| G2with

G ::=end

|

pq:{liUi.Gi}i∈I

|

pq: lU.G

|

pq: l((U)).G

|

pq: ((U)).G We consider parallel composition of sequential global types. We also have three auxiliary forms for global types, denoted with : they represent intermediate steps. Types p  q: lU.G and p  q: l((U)).G denote the commitment of p to output and input along label l , resp. Type p  q: ((U)).G represents the state just before the actual input action by q. We need the expected extension of Definition10for these types.

p q:{li Ui .Gi}i∈I p lj

−−−→ p q: lj Uj .Gj (j ∈ I) p q: l U .G−→ pp q: l ((U )).G p q: l ((U )).G−−→ pq l q: ((U )).G p q: ((U )).G−→ Gq

Fig. 4. LTS over finite, extended global types (Excerpt).

We adapt the LTS in [12] to the case of (extended) global types. The set of observables is σ ::= p

|

p l

|

p

|

p l. Below, psubj(σ) denotes the partic-ipant in σ. This way, e.g., psubj(p l) = p. The LTS over global types, noted G−→ Gσ , is defined by rules including those in Fig.4. Since Definition10 anno-tates prefixes on k with participant identities, their associated actions will be annotated too; given a participantp, we may define the set of annotated visible actions as: λp::= kp(y)

|

kpl

|

kpy

|

kp(y)

|

kpl . We write kpand kpto denote actions kp(y) and kp(y), resp., whenever object y is unimportant. Also, psubj(λp) denotes the participantp which annotates λ. This way, e.g., psubj(kp) =p and psubj(kql ) =q. To relate labels for global types and process labels, given an annotated name k, we define mappings {{·}}k and|| · || as follows:

{{p}}k= kp {{p l}}k = kpl {{p }}k = kp {{ p l }}k= kpl

||kp|| = p ||kpl|| = p l || kp|| = p || kpl|| = p l

Operational correspondence is stated in terms of the multiparty systems of a global type. Following Definition 8, we say that Γ ; Δ, Δ MkG :: z:C is an instrumented compositional typing if (i) it is a valid typing derivation;

(ii) npart(G) ⊆ dom(Δ); (iii) C = 1; (iv) dom(Δ) = k:

Definition 11 (Systems). Let G ∈ G be a WF global type, with part(G) = {p1, . . . ,pn}. Also, let Γ ; Δ, Δ MkG be an instrumented compositional typ-ing, with Δ = cp1:Gp1, . . . , cpn:Gpn, for some Γ . Let z = npart(G). The set of systems of G is defined as:

Sk(G) =

(νz)(Q1|· · ·| Qn| MkG)

|

·; · Qj :: cpj:Gpj, j ∈ 1 . . . n Thus, given G, a multiparty system is obtained by composing MkG with well-typed implementations for each of the local projections of G. An R∈ Sk(G) is an implementation of the multiparty protocol G. By construction, its only visible actions are on annotated names: interactions between all the Qjand MkG will be unobservable.

Theorem7below connects global types and systems: it confirms that (instru-mented) medium processes faithfully mirror the communicating behavior of extended global types. Below, we write G−−−→ Gσ[p] if G−→ Gσ and psubj(σ) =p.

Also, we write P −−−→ Pλ[p]  (resp. P =λ[p]⇒ P) if P −→ Pλ  (resp. P =λ⇒ P) holds and psubj(λ) =p.

86 L. Caires and J.A. P´erez

Theorem 7 (Operational Correspondence). Let G be an extended WF global type and R ∈ Sk(G). We have: If G −−−→ Gσ[p]  then R=λ[p]⇒ R, for some λ, R, k∈ k such that λ = {{σ}}k and R∈ Sk(G). Moreover, if there is some R0

s.t. R =⇒ R0

−−−→ Rλ[p]  then G−−−→ Gσ[p] , for some σ, G such that σ =||λ|| and R∈ Sk(G).