On global types and multi-party sessions

. We present a new, streamlined language of global types equipped with a trace-based semantics and whose features and restrictions are semantically jus-tiﬁed. The multi-party sessions obtained projecting our global types enjoy a liveness property in addition to the traditional progress and are shown to be sound and complete with respect to the set of traces of the originating global type. Our notion of completeness is less demanding than the classical ones, allowing a multi-party session to leave out redundant traces from an underspeciﬁed global type.


Introduction
Relating the global specification of a system of communicating entities with an implementation (or description) of the single entities is a standard problem in many different areas of computer science.The recent development of session-oriented interactions has renewed the interest in this problem.In this work we attack it from the behavioral type and process algebra perspectives and briefly compare the approaches used in other areas.
A (multi-party) session is a place of interaction for a restricted number of participants that communicate messages.The interaction may involve the exchange of arbitrary sequences of messages of possibly different types.Sessions are restricted to a (usually fixed) number of participants, which makes them suitable as a structuring construct for systems of communicating entities.In this work we define a language to describe the interactions that may take place among the participants implementing a given session.In particular, we aim at a definition based on few "essential" assumptions that should not depend on the way each single participant is implemented.To give an example, a bargaining protocol that includes two participants, "seller" and "buyer", can be informally described as follows: Seller sends buyer a price and a description of the product; then buyer sends seller acceptance or it quits the conversation.If we abstract from the value of the price and the content of the description sent by the seller, this simple protocol describes just two possible executions, according to whether the buyer accepts or quits.If we consider that the price and the description are in distinct messages then the possible executions become four, according to which communication happens first.While the protocol above describes a finite set of possible interactions, it can be easily modified to accommodate infinitely many possible executions, as well as additional conversations: for instance the protocol may allow "buyer" to answer "seller" with a counteroffer, or it may interleave this bargaining with an independent bargaining with a second seller.
All essential features of protocols are in the example above, which connects some basic communication actions by the flow control points we underlined in the text.More generally, we interpret a protocol as a possibly infinite set of finite sequences of interactions between a fixed set of participants.We argue that the sequences that characterize a protocol-and thus the protocol itself-can be described by a language with one form of atomic action and three composition operators.Atomic actions: The only atomic action is the interaction, which consists of one (or more) sender(s) (e.g., "seller sends"), the content of the communication (e.g., "a price", "a description", "acceptance"), and one (or more) receiver(s) (e.g., "buyer").Compound actions: Actions and, more generally, protocols can be composed in three different ways.First, two protocols can be composed sequentially (e.g., "Seller sends buyer a price. . .; then buyer sends. . .") thus imposing a precise order between the actions of the composed protocols.Alternatively, two protocols can be composed without specifying any constraint (e.g., "Seller sends a price and (sends) a description") thus indicating that any order between the actions of the composed protocols is acceptable.Finally, protocols can be composed in alternative (e.g., "buyer sends acceptance or it quits"), thus offering a choice between two or more protocols only one of which may be chosen.More formally, we use p a −→ q to state that participant p sends participant q a message whose content is described by a, and we use « ; », « ∧ », and « ∨ » to denote sequential, unconstrained, and alternative composition, respectively.Our initial example can thus be rewritten as follows: The first two actions are composed without constraints, and they are to be followed by one (and only one) action of the alternative before ending.Interactions of unlimited length can be defined by resorting to a Kleene star notation.For example to extend the previous protocol so that the buyer may send a counter-offer and wait for a new price, it suffices to add a Kleene-starred line: The description above states that, after having received (in no particular order) the price and the description from the seller, the buyer can initiate a loop of zero or more interactions and then decide whether to accept or quit.
Whenever there is an alternative there must be a participant that decides which path to take.In both examples it is buyer that makes the choice by deciding whether to send accept or quit.The presence of a participant that decides holds true in loops too, since it is again buyer that decides whether to enter or repeat the iteration (by sending offer ) or to exit it (by sending accept or quit ).We will later show that absence of such decision-makers makes protocols impossible to implement.This last point critically depends on the main hypothesis we assume about the systems we are going to the describe, that is the absence of covert channels.On the one hand, we try to develop a protocol description language that is as generic as possible; on the other hand, we limit the power of the system and require all communications between different participants to be explicitly stated.In doing so we rule out protocols whose implementation essentially relies on the presence of secret/invisible communications between participants: a protocol description must contain all and only the interactions used to implement it.
Protocol specifications such as the ones presented above are usually called global types to emphasize the fact that they describe the acceptable behaviors of a system from a global point of view.In an actual implementation of the system, though, each participant autonomously implements a different part of the protocol.To understand whether an implementation satisfies a specification, one has to consider the set of all possible sequences of synchronizations performed by the implementation and check whether this set satisfies five basic properties: (1) Sequentiality: if the specification states that two interactions must occur in a given order (by separating them by a « ; »), then this order must be respected by all possible executions.So an implementation in which buyer may send accept before receiving price violates the specification (1.1) (and (1.2)).
(2) Alternativeness: if the specification states that two interactions are alternative, then every execution must exhibit one and only one of these two actions.So an implementation in which buyer emits both accept and quit (or none of them) in the same execution violates the specification (1.1).(3) Shuffling: if the specification composes two sequences of interactions in an unconstrained way, then all executions must exhibit some shuffling (in the sense used in combinatorics and algebra) of these sequences.So an implementation in which seller emits price without emitting descr violates the specification (1.1).(4) Fitness: if the implementation exhibits a sequence of interactions, then this sequence is expected by (i.e., it fits) the specification.So any implementation in which seller sends buyer any message other than price and descr violates the specification (1.1).(5) Exhaustivity: if some sequence of interactions is described by the specification, then there must exist at least an execution of the implementation that exhibits these actions (possibly in a different order).So an implementation in which no execution of buyer emits accept violates the specification (1.1).Checking whether an implemented system satisfies a specification by comparing the actual and the expected sequences of interactions is non-trivial, for systems are usually infinitestate.Therefore, on the lines of [HYC08], we proceed the other way round: we extract from a global type the local specification (usually dubbed local type or session type [THK94,HVK98]) of each participant in the system and we type-check the implementation of each participant against the corresponding session type.If the projection operation is done properly and the global specification satisfies some well-formedness conditions, then we are guaranteed that the implementation satisfies the specification.As an example, the global type (1.1) can be projected to the following behaviors for buyer and seller: seller → buyer!descr.buyer!price.(buyer?accept + buyer?quit) buyer → seller?descr.seller?price.(seller!accept⊕ seller!quit) or to seller → buyer!price.buyer!descr.(buyer?accept + buyer?quit) buyer → seller?price.seller?descr.(seller!accept⊕ seller!quit)where p!a denotes the output of a message a to participant p, p?a the input of a message a from participant p, p?a.T + q?b.S the (external) choice to continue as T or S according to whether a is received from p or b is received from q and, finally, p!a.T ⊕ q!b.S denotes the (internal) choice between sending a to p and continue as T or sending b to q and continue as S. We will call session environments the mappings from participants to their session types.It is easy to see that any two processes implementing buyer and seller will satisfy the global type (1.1) if and only if their visible behavior matches one of the two session environments above (these session environments thus represent some sort of minimal typings of processes implementing buyer and seller).In particular, both the above session environments are fitting and exhaustive with respect to the specification since they precisely describe what the single participants are expected and bound to do.
In this work we will discuss how to characterize a set of session environments (if any) from participants to session types that is sound and complete, with respect to a given global type.We will also show an algorithm that, in several practical cases, can effectively perform the extraction of the session environment from a global type.Observe that there are global types that are intrinsically flawed, in the sense that they do not admit any implementation (without covert channels) satisfying them.We classify flawed global types in three categories, according to the seriousness of their flaws.No sequentiality: The mildest flaws are those in which the global type specifies some sequentiality constraint between independent interactions, such as in (p a −→ q; r b −→ s), since it is impossible to implement r so that it sends b only after that q has received a (unless this reception is notified on a covert channel, of course).Therefore, it is possible to find exhaustive (but not fitting) implementations that include some unexpected sequences which differ from the expected ones only by a permutation of interactions done by independent participants.The specification at issue can be easily patched by replacing some « ; »'s by « ∧ »'s.No knowledge for choice: A more severe kind of flaw occurs when the global type requires some participant to behave in different ways in accordance with some choice it is unaware of.For instance, in the global type participant p chooses the branch to execute, but after having received a from q participant r has no way to know whether it has to send a or b.Also in this case it is possible to find exhaustive (but not fitting) implementations of the global type where the participant r chooses to send a or b independently of what p decided to do.
No knowledge, no choice: In the worst case it is not possible to find an exhaustive implementation of the global type, for it specifies some combination of incompatible behaviors, such as performing an input or an output in mutual exclusion.This typically is the case of the absence of a decision-maker in the alternatives such as in where each participant is required to choose between sending or receiving.There seems to be no obvious way to patch these global types without reconsidering also the intended semantics.We conclude this introduction by stressing that in this work we focus on single sessions.The participants of a system can concurrently implement and bring forward different sessions but we suppose the management of different sessions (e.g., the exchange of sessions channels) to belong to the meta-level.The internalization of such a level (i.e., the use of delegation) is left for future work (see Section 7.3.1).
Outline and contributions.We introduce a streamlined language of global specificationsthat we dub global types (Section 2)-and relate it with session environments (Section 3), that is, with sets of independent, sequential, asynchronous session types to be type-checked against implementations.Global types are just regular expressions augmented with a shuffling operator and their semantics is defined in terms of finite sequences of interactions.The semantics chosen for global types ensures that every implementation of a global type preserves the possibility to reach a state where every participant has successfully terminated.This implies that no participant of a multi-party session starves waiting for messages that are never sent or sends messages that no other participant will ever receive.This property is stronger than the progress enforced by other theories of multi-party sessions, where it is enough that two participants synchronize to be able to say that the session has progress.Technically, we make a strong fairness assumption on sessions by considering only fair computations, those where infinitely often enabled transitions occur infinitely often.
In Section 4 we study the relationship between global types and sessions.We do so by defining a projection operation that extracts from a global type all the (sets of) possible session types of its participants.This projection is useful not only to check the implementability of a global description (and, incidentally, to formally define the notions of errors informally described so far) but, above all, to relate in a compositional and modular way a global type with the sets of distributed processes that implement it.We also identify a class of well-formed global types whose projections need no covert channels.Interestingly, we are able to effectively characterize well-formed global types solely in terms of their semantics.
In Section 5 we present a projection algorithm for global types.The effective generation of all possible projections is impossible.The reason is that the projectability of a global type may rely on some global knowledge that is no longer available when working at the level of single session types: while in a global approach we can, say, add to some participant new synchronization offers that, thanks to our global knowledge, we know will never be used, this cannot be done when working at the level of single participant.Therefore in order to work at the projected level we will use stronger assumptions that ensure a sound implementation in all possible contexts.
In Section 6 we show some limitations deriving from the use of the Kleene star operator in our language of global types, and we present one possible way to circumvent them.Section 7 contains an extended survey of related work, with samples of the literature of session types and session choreography expressed in our syntax and an in-depth comparison with our work.Few final considerations conclude the work in Section 8.The Appendix contains proofs and some technical discussions.
We summarize the contributions of our work below: • With respect to (multi-party) session type theories [HYC08], we adopt a more abstract and -we claim-natural language of global types (Section 2) that is closely related to the language of Web service choreographies in [BZ07].We define a notion of session correctness that depends on a strong fairness assumption.On the one hand, this is more demanding than in other multi-party session theories because we insist on the property that a correct session must preserve the ability to reach a terminated state; on the other hand, we claim that eventual termination is indeed a desirable property of sessions, and we provide a number of examples showing that, if the hypothesis of an eventual termination of every session is assumed, our formalism allows for a range of projectable global specifications that is strictly larger than that other formalisms, under the same assumption, have.
where projection is defined by an homomorphism between the global and the local specifications, we define a significantly more sophisticated projection procedure (Sections 4 and 5) with two main upshots.First, we handle the projection of unconstrained composition of global specifications in a more flexible way, by permitting (partial) serialization of independent activities whenever this is either convenient or necessary.Second, we widen the range of projectable choreographies by imposing fewer constraints on the way alternative specifications can be composed together.We also point out some shortcomings of the Kleene star operator and propose a solution based on k-exit iterations that circumvents them (Section 6).• In order to account for the possible serializations of independent activities, we identify an original notion of completeness (Definition 4.1) of projections with respect to global specifications that is weaker (and consequently more flexible) than the corresponding notions in other theories.• Section 7 provides a rather detailed survey of a wide range of related formalisms and techniques.

Global Types
In this section we define the syntax and semantics of global types.We assume a set A of message types, ranged over by a, b, . . ., and a set Π of roles, ranged over by p, q, . . ., which we use to uniquely identify the participants of a session; we let π, . . .range over non-empty, finite sets of roles.Global types, ranged over by G , are the terms generated by the grammar in Table 1.Their syntax was already explained in Section 1 except for two novelties.First, we include a skip atom which denotes the unit of sequential composition (it plays the same role as the empty word in regular expressions).This is useful, for instance, to express optional interactions.Thus, if in our example we want the buyer to do at most one counteroffer instead of several ones, we just replace the starred line in (1.2) by which, using syntactic sugar of regular expressions, might be rendered as Second, we generalize interactions by allowing a finite set of roles on the l.h.s. of interactions.Therefore, π a −→ p denotes the fact that (the participant identified by) p waits for an a message from all of the participants whose tags are in π.We will write p a −→ q as a shorthand for {p} a −→ q.An example showing the usefulness of multiple roles on the left-hand side of actions is the following one which represents two buyers waiting for both the price from a seller and the mortgage from a bank before deciding the purchase.Notice that without this generalization the communication of accept to, say, the seller would be performed by two distinct communications from buyer1 and buyer2.But in that case, how could buyer1 be sure that buyer2 had received mortgage before sending accept to seller?And symmetrically, how could buyer2 be sure that buyer1 had received price before sending accept to seller?Actions with multiplesenders allow us to express the join of independent activities (in this case, the receival of price and mortgage).
To be as general as possible, one could also consider interactions of the form π a −→ π ′ , which could be used to specify broadcast communications between participants.We avoided this generalization since it cannot be implemented without covert channels.In fact in a sound execution of seller price −→ {buyer1,buyer2}, the reception of price by buyer1 should wait also for the reception of price by buyer2 and vice versa, and this requires a synchronization between buyer1 and buyer2.
In general we will assume p ∈ π for every interaction π a −→ p occurring in a global type, that is, we forbid participants to send messages to themselves.
For the sake of readability we adopt the following precedence of global type operators −→ * ; ∧ ∨.
Global types denote languages of legal interactions that can occur in a multi-party session.These languages are defined over the alphabet of interactions and we use α as short for π a −→ p when possible; we use ϕ, ψ, . . . to range over strings in Σ * and ε to denote the empty string, as usual.To improve readability we will occasionally use « ; » to denote string concatenation.
In order to express the language of a global type having the shape G 1 ∧ G 2 we need a standard shuffling operator over languages, which can be defined as follows: Definition 2.1 (shuffling).The shuffle of L 1 and L 2 , denoted by L 1 ∃ L 2 , is the language defined by: Observe that, in L 1 ∃ L 2 , the order of interactions coming from one language is preserved, but these interactions can be interspersed with other interactions coming from the other language.
Definition 2.2 (traces of global types).The set of traces of a global type is inductively defined by the following equations: where juxtaposition denotes concatenation and (•) ⋆ is the usual Kleene closure of regular languages.
Before we move on, it is worth noting that tr(G ) is a regular language (recall that regular languages are closed under shuffling).Since a regular language is made of finite strings, we are implicitly making the assumption that a global type specifies interactions of finite length.This means that we are considering interactions of arbitrary length, but such that the termination of all the involved participants is always within reach.This is a subtle, yet radical change from other multi-party session theories, where infinite interactions are considered legal.
By way of example, consider the global type which represents the bargain protocol described in the introduction.Every long enough string in tr(G ) has either the form for some appropriate ψ, meaning that the phase in which the buyer makes new offers can be arbitrarily long, although it must eventually terminate with the decision to either quit or accept.
Table 2: Syntax of pre-session types.

Multi-Party Sessions
We devote this section to the formal definition of the behavior of the participants of a multi-party session.
3.1.Session Types.We need an infinite set of recursion variables ranged over by X, . . . .Pre-session types, ranged over by T , S, . . ., are the terms generated by the grammar in Table 2 such that all recursion variables are guarded by at least one input or output prefix.We consider pre-session types modulo associativity, commutativity, and idempotence of internal and external choices, fold/unfold of recursions and the equalities p!a.T ⊕ p!a.S = p!a.(T ⊕ S) π?a.T + π?a.S = π?a.(T + S) Pre-session types are behavioral descriptions of the participants of a multi-party session.Informally, end describes a successfully terminated party that no longer participates to a session.The pre-session type p!a.T describes a participant that sends an a message to participant p and afterwards behaves according to T ; the pre-session type π?a.T describes a participant that waits for an a message from all the participants in π and, upon arrival of the message, behaves according to T ; we will usually abbreviate {p}?a.T with p?a.T .Behaviors can be combined by means of behavioral choices ⊕ and +: T ⊕ S describes a participant that internally decides whether to behave according to T or S; T + S describes a participant that offers to the other participants two possible behaviors, T and S. The choice as to which behavior is taken depends on the messages sent by the other participants.In the following, we sometimes use n-ary versions of internal and external choices and write, for example, As usual, terms X and rec X.T are used for describing recursive behaviors.For example, rec X.(p!a.X ⊕p!b.end) describes a participant that sends an arbitrary number of a messages to p and terminates by sending a b message; dually, rec X.(p?a.X + p?b.end) describes a participant that is capable of receiving an arbitrary number of a messages from p and terminates as soon a b message is received.
Session types are the pre-session types where internal choices are used to combine outputs, external choices are used to combine inputs, and the continuation after every prefix is uniquely determined by the prefix.Formally: Definition 3.1 (session types).A pre-session type T is a session type if either: • T = end, or • T = i∈I p i !a i .T i and ∀i, j ∈ I we have that p i !a i = p j !a j implies i = j and each T i is a session type, or • T = i∈I π i ?a i .T i and ∀i, j ∈ I we have that π i ⊆ π j and a i = a j imply i = j and each T i is a session type.

Session Environments.
A session environment is defined as the set of the session types of its participants, where each participant is uniquely identified by a role.Formally: In what follows we use ∆ to range over sessions and we write ∆ ⊎ ∆ ′ to denote the union of sessions, when their domains are disjoint.
To describe the operational semantics of a session we model an asynchronous form of communication where the messages sent by the participants of the session are stored within a buffer associated with the session.Each message has the form p a −→ q describing the sender p, the receiver q, and the type a of message.Buffers, ranged over by B, . . ., are finite sequences p 1 when p = p ′ or q = q ′ , that is, we care about the order of messages in the buffer only when these have both the same sender and the same receiver.In practice, this corresponds to a form of communication where each pair of participants of a multi-party session is connected by a distinct FIFO buffer.
There are two possible reductions of a session: The first rule describes the effect of an output operation performed by participant p, which stores the message p a k −→ p k in the buffer and leaves participant p with a residual session type T k corresponding to the message that has been sent.The second rule describes the effect of an input operation performed by participant p.If the buffer contains enough messages of type a coming from all the participants in π k , those messages are removed from the buffer and the receiver continues as described in T k .In this rule we decorate the reduction relation with π k a −→ p that describes the occurred interaction (as we have already remarked, we take the point of view that an interaction is completed when messages are received).This decoration will allow us to relate the behavior of an implemented session with the traces of a global type (see Definition 2.2).According to this semantics, the input prefixes {p 1 , . . ., p n }?a resemble join patterns p 1 ?a& • • • & p n ?a in the join calculus [FG96], except that we impose that all the messages coming from p 1 , . . ., p n have the same type.
We adopt some conventional notation: we write =⇒ for the reflexive, transitive closure of −→; we write α =⇒ for the composition =⇒ α −→=⇒ and We can now formally characterize the "correct sessions" as those in which, no matter how they reduce, it is always possible to reach a state where all of the participants are successfully terminated and the buffer has been emptied.
We adopt the term "live session" to emphasize the fact that Definition 3.3 states a liveness property: every finite computation ε ∆ ϕ =⇒ B ∆ ′ can always be extended to =⇒ ε {p i : end} i∈I .This is stronger than the progress property enforced by other multi-party session type theories, where it is only required that a session must never get stuck (but it is possible that some participants starve for messages that are never sent).As an example, the session is alive because, no matter how many a messages p sends, q can receive all of them and, if p chooses to send a b message, the interaction terminates successfully for both p and q.This example also shows that, despite the fact that session types describe finite-state processes, the session ∆ 1 is not finite-state, in the sense that the set of configurations This happens because there is no bound on the size of the buffer and an arbitrary number of a messages sent by p can accumulate in B before q receives them.As a consequence, the fact that a session is alive cannot be established in general by means of a brute force algorithm that checks every reachable configuration.By contrast, the session ∆ 2 = {p : rec X.q!a.X , q : rec Y.p?a.Y } which is normally regarded correct in other session type theories, is not alive because there is no way for p and q to reach a successfully terminated state.The point is that hitherto correctness of session was associated to progress (i.e., the system is never stuck).This is a weak notion of correctness since, for instance the session ∆ 2 ⊎ {r : p?c.end} satisfies progress even though role r starves waiting for its input.While in this example starvation is clear since no c message is ever sent, determining starvation is in general less obvious, as for ∆ 3 = {p : rec X.q!a.q!b.X , q : rec Y.(p?a.p?b.Y + p?b.r!c.end) , r : q?c.end} which satisfies progress, where every input corresponds to a compatible output, and viceversa, but which is not alive.
We remark once again that our work focuses on a single session.In particular, our definition of live session does not preclude the existence of a perpetual server that opens an unbounded number of sessions, each of them having a finite but unbounded length.
We can now define the traces of a session as the set of sequences of interactions that can occur in every possible reduction.It is convenient to define the traces of an incorrect (i.e., non-live) session as the empty set (observe that tr(G ) = ∅ for every G ). Definition 3.4 (session traces).
It is easy to verify that tr(∆ 1 ) = tr((p

Semantic projection
In this section we show how to project a global type to the session types of its participantsi.e., to a session-in such a way that the projection is correct with respect to the global type.Before we move on, we must be more precise about what we mean by correctness of a session ∆ with respect to a global type G .In our setting, correctness refers to some relationship between the traces of ∆ and those of G .In general, however, we cannot require that G and ∆ have exactly the same traces: when projecting G 1 ∧ G 2 we might need to impose a particular order in which the interactions specified by G 1 and G 2 must occur (shuffling condition).At the same time, asking only tr(∆) ⊆ tr(G ) would lead us to immediately lose the exhaustivity property, since for instance {p : q!a.end , q : p?a.end} would implement p a −→ q ∨ p b −→ q even though the implementation systematically exhibits only one (p a −→ q) of the specified alternative behaviors.In the end, we say that ∆ is a correct implementation of G if: first, every trace of ∆ is a trace of G (soundness); second, every trace of G is the permutation of a trace of ∆ (completeness).Formally: where L • is the closure of L under arbitrary permutations of the strings in L: Since these relations between languages (of traces) play a crucial role, it is convenient to define a suitable pre-order relation: 1 and extend it to global types and sessions in the natural way, by considering the corresponding sets of traces.Therefore, we write ∆ G if tr(∆) tr(G ) and similarly for G G ′ and ∆ ∆ ′ .
It is easy to see that soundness and completeness respectively formalize the notions of fitness and exhaustivity that we have outlined in the introduction.As for the remaining three properties listed in the introduction (i.e., sequentiality, alternativeness, and shuffling), they are entailed by the formalization of the semantics of a global type in terms of its traces (Definition 2.2).In particular, we have that soundness implies sequentiality and alternativeness, while completeness implies shuffling.Therefore, in the formal treatment that follows we will focus on soundness and completeness as the only characterizing properties connecting sessions and global types.The relation ∆ G summarizes the fact that ∆ is both sound and complete with respect to G , namely that ∆ is a correct implementation of the specification G .
Table 3 presents our rules for building the projections of global types.Projecting a global type basically means compiling it to an "equivalent" set of session types.Since the source language (global types) is equipped with sequential composition while the target language (session types) is not, it is convenient to parameterize projection on a continuation, i.e., we consider judgments of the shape: meaning that if ∆ is the projection of some G ′ , then ∆ ′ is the projection of G ; G ′ .We say that ∆ ′ is a projection of G with continuation ∆.This shape of judgments immediately gives us the rule (SP-Sequence).
The projection of an interaction π a −→ p adds p!a in front of the session type of all the roles in π, and π?a in front of the session type of p (rule (SP-Action)).For example we have: {p : end, q : end} ⊢ p a −→ q ⊲ {p : q!a.end, q : p?a.end}An alternative G 1 ∨ G 2 (rule (SP-Alternative)) can be projected only if there is a participant p that actively chooses among different behaviors by sending different messages, while all the other participants must exhibit the same behavior in both branches.The subsumption rule (SP-Subsumption) can be used to fulfill this requirement in many cases.
For example we have ∆ 0 ⊢ p a −→ q ⊲ {p : q!a.end, q : p?a.end} and ∆ 0 ⊢ p b −→ q ⊲ {p : q!b.end, q : p?b.end}, where ∆ 0 = {p : end, q : end}.In order to project p a −→ q ∨ p b −→ q with continuation ∆ 0 we derive first by subsumption ∆ 0 ⊢ p a −→ q ⊲ {p : q!a.end , q : T } and ∆ 0 ⊢ p b −→ q ⊲ {p : q!b.end , q : T } where T = p?a.end + p?b.end.Then we obtain Notice that rule (SP-Alternative) imposes that in alternative branches there must be one and only one participant that takes the decision.For instance, the global type cannot be projected since we would need a covert channel for p to agree with q about whether to send to r the message a or b.
Rule (SP-Subsumption) can be easily understood by recalling that we require a projection To project a starred global type we also require that one participant p chooses between repeating the loop or exiting by sending messages, while the session types of all other participants are unchanged.If T 1 and T 2 are the session types describing the behavior of p when it has respectively decided to perform one more iteration or to terminate the iteration, then T 1 ⊕ T 2 describes the behavior of p before it takes the decision.The projection rule requires that one execution of G followed by the choice between T 1 and T 2 projects in a session with type T 1 for p.This judgment is possible only if T 1 is a recursive type, as expected, and it is the premise of rule (SP-Iteration).For example if T 1 = q!a.rec X.(q!a.X ⊕ q!b.end), T 2 = q!b.end, and S = rec Y.(p?a.Y + p?b.end) we can derive {p : Notably there is no rule for « ∧ », the both constructor.We deal with this constructor by observing that all interleavings of the actions in G 1 and G 2 give global types G such that G G 1 ∧ G 2 , and therefore we can use the subsumption rule to eliminate every occurrence of « ∧ ».For example, to project the global type since the two actions that compose both global types have disjoint participants, then the projections of these global types (as well as that of r b −→ s; p a −→ q) will have exactly the same set of traces.
Other interesting examples of subsumptions useful for projecting are In (4.1) the -larger global type describes the shuffling of two interactions, therefore we can project one particular ordering still preserving completeness.In (4.2) we exploit the left-distributivity law of regular expressions to push the « ∨ » construct where the choice is actually being made (this is possible thanks to the trace semantics we adopt for global types).We are interested in projections without continuations, that is, in judgments of the shape {p : end | p ∈ G } ⊢ G ⊲ ∆ (where p ∈ G means that p occurs in G ) which we shortly write as ⊢ G ⊲ ∆ The mere existence of a projection does not mean that the projection behaves as specified in the global type.For example, we have ⊢ p a −→ q; r a −→ s ⊲ {p : q!a.end, q : p?a.end, r : s!a.end, s : r?a.end} but the projection admits the trace r a −→ s; p a −→ q which is not allowed by the global type.Clearly the problem resides in the global type, which tries to impose a temporal ordering between interactions involving disjoint participants.What we want, in accordance with the traces of a global type G 1 ; G 2 , is that no interaction in G 2 can be completed before all the interactions in G 1 are completed.In more detail: • an action π a −→ p is completed when the participant p has received the message a from all the participants in π; ψ is a trace of a global type, then either the action π ′ b −→ p ′ cannot be completed before the action π a −→ p is completed, or they can be executed in any order.The first case requires p to be either p ′ or a member of π ′ , in the second case the set of traces must also contain the trace ϕ; π This leads us to the following definition of well-formed global type.
Definition 4.2 (well-formed global type).We say that a set of traces L is well formed if It is easy to decide well-formedness of an arbitrary global type G by looking at the automaton that recognizes the language of traces generated by G .
Projectability and well-formedness must be kept separate because it is sometimes necessary to project ill-formed global types.For example, the ill-formed global type Clearly, if a global type is projectable (i.e., ⊢ G ⊲ ∆ is derivable) then well-formedness of G is a necessary condition for the soundness and completeness of its projection (i.e., for ∆ G ).It turns out that well-formedness is also a sufficient condition for having soundness and completeness of projections, as stated in the following theorem, whose proof is the content of Appendix A.
In summary, if a well-formed global type G is projectable, then its projection ∆ is a live session (it cannot generate the empty set of traces since tr(G ) ⊆ tr(∆) • ) which is sound and complete wrt G and, therefore, satisfies the sequentiality, alternativeness, and shuffling properties outlined in the introduction.
Remark 4.1.We now have all the ingredients for showing that actions involving multiple senders are not redundant, in the sense that they cannot be encoded in terms of more primitive actions with single senders.In particular, we show that the global type is not always equivalent to the expansion despite the fact that, in G 1 and G 2 , the same number of messages is exchanged between the very same participants.
If we consider the global types G ′ 1 and G ′ 2 defined by: Basically, both G ′ 1 and G ′ 2 specify the constraint that no b message is received by q before both a messages have been received by q 1 and q 2 .However, in G 2 the b messages are received by means of independent actions, and therefore it can happen that the b message from q 1 is received by q before the a message from p is received by q 2 , which is exactly the scenario described by the trace above that is not in tr(G ′ 2 ).The global type G 1 , on the other hand, specifies that the receive operation performed by q is considered completed only when both b messages from q 1 and q 2 are available.The interested reader may compare the projections of G ′ 1 and G ′ 2 and verify that the one for G ′ 2 does indeed exhibit an undesired trace.
We conclude this section by formally characterizing the three kinds of problematic global types we have described earlier.We start from the least severe problem and move towards the more serious ones.Let L # denote the smallest well-formed set such that L ⊆ L # .
No sequentiality.Assuming that there is no ∆ that is both sound and complete for G , it might be the case that we can find a session whose traces are complete for G and sound for the global type G ′ obtained from G by turning some « ; »'s into « ∧ »'s.This means that the original global type G is ill formed, namely that it specifies some sequentiality constraints that are impossible to implement.For instance, {p : q!a.end, q : p?a.end, r : s!b.end, s : r?b.end} is a complete but not sound session for the ill-formed global type p a −→ q; r b −→ s (while it is a sound and complete session for p a −→ q ∧ r b −→ s).We characterize the global types G that present this error as: No knowledge for choice.In this case every session ∆ that is complete for G invariably exhibits some interactions that are not allowed by G despite the fact that G is well formed.This happens when the global type specifies alternative behaviors, but some participants do not have enough information to behave consistently.For example, the global type mandates that r should send either a or b in accordance with the message that p sends to q.
Unfortunately, r has no information as to which message q has received, because q notifies r with an a message in both branches.A complete implementation of this global type is {p : q!a.(r?a.end + r?b.end) ⊕ q!b.(r?a.end + r?b.end), q : p?a.r!a.end + p?b.r!a.end, r : q?a.(q!a.end ⊕ q!b.end)} which also produces the traces p No knowledge, no choice.In this case we cannot find a complete session ∆ for G .This typically means that G specifies some combination of incompatible behaviors.For example, the global type p a −→ q ∨ q a −→ p implies an agreement between p and q for establishing who is entitled to send the a message.In a distributed environment, however, there can be no agreement without a previous message exchange.Therefore, we can either have a sound but not complete session that implements just one of the two branches (for example, {p : q!a.end, q : p?a.end}) or a session like {p : q!a.q?a.end, q : p?a.p!a.end}where both p and q send their message but which is neither sound nor complete.We characterize this error as: ∄∆ : tr(G ) ⊆ tr(∆) .

Algorithmic projection
We now attack the problem of computing the projection of a global type.We are looking for an algorithm that "implements" the projection rules of Section 4, that is, that given a session continuation ∆ and a global type G , produces a projection ∆ ′ such that ∆ ⊢ G : ∆ ′ .In other terms this algorithm must be sound with respect to the semantic projection (completeness, that is, returning a projection for every global type that is semantically projectable, seems out of reach, yet).
The deduction system in Table 3 is not algorithmic because of two rules: the rule (SP-Iteration) that does not satisfy the subformula property since the context ∆ used in the premises is the result of the conclusion; the rule (SP-Subsumption) since it is neither syntax-directed (it is defined for a generic G ) nor does it satisfy the subformula property (the G ′ and ∆ ′′ in the premises are not uniquely determined). 1 The latter rule can be expressed as the composition of the two rules Splitting (SP-Subsumption) into (SP-SubsumptionG) and (SP-SubsumptionS) is useful to explain the following problems we have to tackle to define an algorithm: (1) How to eliminate (SP-SubsumptionS), the subsumption rule for sessions.
(2) How to define an algorithmic version of (SP-Iteration), the rule for Kleene star.
(3) How to eliminate (SP-SubsumptionG), the subsumption rule for global types.We address each problem in order and discuss the related rules in the next sections.5.1.Session subsumption.Rule (SP-SubsumptionS) is needed to project alternative branches and iterations (a loop is an unbound repetition of alternatives, each one starting with the choice of whether to enter the loop or to skip it): each participant different from the one that actively chooses must behave according to the same session type in both branches.More precisely, to project G 1 ∨ G 2 the rule (SP-Alternative) requires to deduce for G 1 and G 2 the same projection: if different projections are deduced, then they must be previously subsumed to a common lower bound.The algorithmic projection of an alternative (see the corresponding rule in Table 4) allows premises with two different sessions, but then merges them.Of course not every pair of projections is mergeable.Intuitively, two projections are mergeable if so are the behaviors of each participant.This requires participants to respect a precise behavior: as long as a participant cannot determine in which branch (i.e., projection) it is, then it must do the same actions in all branches (i.e., projections).
For example, to project G = (p a −→ q; r c −→ q; . . . ) ∨ (p b −→ q; r c −→ q; . . . ) we project each branch separately obtaining ∆ 1 = {p : q!a . . ., q : p?a.r?c . . ., r : q!c . . .} and ∆ 2 = {p : q!b . . ., q : p?b.r?c . . ., r : q!c . . .}. Since p performs the choice, in the projection of G we obtain p : q!a . . .⊕ q!b . . .and we must merge {q : p?a.r?c . . ., r : q!c . . .} with {q : p?b.r?c . . ., r : q!c . . .}. Regarding q, observe that it is the receiver of the message from p, therefore it becomes aware of the choice and can behave differently right after the first input operation.Merging its behaviors yields q : p?a.r?c . . .+ p?b.r?c . . . .Regarding r, it has no information as to which choice has been made by p, therefore it must have the same behavior in both branches, as is the case.Since merging is idempotent, we obtain r : q!c . . . .In summary, mergeability of two branches of an « ∨ » corresponds to the "awareness" of the choice made when branching (see the discussion in Section 4 about the "No knowledge for choice" error), and it is possible when, roughly, each participant performs the same internal choices and disjoint external choices in the two sessions.
Special care must be taken when merging external choices to avoid unexpected interactions that may invalidate the correctness of the projection.To illustrate the problem consider the session types T = p?a.q?b.end and S = q?b.end describing the behavior of a participant r.If we let r behave according to the merge of T and S, which intuitively is the external choice p?a.q?b.end + q?b.end, it may be possible that the message b from q is read before the message a from p arrives.Therefore, r may mistakenly think that it should no longer participate to the session, while there is still a message targeted to r that will never be read.Therefore, T and S are incompatible and it is not possible to merge them safely.On the contrary, p?a.p?b.end and p?b.end are compatible and can be merged to p?a.p?b.end + p?b.end.In this case, since the order of messages coming from the same sender is preserved, it is not possible for r to read the b message coming from p before the a message, assuming that p sent both.More formally: Definition 5.1 (compatibility).We say that an input p?a is compatible with a session type T if either (i) p?a does not occur in T , or (ii) T = i∈I p i !a i .T i and p?a is compatible with T i for all i ∈ I, or (iii) T = i∈I π i ?a i .T i and for all i ∈ I either p ∈ π i and a = a i or p ∈ π i and p?a is compatible with T i .We say that an input π?a is compatible with a session type T if p?a is compatible with T for some p ∈ π.
Finally, T = i∈I π i ?a i .T i + j∈J π j ?a j .T j and S = i∈I π i ?a i .S i + h∈H π h ?a h .S h are compatible if π j ?a j is compatible with S for all j ∈ J and π h ?a h is compatible with T for all h ∈ H.
The merge operator just connects sessions with the same output guards by internal choices and with compatible input guards by external choices: Definition 5.2 (merge).The merge of T and S, written T S, is defined coinductively and by cases on the structure of T and S thus: • if T = i∈I π i ?a i .T i + j∈J π j ?a j .T j and S = i∈I π i ?a i .S i + h∈H π h ?a h .S h are compatible, then T S = i∈I π i ?a i .(Ti S i ) + j∈J π j ?a j .T j + h∈H π h ?a h .S h .
We extend merging to sessions so that Rules (AP-Alternative) and (AP-Iteration) of Table 4 are the algorithmic versions of (SP-Alternative) and (SP-Iteration), but instead of relying on subsumption they use the merge operator to compute common behaviors.
The merge operation is a sound but incomplete approximation of session subsumption insofar as the merge of two sessions can be undefined even though the two sessions completed with the participant that makes the decision have a common lower bound according to .
This implies that there are global types which can be semantically but not algorithmically projected.Take for example The behavior of r in G 1 and G 2 respectively is T = p?a.p!a.q?b.end and S = q?b.end.Then we see that G 1 ∨ G 2 is semantically projectable, for instance by inferring the behavior T + S for r.However, T and S are incompatible and G 1 ∨ G 2 is not algorithmically projectable.The point is that the relation on projections has a comprehensive perspective of the whole session and "realizes" that, if p initially chooses to send a, then r will not receive a b message coming from q until r has sent a to p.The merge operator, on the other hand, is defined locally on pairs of session types and ignores that the a message that r sends to p is used to enforce the arrival of the b message from q to r only afterwards.For this reason it conservatively declares T and S incompatible, making G 1 ∨ G 2 impossible to project algorithmically.Appendix B discusses further examples illustrating merge and compatibility.5.2.Projection of Kleene star.Since an iteration G * is intuitively equivalent to skip ∨ G ; G * it comes as no surprise that the algorithmic rule (AP-Iteration) uses the merge operator.The use of recursion variables for continuations is also natural: in the premise we project G taking recursion variables as session types in the continuation; the conclusion projects G * as the choice between exiting and entering the loop.There is, however, a subtle point in this rule that may go unnoticed: the projection of G * may require a continuation that includes actions and roles that precede G * .The point can be illustrated by the global type (p −→ q where p initially decides whether to enter the outermost iteration (by sending a) or not (by sending c).If it enters the iteration, then it eventually decides whether to also enter the innermost iteration (by sending b), whether to repeat the outermost one (by sending a), or to exit both (by sending c).Therefore, when we project (p b −→ q) * , we must do it in a context in which both p c −→ q and p a −→ q are possible, that is a continuation of the form {p : q!a . . .⊕ q!c.end} even though no a is sent by an action (syntactically) following (p b −→ q) * .For the same reason, the projection of (p −→ r will need a recursive session type for r in the continuation.5.3.Global type subsumption.Elimination of global type subsumption is the most difficult problem when defining the projection algorithm.While in the case of sessions the definition of the merge operator gives us a sound -though not complete-tool that replaces session subsumption in very specific places, we do not have such a tool for global type containment.This is unfortunate since global type subsumption is necessary to project several usage patterns (see for example the inequations (4.1) and (4.2)), but most importantly it is the only way to eliminate ∧-types (neither the semantic nor the algorithmic deduction systems have projection rules for « ∧ »).The minimal facility that a projection algorithm should provide is to feed the algorithmic rules with all the variants of a global type obtained by replacing occurrences of G 1 ∧ G 2 by either G 1 ; G 2 or G 2 ; G 1 .Unfortunately, this is not enough to cover all the occurrences in which rule (SP-SubsumptionG) is necessary.Indeed, while G 1 ; G 2 and G 2 ; G 1 are in many cases projectable (for instance, when G 1 and G 2 have distinct roles and are both projectable), there exist G 1 and G 2 such that G 1 ∧ G 2 is projectable only by considering a clever interleaving of the actions occurring in them.Consider for instance The projection of G 1 ∧ G 2 from the environment {q : p!a.end, r : p!b.end} can be obtained only from the interleaving The reason is that q and r receive messages only in one of the two branches of the « ∨ », so we need to compute the merge of their types in these branches with their types in the continuations.The example shows that to project G 1 ∧ G 2 it may be necessary to arbitrarily decompose one or both of G 1 and G 2 to find the particular interleaving of actions that can be projected.As long as G 1 and G 2 are finite (no non-trivial iteration occurs in them), we can use a brute force approach and try to project all the elements in their shuffle, since there are only finitely many of them.In general -i.e., in presence of iteration-this is not an effective solution.However, we conjecture that even in the presence of infinitely many traces one may always resort to the finite case by considering only zero, one, and two unfoldings of starred global types.To give a rough idea of the intuition supporting this conjecture consider the global type G * ∧ G ′ : its projectability requires the projectability of G ′ (since G can be iterated zero times), of G ∧ G ′ (since G can occur only once) and of G ; G (since the number of occurrences of G is unbounded).It is enough to require also that either G ; (G ∧ G ′ ) or (G ∧ G ′ ); G can be projected, since then the projectability of either So we can -or, conjecture we can-get rid of all occurrences of « ∧ » operators automatically, without losing in projectability.However, examples (4.1) and (4.2) in Section 4 show that rule (SP-SubsumptionG) is useful to project also global types in which the ∧-constructor does not occur.A fully automated approach may consider (4.1) and (4.2) as right-to-left rewriting rules that, in conjunction with some other rules, form a rewriting system generating a set of global types to be fed to the algorithm of Table 4.The choice of such rewriting rules must rely on a more thorough study to formally characterize the sensible classes of approximations to be used in the algorithms.An alternative approach is to consider a global type G as somewhat underspecified, in that it may allow for a large number of different implementations (exhibiting different sets of traces) that are sound and complete.Therefore, rule (SP-SubsumptionG) may be interpreted as a human-assisted refinement process where the designer of a system proposes one particular implementation G G ′ of a system described by G ′ .In this respect it is interesting to observe that checking whether L 1 L 2 when L 1 and L 2 are regular is decidable, since this is a direct consequence of the decidability of the Parikh equivalence on regular languages [Par66].25.4.Properties of the algorithmic rules.Every deduction of the algorithmic system given in Table 4, possibly preceded by the elimination of « ∧ » and other potential sources of failures by applying the rewritings/heuristics outlined in the previous subsection, induces a similar deduction using the rules for semantic projection (Table 3).For the proof see Appendix D.
As a corollary of Theorems 4.1 and 5.1, we immediately obtain that the projection ∆ of a well-formed G returned by the algorithm is sound and complete with respect to G .
Remark 5.1.Although every projection of a global type G produced by the algorithm is sound and complete with respect to G , let us stress once more that the algorithm itself is sound but not complete with respect to the semantic projection system defined in Figure 3: while every algorithmic projection is a semantic projection as well, there exist global types which are projectable semantically but not algorithmically.

k-Exit iterations
The syntax of global types (Table 1) includes that of regular expressions and therefore is expressive enough for describing any protocol that follows a regular pattern.Nonetheless, the simple Kleene star prevents us from projecting some useful protocols.To illustrate the point, suppose we want to describe an interaction where two participants p and q alternate in a negotiation in which each of them may decide to bail out.On p's turn, p sends either a bailout message or a handover message to q; if a bailout message is sent, the negotiation ends, otherwise it continues with q that behaves in a symmetric way.The global type describes this protocol as an arbitrarily long negotiation that may end in two possible ways, according to the participant that chooses to bail out.This global type cannot be projected because of the two occurrences of the interaction p handover −→ q, which make it ambiguous whether p actually chooses to bail out or to continue the negotiation.In general, our projection rules (SP-Iteration) and (AP-Iteration) make the assumption that an iteration can be exited in one way only, while in this case there are two possibilities according to which participant bails out.This lack of expressiveness of the simple Kleene star used in a nondeterministic setting [Mil84] led researchers to seek for alternative iterative constructs.
Table 5: Semantic projection of k-exit iteration.
, which is a generalization of the binary Kleene star and has the form indicating a loop consisting of k subsequent phases G 1 , . . ., G k .The loop can be exited just before each phase through the corresponding G ′ i .Formally, the traces of the k-exit iteration can be expressed thus: and, for example, the negotiation above can be represented as the global type while the unary Kleene star G * can be encoded as (G ) 1 * (skip).
In our setting, the advantage of the k-exit iteration over the Kleene star is that it syntactically identifies the k points in which a decision is made by a participant of a multiparty session and, in this way, it enables more sophisticated projection rules such as those in Table 5. Albeit intimidating, rule (SP-k-Exit Iteration) is just a generalization of rule (SP-Iteration).For each phase i a (distinct) participant p i is identified: the participant may decide to exit the loop behaving as S i or to continue the iteration behaving as T i .While projecting each phase G i , the participant p (i mod k)+1 that will decide at the next turn is given the continuation T (i mod k)+1 ⊕ S (i mod k)+1 , while the others must behave according to some R i that is the same for every phase in which they play no active role.Once again, rule (SP-Subsumption) is required in order to synthesize these behaviors.For example, the global type (6.1) is projected to {p : rec X.(q!handover.(q?handover.X + q?bailout.end)⊕ q!bailout.end),q : rec Y.(p?handover.(p!handover.Y ⊕ p!bailout.end)+ p?bailout.end)}as one expects.

Related work
The formalization and analysis of the relation between a global description of a distributed system and a more machine-oriented description of a set of components that implements it is a problem that has been studied in several contexts and by different communities.In this setting, important properties that are considered are the verification that an implementation satisfies the specification, the implementability of the specification, and the study of different properties of the specification that can then be transposed to each (possibly automatically In this work we focused on the implementability problem, and we tackled it from the "Web service coordination" perspective developed by the community that works on behavioral types and process algebrae.We are just the latest ones to attack this problem.So many other communities have been considering it before us that even a sketchy survey has no chance to be exhaustive.In what follows we describe two alternative approaches studied by important communities with a large amount of different and important contributions, namely the "automata" and "cryptographic protocols" approaches, and then focus on surveying our "behavioral types/process algebra" approach stressing the relations with the two other approaches and its peculiarities.7.1.Automata approach.Probably the most extensive research on this problem is pursued by the "automata/model-checking" (particularly, finite state automata) community where special care is paid to software engineering specification problems.In particular, a lot of research effort has focused on two specification languages standardized in telecommunications, the Message Sequence Charts (MSCs, ITU Z.120 standard) and the Specification and Description Language (SDL, ITU Z.100 standard).These respectively play the roles of our global types and session types.MSCs have become popular in software development thanks to their graphical representation that depicts every process by a vertical line and each message as an arrow from the sender to the receiver process fired according to their top-down ordering.This standard, included in UML, can also represent other features, such as timers, atomic events, local/global conditions, but it can represent neither iterations nor branching.This is why it has been extended to Message Sequence Graphs (MSGs, a special case of the High-Level Message Sequence Charts included in the Z.120 standard, with equivalent expressivity [MR97]) which consist of finite transition systems whose states encapsulate a single MSC: reaching a given state starts the execution of the embedded MSC whose termination makes the control move to another state.MSGs play the same role as our global types.
In particular the global type (1.2) of the introduction corresponds to the MSG in Figure 1.The MSG is formed by four states that embed a MSC each.The middle state can loop on itself or branch in one of the two possible final states.
While a MSG specifies the behavior of a distributed system in terms of interactions, Communicating Finite-State Machines (CFSMs) -the core theoretical model of SDL-  describe it in terms of its single components.They are systems of finite state automata that communicate via asynchronous unbounded FIFO channels.The automata transitions are labeled by communication primitives which specify the message and the sender or receiver of it and their execution triggers a read or write action on the corresponding buffer.A run is successful if each automaton ends its execution in a final state and all buffers are empty.An example is depicted in Figure 2 which implements the protocol described by the MSG of Figure 1.The automaton on the top implements the seller while the one on the bottom the buyer.They communicate by two directional buffers depicted in the middle of the figure.It is clear that every run of these machines places at most 2 messages in the buffers and that buffers of length 1 would suffice to implement this protocol without causing deadlocks.CFSMs essentially are our pre-session types: nothing prevents two transitions respectively labeled by an input and an output operation to spring from the same state.As in our case the interest is in relating MSGs with CFSMs so that the latter are implementations of the former.It comes as no surprise that the two formalisms are in general incomparable.As pointed out in [GMP03,GM05] this depends on two fundamental parameters: control and state.In MSGs (as well as in our global types) the control of branching is essentially global since it affects all the roles that occur in future executions, whereas in CFSMs (as well as in session types) it is inherently local, since it corresponds to the local transition function.Consequently, there are MSGs that are not implementable by CFSMs, insofar as the latter cannot implement global choices (in this work we further distinguished three degrees of "non implementability": no sequentiality, no knowledge for choice and no knowledge no choice).Viceversa, the unbounded buffers of CFSMs provide them with infinite states and this gives them a Turing equivalent expressivity [BZ83].MSGs, instead, are finitely generated, in the sense that for every MSG G there exists a finite set S of finite MSCs such that any execution of G can be written as the juxtaposition of the execution of elements in S .It is then clear that MSGs cannot specify all CFSMs systems (an example of this is the bit protocol in which a sender resends a message to a receiver since the acknowledgment arrived too late: to be specified, this protocol needs MSCs of arbitrary length, see [GMP03]).The relative expressive powers of the two formalisms (finitely generated vs. Turing complete) makes it apparent that the static verification of properties should be much "easier" on MSGs than on CFSMs.Indeed, the expressivity of CFSMs is used to justify the use of MSGs as an early specification tool to then be implemented (i.e., projected) into CFSMs: since CFSMs are Turing complete, all nontrivial behavioral properties -termination, reachability (i.e., is a given control state reachable?),deadlock-freedom, boundedness (i.e., is there some bound n such that every reachable configuration has buffers of size at most n?) -are undecidable.Even if some of these properties can be made decidable by some restrictions (e.g., reachability and safety properties become decidable with lossy channels, even though liveness properties and boundedness remain undecidable, see [Sch04]) is believed that a satisfactory set of decidable properties can be obtained only with trivial CFSMs (e.g., with only two processes or with bounded buffers).Half-duplex systems [CF05] made of two CFSMs, where each reachable configuration has at most one buffer non-empty, are closely related to dyadic sessions and exhibit a number of decidable results which, unfortunately, do not scale to systems made of an arbitrary number of machines, even if the half-duplex restriction is maintained.MSGs have potentially much better properties, since they are finitely generated.For instance, it is possible to determine the maximum size of the buffers that each MSC that composes an MSG has to use in order to execute it.Such properties combined with the fact that the global semantics of CFSMs/SDL specifications is much more difficult to understand than that of MSGs, explain why it is very sensible to start with a MSG, model-check its properties and then implement it as a set of CFSMs.However, MSGs do not have robust closure properties as, say, regular languages (the choice we made for our global types).As a consequence, many variants of MSGs have been proposed in the literature to make verification and projection effectively and efficiently implementable (an extensive list of references can be found in [GM05] and a more detailed comparison is given in [GMP03]).In particular if one considers the restrictions we imposed on our global types, namely that branching is controlled by one process (they are called local-choice MSGs), then properties can be model-checked in polynomial or tractable time (while in the general setting of MSGs many variants of model-checking are undecidable [AY99,MPS98]).MSGs can also be restricted to the class of regular MSGs that have robust properties and for which the implementability by deadlock-free CFSMs is decidable.In this context however implementability means generating the same set of traces [AEY00,AEY01].So we are in the presence of quite a strict definition of implementability.Other notions of implementability have been studied yielding different decidability results (e.g., see [AEY00,AEY01]): among these we can cite implementations allowed to produce messages not described by the MSG (i.e., unfit implementations, in the terminology used in our introduction), or the use of internal communications with messages on a distinct alphabet to synchronize the system (we avoided this approach which corresponds to using covert channels), or implementations allowed to admit deadlocks.The reader can refer to [GMP03] for an extensive survey.However we are not aware of weaker implementability definitions such as the notions of soundness and completeness we introduced here.These, besides being an original contribution of our work, are also the main point that makes algorithmic projection difficult.There are some works, such as [BB11], characterizing classes of CFSMs for which it is possible to decide the conformance with respect to a global specification (choreography).7.2.Cryptographic protocols.Another domain in which much research on this topic has been done is the verification of cryptographic protocols.In this context, protocol narrations, which describe protocols in terms of conversations between "roles", must be matched against or implemented into a set of specifications for the single roles.However the goals pursued in this area are quite different from the one we outlined in the previous section, which yields global specification languages with characteristics different from the one considered by the automata approach.A first important difference is the content of messages.While in the automata based research the content of communications is of lesser importance since it is usually drawn from a finite set of messages, in the domain of cryptographic protocols messages are defined by expressive languages that at least include cryptographic primitives.Whereas message content is richer, the communication pattern is somewhat simpler since security protocols are always of finite length, which is why MSCs rather than MSGs are used.However one has to be very precise about the way an agent processes its messages (which parts of a message should be extracted and checked by an agent and how an answer should be computed).This is why MSCs are annotated or enriched with mechanisms that express the internal actions to be performed by the agents.This gives raise to different flavors of formalisms (Figure 3 gives three samples of such languages: for more examples and a list of references see [CR10]).These global specifications are then used to verify security properties and, in some cases, to generate specifications for the roles composing them.Local specifications are much finer-grained and lower-level than those used in the automata approach.The details of internal executions of each agent are exposed and precisely defined since the overlook of small details may lead to dramatic flaws.This explains why the palette of languages used to describe the local behavior appears to be more variegated than in the previous area: the pioneering work on compilation by Carlsen [Car94] compiles protocol narrations into a modal logic of communication; the system Casper produces CSP descriptions of protocols that are suitable to be model-checked [Low98] while CAPSL [MD02] and CASRUL [JRV00] translate global specifications of protocols, such as those given in Figure 3 (HLPSL is the protocol specification language used by CASRUL), into rewriting systems; in [CVB06] MSCs are interpreted into systems of pattern matching spi-calculus processes [AG99,HJ06].Recent work has shown that most of the annotation and extensions of MSCs aimed at describing internal computations, can be computed automatically from the protocol narration, and thus compile lightly annotated MSCs into an operational semantics that describes the necessary internal actions [CR10].
The degree of detail about local behavior present both in global and local specification languages is not the only difference with the previous automata based approach.The other fundamental difference is the dynamism of the scenarios that both compilation and analysis must account for.Each role is not necessarily implemented by a single agent or process but the concurrent presence of several agents that interpret the same role must be allowed in the system.The system may include intruder agents that are not described by the global specification and that may interfere with it; in particular, they may intercept, read, destroy and forge messages and, more generally, change the topology of the communications.Furthermore different executions of the protocol may be not independent as attackers can store and detour information in one execution to use it in a later one.
In this context the works closest to our approach are [MK08] and [BCD + 09].McCarthy and Krishnamurthi [MK08] describe WPPL, a global description language which besides the basic communication action of MSCs provides actions for role definition and trust management.WPPL specifications are then projected in local behaviors defined in CPPL, a domain specific language that describes cryptographic protocol roles with trust annotations.In their work they give a nice comparison of their approach with the one used in Web services that we describe next.In particular, cryptography introduces information asymmetries (e.g., because of the presence of an intruder the message received by a role may be different from the one that was sent to it, or a encrypted message can be received only if the partner has the corresponding key) that are not handled by existing end-point projection systems.In a nutshell, in Web services global description formalisms as well as in the automata approach the focus is on communication patterns and the communication content is neglected, while in the realm of cryptographic protocols it is the combination of the two that really matters.
Bhargavan et al. describe in [BCD + 09] a compiler from high-level multi-party session descriptions to custom cryptographic protocols coded as ML modules.In the generated code each participant has strong security guarantees for all her/his messages against any adversary that may control both the network and some participants to the session.7.3.Web services.Our work springs from the research done to formally describe and verify compositions of Web services.This research has mainly centered on using process algebras to describe and verify visible local behavior of services and just recently (all the references date of the last five years) has started to consider global choreographic descriptions of multiple services and the problem of their projection.This yielded the three layered structure depicted in Figure 4 (courtesy of P.-M.Deniélou) where a global type describing the choreography is projected into a set of session types that are then used to type-check the processes that implement it (as well as guide their implementation).The study thus focuses on defining the relation between the different layers.Implementability is the relation between the first and second layer.Here the important properties are that projection produces systems that are sound and complete with respect to the global description (in the sense stated by Theorem 4.1) and deadlock free (e.g., we rule out specifications such as p a −→ q ∨ p a −→ r when it has no continuation, since whatever the choice either q or r will be stuck).Typeability is the relation between the second and third layer.Here the important properties are subject reduction (well-typed processes reduce only to well-typed processes) and progress (which in this context implies deadlock freedom).
Although in this work we disregarded the lower layer of processes, it is nevertheless an essential component of this research.In particular, it explains the nature of the messages that characterize this approach, which are types.One of the principal aims of this research, thus, is to find the right level of abstraction that must be expressed by types and session types.Consider again Figure 4.The process layer clearly shows the relation between the message received by bob and the one it sends to carol, but this relation (actually, any relation) is abstracted away both in the session and the global type layers.The level of abstraction is greater than that of cryptographic protocols since values are not tracked by global descriptions.Although tracking of values could be partially recovered by resorting to singleton types, there is a particular class of values that deserves special care and whose handling is one of the main future challenges of this research, that is, channels.The goal is to include higher order types in global specifications thus enabling the transmission of session channels and therefore the reification of dynamic reconfiguration of session topology.We thus aim at defining reconfiguration in the specification itself, as opposed to the case of cryptographic protocols where the reconfiguration of the communication topology is considered at meta-level for verification purposes.As a matter of fact, this feature has already been studied in the literature.For instance, the extension of ws-cdl [WSC05] with channel passing is studied in [CZ08] (as the automata approach has the MSC as their reference standard, so the Web service community refers to the ws-cdl standard whose implementability has been studied in [QZCY07]); the paper that first introduced a global calculus for session types [CHY07] explicitly mentions channels in messages that can be sent to other participants to open new sessions on them.In our opinion the existing works on session types are deeply syntactic in nature, in the sense that the operators in global types have been conceived as syntactic adaptations of the corresponding ones in session types.As a consequence, these operators do not always have a clear semantic justification.Here we preferred to take a step back and to start by defining global descriptions whose restrictions are semantically justified.So we favored a less rich language with few semantically justified features and leave the addition of more advanced features for a later time.
Coming back to the comparison of the three approaches, the Web service-oriented approach shares several features in common with the other two.As for the automata approach we (in the sense of the Web service community) focus on the expressiveness of the control, the possibility of branching and iteration, and the effective implementability into deadlock-free local descriptions.However the tendency for Web services is to impose syntactic restrictions from the beginning rather than study the general case and then devise appropriate restrictions with the sought properties (in this respect our work and those of Bravetti, Zavattaro and Lanese [BZ07, BZ08, BLZ08] are few exceptions in the panorama of the Web service approach).Commonalities with the cryptographic protocol approach are more technical.In particular we share the dynamism of the communication topology (with the caveat about whether this dynamism is performed at the linguistic or meta-linguistic level) and the robustness with respect to reconfiguration (the projected session types should ensure that welltyped process will be deadlock free even in the presence of multiple interleaved sessions and session delegation, though few works actually enforce this property [BCD + 08, DCdLY08]).As for cryptographic protocols, this dynamism is also accounted at level of participants since recent work in session types studies global descriptions of roles that can then be implemented by several different agents [DY11].Finally, we take into account the internal behavior of processes (similarly to what happens for cryptographic protocols) without giving a precise specification of it but using precise enough (session) types to prevent any possible internal behavior to disrupt the properties of systems.There are also some characteristics that are specific to our approach such as the exploration of new linguistic features (for instance in this work we introduced actions with multi-senders) and a pervasive use of compositional deduction systems that we inherit from type theory.We conclude this section with a more in-depth description of the main references in this specific area so as to give a more detailed comparison with our work.7.3.1.Multi-party global types.Global types were introduced in [HYC08] for multi-party sessions, while [CHY07] describes a global calculus for dyadic sessions.Channels are present in both [CHY07] and [HYC08].However the language of [CHY07] includes control structures and messages of complex form, since it was intended to be an executable language to describe Web-service interactions and, as such, it is directly projected into a language of processes.Thus it lacks the intermediate layer of Figure 4 which is bypassed by providing a more concrete upper layer.The three-layered structure of Figure 4 faithfully describes the work in [HYC08] which, nevertheless, presents several differences with the work presented here.In the syntax of our work, the global types of [HYC08] can essentially be described by the following grammar: ) In a nutshell, sequencing is replaced by prefix actions (terminated by "end"), labels are decorated by channels (ranged over by k), and general µ-recursive definitions replace the (less expressive) Kleene star.Session types (called "local types" in [HYC08]) are even more similar to those presented here, the only difference being that input/output actions, which have the form k?a.T and k!a.T , specify channel names rather than participant names.
While the syntactic differences are minimal, it is not so for semantic ones.A first important difference is that the global types of [HYC08] must satisfy several restrictions: (1) The set of participants of two global types composed in parallel must be disjoint.While this restriction clearly simplifies the algorithmic projection (the projection of of G 1 ∧ G 2 reduces to the projection of G 1 ; G 2 , cf.Section 5.3), it rules out simple protocols such as (1.1), the very first we presented in this work.
(2) The first actions of global types composed by branching must specify the same channel, the same sender, the same receiver, and distinct messages (actually, labels).Furthermore every participant that is neither the first sender nor the first receiver must behave the same in all branches.The use of the same channel and, to a lesser extent, of the same senders and receivers for branching is a consequence of having adopted the original syntax of labeled branching used in the session types of [HVK98].This first restriction forces the adoption of the second one: since session type communication specifies channels rather than participants, and since the channel is the same in all branches, then the only way for the (unique) receiver to distinguish the branches is to receive distinct messages on each of them.These restrictions, of syntactic origin, are more constraining than ours which just require the presence of a single "decision maker".The restriction for "passive" participants to have the same behavior in all branches is a quite coarse condition to enforce what in our system is called "mergeability" (a similar notion of merge was already introduced in [YDBH10, DY11]).The syntax of global types in [HYC08] is more constraining than ours and the semantics of sequential composition is weaker.For example, two interactions like p −→ s.end are required to happen in the same order as they occur in the global types only if k and k ′ are the same channel.Thus if k = k ′ the participants p, q, r, and s can be unrelated.The reason of such a choice is, once more, due to the fact that global types are designed in function of the session types as defined by [HVK98] where different channels are typed independently and, thus, sequentiality constraints can be enforced only between communications on a same channel.It is interesting to notice that the situation is somehow dual to the one presented here.While we demand the sequentiality of « ; » be strictly enforced, we accept any order on actions composed in parallel by a « ∧ ».In [HYC08] instead, while actions composed in parallel are forced to be independent (by demanding disjoint participants), any order of the "sequential" composition is accepted as long as it happens on distinct channels.
In order to appreciate the usage of global types of [HYC08] and their projection let us revisit the paradigmatic example given in [HYC08], according to which two buyers, buyer1 and buyer2, wish to collaborate to buy an item from a seller seller: buyer1 asks the item to seller, which sends a price to both buyers; buyer1 communicates to buyer2 its participation and buyer2 decides either to quit (by sending quit to seller) or to accept the price by communicating ok and the delivery address to the seller, and expecting a delivery date.This compound protocol is expressed as the following global type: Notice that in the final branching of the protocol each action starting a branch is a communication from buyer2 to seller on the same channel h of two different labels ok and quit (strictly speaking, two singleton types whose only value is, respectively, ok and quit ).As expected the above global type is projected into seller → h?string.k!int.k′ !int.(h?quit.end+ h?ok.h?string.k′ !date.end) buyer1 → h!string.k?int.l!int.endbuyer2 → k ′ ?int.l?int.(h!quit.end+ h!ok.h!string.k′ ?date.end)Notice how participants are replaced by channels.In particular this implies that buyer2 can distinguish the receptions from seller and buyer1 because they happen on distinct channels.Thus, in a sense, explicit channels play the same role of explicit participants in session types, except that the presence of channels makes global type analysis more difficult.This explains why such a feature has been abandoned in [DY11] (the latest follow up of the multi-party sessions work) where global types no longer specify channels and session types use participants instead of channels (see later on).
We said that [HYC08] enforces sequentiality only on a per channel basis.Concretely, this means that for every projection the interactions on h in the first and fifth or sixth lines of the protocol in (7.1) must happen in the same relative order as they appear in the global types, and the same must hold for interactions on k ′ in the third and sixth lines.A rough way to ensure this property would be to prune all actions that are not on a given channel and then impose a well-formedness condition akin to the one we introduced in Definition 4.2.In [HYC08] much a finer-grained technique is used: it performs a global analysis of the dependency relation of a global type and ensures sequentiality on a given channel by exploiting synchronization information on interactions occurring also on different channels.In [CHY07] a stricter condition (dubbed "well-threadedness") is described for dyadic sessions, and it enforces a sequentiality condition similar to our well-formedness.
Finally, we already saw that messages in the global types of [HYC08] can be either types (to describe value of the communication) or labels (to perform branching), but they can also be channels such as in , which allows global types to describe delegation.Delegation was introduced in [HYC08] for multi-party sessions and is directly inherited from the homonym feature of dyadic sessions [HVK98].A participant can delegate another agent to play his role in a session in a way that is transparent for all the remaining participants of the session.In the example above buyer1 delegates to buyer2 the task to continue the conversation with seller on k.By allowing higher-order channels, the concrete topology of communications may dynamically evolve.To ensure projectability in the presence of such a feature, further restrictions are required [HYC08].
If we focus on semantically justified restrictions, the presence of channels requires types to be "well-threaded" (to avoid that the use of different channels disrupts the sequentiality constraints of the specification) and message structures to be used "coherently" in different threads (to assure that a fixed server offers the same services to different clients), as discussed in [CHY07].We did not include such features in our treatment since we wanted to study the problems of sequentiality (which yielded Definition 4.2 of well-formed global type) and of coherence (which is embodied by the subsession relation whose algorithmic counterpart is the merge operator) in the simplest possible setting (a single multi-party session) without further complexity induced by extra features.As a consequence of this choice, our merge between session types is a generalization of the merge in [YDBH10,DY11] since we allow inputs from different senders (this is the reason why our compatibility is more demanding than the corresponding notion in [YDBH10]).Since our framework does not include channels, we naturally disregarded any issue arising from delegation.
Our crusade for simplification did not restrict itself to exclude features that seemed inessential or too syntax dependent, but it also used simpler forms of existing constructs.In particular an important design choice was to use Kleene star instead of more expressive recursive global types used in [HYC08,DY11].As an example, the global type describing an arbitrary long interaction between participants p and q that p may terminate at any time can be described as (p a −→ q) * ; p b −→ q in our calculus and as µX.(p −→ q.end) in [HYC08].The main advantage of the star over recursion is that it gives us a fair implementation of the projected specification almost for free.Fairness seems to us an important -though mostly neglected by current literature-requirement for (multi-party) sessions.In particular, it allows us to develop a theory where multi-party sessions preserve a stronger liveness property, namely the potential to successfully terminate (termination under fairness assumption).A direct consequence of our choice is that we are capable of projecting global types where the progress of some participants crucially relies on the eventual termination of arbitrarily long interactions involving other participants.For example, the global type is not in [HYC08].The point is that participant r is waiting for a c message that will be sent only if p stops sending a messages to q.This is guaranteed in our theory but not in [HYC08] where, in principle, p may send a messages to q forever.In general recursion is more expressive than iteration.For example, we cannot express non-terminating interactions such as µX.p a −→ q.X.In the present work we regard this global type as wrong and take the point of view that a session eventually terminates, although there can be no upper bound to its duration.Recursion is more flexible when it comes to specifying iterations with multiple exit paths.For example, the global type µX.(p handover −→ q.(q handover −→ p.X ∨ q bailout −→ p.end) ∨ p bailout −→ q.end) is a straightforward modeling of the global type that requires 2-exit iteration to be projected in our framework (Section 6).
The exploration of a whole palette of different paradigms for global and local types and of variations thereof is another element that distinguishes the research done in the Web service communities from that in other communities.In particular, the Web service community does not hesitate to borrow features from other communities and, in this respect, a remarkable work is the one on dynamic multirole session types by Deniélou and Yoshida [DY11].Consider again the very first example (1.1) of the introduction.It consists of just a single seller and a single buyer.While it seems reasonable to describe the protocol for a particular seller, it is restrictive to think that it will handle just one buyer at the time.The idea is that the seller will interact with a variable number of buyers, all implementing the same protocol, that will dynamically join and leave the session.Mutatis mutandis, Deniélou and Yoshida propose to describe the protocol as follows: Here buyer no longer denotes a single participant but rather a role that can be played by different participants (or processes) ranged over by x.The notion of role is extensively used in the research on the verification of cryptographic protocols, especially at a meta-linguistic level.Remarkably, Deniélou and Yoshida have internalized it, making it possible to precisely express the multi-role aspects of an interaction protocol both in global and in local types.Indeed, the possible projections of the global type above are: seller → ∀x : buyer.x!descr.x!price.(x?accept + x?quit) buyer → seller?descr.seller?price.(seller!accept⊕ seller!quit) and seller → ∀x : buyer.x!price.x!descr.(x?accept + x?quit) buyer → seller?price.seller?descr.(seller!accept⊕ seller!quit)Note that session types use participants instead of channels (global types such as (7.2) no longer specify channels).This yields projections that, apart from the quantifications in seller, are the same as those we gave in the introduction for example (1.1).Deniélou and Yoshida develop a theory that ensures communication safety (received messages are of the expected type) and progress (communications do not get stuck) of sessions in the presence of dynamically joining and leaving participants.
Finally, although we aimed at simplifying as much as possible, we still imposed a few restrictions that seemed unavoidable.Foremost, the sequentiality condition of Section 4: any two actions that are bound by a semicolon must always appear in the same order in all traces of (sound and complete) implementations.Surprisingly, in all current literature of multi-party session types we are aware of, just one work [CHY07] enforces the sequential semantics of « ; ».In [CHY07] the sequentiality condition, called connectedness, is introduced (albeit in a simplified setting since-as in [HVK98, HYC08]-instead of sequential composition the authors consider the simpler case of prefixed actions) and identified as one of three basic principles for global descriptions under which a sound and complete implementation can be defined.All other (even later) works admit to project, say, q a −→ p; r a −→ p in implementations in which p receives from r before having received from q.While the technical interest of relaxing the sequentiality constraint in the interpretation of the « ; » operator is clear -it greatly simplifies projectability-we really cannot see any semantically plausible reason to do it.
Our simpler setting allows us to give a semantic justification of the formalism and of the restrictions and the operators we introduced in it.For these reasons many restrictions that are present in other formalisms are pointless in our framework.For instance, two global types whose actions be interleaved in an arbitrary way (i.e., composed by « ∧ » in our calculus) can share common participants in our global types, while in [HYC08] (which use the parallel operator for « ∧ ») this is forbidden.So these works fail to project (actually, they reject) protocols as simple as the first line of the example given in the specification (1.1) in the introduction.Likewise we can have different receiver participants in a choice like, for example, the case in which two cooperating buyers wait for a price from a given seller: while such a situation is forbidden in [HYC08].
Another situation possible in our setting but forbidden in [HYC08,DY11] is to have different sets of participants for alternatives, such as in the following case where a buyer is notified about a price by the broker or directly by the seller, but in both cases gives an answer to the broker: where the two branches involve exactly the same set of participants.This form is compatible with respect to the notion of projection in [HYC08,DY11].However, the same transformation is not possible for (7.4) because in this case projectability relies on the fairness assumption.Indeed while we can consider a Kleene star as an infinite union of finite branches and thus, semantically, add the continuation to each of these branches, the finiteness of each branch is guaranteed in our framework but not in [HYC08,DY11].
7.3.2.Choreographies.Global types can be seen as choreographies [WSC05] describing the interaction of some distributed processes connected through a private multi-party session.Therefore, there is a close relationship between our work and those by Zavattaro and his colleagues [BZ07, LGMZ08, BZ08, BLZ08], which concern the projection of choreographies into the contracts of their participants.The choreography language in these works coincides with our language of global types (including the use of iteration instead of recursion).Basically, the only difference at syntactic level is that interactions have the form a p→q instead of p a −→ q.Just like in our case, a choreography is correct if it preserves the possibility to reach a state where all of the involved Web services have successfully terminated.There are some relevant differences though, starting from choreographic interactions that invariably involve exactly one sender and one receiver, while in the present work we allow for multiple senders.Other differences concern the communication model and the projection procedure.In particular, the communication model is synchronous in [BZ07], based on FIFO buffers associated with each participant of a choreography in [BZ08], and partially asynchronous in [BLZ08] (output actions can fire, and thus drive the choice of an internal choice, also in the absence of a dual active receiving action, but their continuation is blocked until the message is consumed by the receiver).Our model (Section 3) closely follows the ones adopted for multiparty sessions, where there is a single buffer and we consider the possibility for a receiver to specify the participant from which a message is expected.In [BZ07, LGMZ08, BZ08, BLZ08] the projection procedure is basically an homomorphism from choreographies to the behavior of their participants, which is described by a contract language equipped with parallel composition, while our session types are purely sequential.[BZ07,BZ08] give no conditions to establish which choreographies produce correct projections.In contrast, [BLZ08,LGMZ08] define three connectedness conditions that guarantee correctness of the projection for various (synchronous and asynchronous) semantics.The interesting aspect is that these conditions are solely stated on the syntax of the choreography, while we need the combination of projectability (Table 3) and well-formedness (Definition 4.2).Depending on the communication semantics, which can be synchronous or asynchronous in [BLZ08,LGMZ08], the connectedness conditions may impose different constraints if compared to our well-formedness.For example, the choreography p a −→ q; r b −→ p is connected for sequence according to [BLZ08] but is not well formed according to Definition 4.2.This is a consequence of the different communication models adopted in [BLZ08] and in the present work.In [BLZ08] it is not possible for p to receive the b message from r before q has received the a message from p because p will block on the output of a until q receives the message.In our model, output messages are inserted within the buffer associated with the session, so the sender can immediately proceed.This corresponds to the receiver semantics in [LGMZ08].
The connectedness conditions for alternative choreographies in [BLZ08, LGMZ08] impose stricter constraints since they require that the roles in both branches be the same.Therefore, the two global types involving the broker participant described by examples (7.3) and (7.4) are not connected.Additionally, the fact that these conditions are stated by looking at the syntax of choreographies may discriminate between equivalent choreographies.For example, the choreographies are equivalent (they generate the same set of traces), but only the second one is connected.In the first one, the fact that both branches emit actions where the sender can be either p or r seems to suggest the absence of a decision maker, while in fact there is one (r).Our definition of well-formedness, being based on the set of traces generated by a global type rather than its syntax, does not distinguish between the two choreographies.As we have shown, a careful projection procedure does not need these requirements for the projection to respect the choreography.
In [BZ07] the projection of choreographies with iteration is taken into account and in [LGMZ08] it is argued that the connected conditions scale without problems to this more general scenario.The authors do not address the limited expressiveness of singleexit iterations.For example, the first global type at the beginning of Section 6 yields a deadlocking projection also for [BZ07].Given the similarities between choreographies and global types it is reasonable to expect that the adoption of k-exit iterations might resolve the issue in their setting as well.
While discussing MSGs we argued that requiring the specification and its projection produce the same set of traces (called standard implementation in [GMP03]) seemed overly constraining and advocated a more flexible solution such as the definitions of soundness and completeness introduced in the present work.Interestingly, Bravetti, Lanese and Zavattaro [BLZ08] take the opposite viewpoint, and make this relation even stricter by requiring the relation between a choreography and its projection to be a strong bisimulation.
The problem of analyzing choreographies and characterizing their properties has been addressed also by the community studying multiagent systems.In particular, Baldoni et al. [BBC + 09] propose a notion of interoperable choreography which basically coincides with our notion of liveness: the interaction between the parties must preserve the ability to reach a state in which every party has successfully completed its task.Interoperability induces a notion of conformance between parties that is similar to our implementation pre-order and to other refinement relations.The main difference with respect to our work and those cited above is that in [BBC + 09] a choreography is directly represented as the composition of its participants and their behavior is described by means of finite-state automata rather than terms of a process algebra.It appears that the techniques of choreography projection described in the present paper can be easily adapted to the context of [BBC + 09] and that multiagent systems might provide an additional playground to further explore and validate the whole approach.7.3.3.Other calculi.In this brief overview we focused on works that study the relation between global specifications and local machine-oriented implementations.However in the literature there is an important effort to devise new description paradigms for either global descriptions or local descriptions.In the latter category we wish to cite [HVK98,BBDNL08], while [CP09] seems a natural candidate in which to project an eventual higher order extension of our global types.For what concerns global descriptions, the Conversation Calculus [CV09] stands out for the originality of its approach.

Conclusion
We think that the design-by-contract approach advocated in [CHY07, HYC08] and expanded in later works is a very reasonable way to implement distributed systems that are correct by construction.In this work we have presented a theory of global types in an attempt of better understanding their properties and their relationship with multi-party session types.We summarize the results of our investigations in the remaining few lines.First of all, we have defined a proper algebra of global types whose operators have a clear meaning.In particular, we distinguish between sequential composition, which models a strictly sequential execution of interactions, and unconstrained composition, which allows the designer to underspecify the order of possibly dependent interactions.The semantics of global types is expressed in terms of regular languages.Aside from providing an accessible intuition on the behavior of the system being specified, the most significant consequence is to induce a fair theory of multi-party session types where correct sessions preserve the ability to reach a state in which all the participants have successfully terminated.This property is stronger than the usual progress property within the same session that is guaranteed in other works.We claim that eventual termination is both desirable in practice and also technically convenient, because it allows us to easily express the fact that every participant of a session makes progress (this is non-trivial, especially in an asynchronous setting).We have defined two projection methods from global to session types, a semantic and an algorithmic one.The former allows us to reason about which are the global types that can be projected, the latter about how these types are projected.This allowed us to define three classes of flawed global types and to suggest if and how they can be amended.Most notably, we have characterized the absence of sequentiality solely in terms of the traces of global types, while we have not been able to provide similar trace-based characterizations for the other flaws.Finally, we have defined a notion of completeness relating a global type and its implementation which is original to the best of our knowledge.In other theories we are aware of, this property is either completely neglected or it is stricter, by requiring the equivalence between the traces of the global type and those of the corresponding implementation.Rule (SP-Subsumption): By induction tr(∆ ′ ) (tr(G ′ )tr(∆)) # , so by Lemma A.1(5a) tr(∆ ′′ ) (tr(G ′ )tr(∆)) # .From G ′ G we conclude tr(∆ ′′ ) (tr(G )tr(∆)) # by Lemma A.1(5c) and (5a).

Appendix B. More on merge and compatibility
We start with an example showing the utility of the compatibility condition.Let ∆ 1 = {q : p?a.r!b.end, r : q?b.end} and ∆ 2 = {q : p?c.p!d.r!b.end, r : p?e.q?b.end}.The merge of ∆ 1 and ∆ 2 is undefined, since the session types of r in ∆ 1 and ∆ 2 are not compatible: the problem is that the input q?b is not compatible with the session type p?e.q?b.end.Let ∆ be the session obtained by adding role p with the expected session type to the merge of ∆ 1 and ∆ 2 (ignoring the compatibility condition), that is, ∆ = {p : q!a.end ⊕ q!c.q?d.r!e.end, q : p?a.r!b.end + p?c.p!d.r!b.end, r : q?b.end + p?e.q?b.end}.Starting from the empty buffer and ∆ we can reach the stuck configuration in which the buffer contains the action p =⇒ p e −→ r {p : end, q : end, r : end} i.e., participant r chooses the wrong session type, since he is not aware in which branch he is.Notice that ∆ 1 ⊎ {p : q!a.end} and ∆ 2 ⊎ {p : q!c.q?d.r!e.end} can be obtained as  −→ r to project G 2 and reasoning as before we get ∆ ′ = {p : q!a.end ⊕q!c.q?d.r!e.end, q : p?a.r!b.end + p?c.r!b.p!d.end, r : q?b.end + p?e.q?b.end}.Also ∆ ′ is not a live session, and since we eliminated ∧ from G 2 in all possible ways we see no way to semantically project G 1 ∨ G 2 .

Figure 1 :
Figure 1: MSG of the seller-buyer protocol
may arise when choosing between repeating or exiting a loop: seller agency −→ broker; (broker offer −→ buyer; buyer counteroffer −→ broker) * ; (broker result −→ seller ∧ broker result −→ buyer) (7.4)which is again forbidden in[HYC08,DY11].Note that the interaction following « ; » in (7.3) can be distributed on the two branches, yielding the global type seller agency

Table 1 :
Syntax of global types.

Table 4 :
Rules for algorithmic projection.