Abstract Subtyping for
Asynchronous Multiparty Sessions
Abstract
Session subtyping answers the question of whether a program in a communicating system can be safely substituted for another, when their communication behaviour is described by session types. Asynchronous session subtyping is undecidable, even for two participants, hence the interest in sound, but incomplete, subtyping algorithms. Asynchronous multiparty subtyping can be formulated by decomposing session types into single input and output types which preclude, respectively, external and internal choice. This paper shows how abstract interpretation can sit atop this approach and how it leads to an algorithm that can prove subtyping for intricate communication patterns.
Keywords and phrases:
asynchrony, session subtyping, automata, abstract interpretationCopyright and License:
2012 ACM Subject Classification:
Theory of computation Program reasoning ; Theory of computation Process calculiFunding:
This work was supported by EPSRC project EP/T014512/1 (STARDUST) and the PRIN 2022 PNRR project DeLiCE (F53D23009130001).Editors:
Patricia Bouyer and Jaco van de PolSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
A significant challenge in message-passing concurrency is ensuring that each process in the system adheres to a desired protocol and is free from communication errors. Session types have proved to be powerful in addressing this challenge: they provide a theory for designing protocols with desirable behavioural guarantees, and are directly applicable to programming languages (notably Java [31], Python [22], Rust [33], Go [34] and Erlang [24, 37]) via static type-checking, runtime monitoring, or API generation. Session types were initially proposed for binary sessions involving only two roles (aka participants) [29], and were later extended to multiparty sessions, to allow for many roles [30]. Multiparty session types produce, via automated projection from a global protocol, a safe (by construction) realisation given as a collection of local types, one for each role. In this work we use this as a starting point: a collection of local types whose communications are safe in the sense that no role will ever: (1) get stuck (until it terminates); and (2) receive an unexpected message.
To illustrate protocol realisation, consider the three local types below: a server , a client , and a logger , where , , and denote the respective roles. The server can initially receive two kinds of messages from the client: for more feeds or for termination. Feed requests are served with a feed () and waiting for further requests. The logging process gets regular updates by the server and sends a final summary to the client:
We omit formalities on the semantics for the purposes of this introduction, and instead use color coding to hint at the correspondence between pairs of send/receive actions. This correspondence ensures that, in a system behaving as the parallel composition of the three local types, no role ever gets stuck or receives an unexpected message.111Session types also accompany labels with payloads of type String, Int, higher-order, etc. We omit these details in our presentation as they are not relevant to subtyping.
A fundamental problem in the application of session types is checking whether the implementation of one component in a distributed system can be substituted for another, without compromising safety of the overarching protocol. This problem can be addressed at the level of types and formulated as session subtyping [13, 21, 25, 26, 27]. Session subtyping establishes a preorder relation on local types: is a subtype of , written , if a program with type can be safely substituted by a program with type . Specifically, given a safe protocol , ensures that is also safe. For example, consider the variant of given earlier. With respect to , has: (1) less send options (initially it can only select next, and after receiving one feed it can only select stop), (2) more receive options (the additional option ). This notion of substitutability is covariant on send actions and contravariant on receive actions [25]. In fact, one can verify , which ensures that if is safe then so is .
Asynchronous session types are particularly interesting due to the use of FIFO channels in distributed systems and languages such as Go and Rust. When considering asynchronous session types, channels are unidirectional and unbounded (hence two are used for each pair of roles, one in each direction). For example, the asynchronous protocol behaves as the parallel composition of 3 roles communicating over 6 unidirectional channels, where a send action enqueues a message to a channel and a receive action dequeues it.
Establishing whether subtyping holds is non-trivial, especially when communication is asynchronous. Recent work [27] has provided, for the first time, a sound and complete definition of Multiparty Asynchronous session Subtyping (MAS). This definition of session subtyping is sound and complete in the sense that it precisely capture only and all the safety-preserving modification one can perform on a local type. Besides co- and contra-variance, MAS enables some actions to be swapped, reflecting the asynchronous nature of interaction. MAS allows two kinds of swapping:
- SW1
-
a role can anticipate an output action with respect to an input action;
- SW2
-
a role can swap actions of the same directions from/to different roles.
Below, is a variant of where the client anticipates the end-of-session request before the processing of the feed . This swap may be desirable to allow the client to process the feed from its own local queue at a later stage, and is allowed by SW1. is a variant of where the send actions and have been swapped, which is allowed by SW2. Indeed and .
This flexibility comes at a price: for interactions over unbounded channels MAS is undecidable [7, 35]. The subtyping problem can be viewed as a simulation game between the candidate subtype and the supertype, in which supertype is required to mirror any action performed by the candidate subtype. Consider checking whether is a subtype of where:
The client requests feeds at double the pace of its own feed processing time. It is actually the case that according to asynchronous subtyping [7, 27]. However to verify , one needs to show that can follow the actions of , albeit with send actions being delayed. Due to unbounded channel size, an unbounded number of input actions (the feed processing) can be deferred, yielding an infinite space of possible interleavings.
Sound algorithms have emerged which aim to establish subtyping in practical scenarios. Most of these algorithms are limited to binary sessions (only two roles) and follow the definition of binary subtyping in [13]. The definition in [13] is operational in nature, based on simulation trees, which makes it relatively straightforward to translate it into a practical subtyping algorithm [3, 6]. Unlike the binary case [13], the multiparty definition of MAS in [27] is declarative. While MAS concisely expresses an intrinsically complex problem, it is also highly non-intuitive. Therefore, it is unrealistic to expect a developer to be able to check the correctness of their code substitutions using the definition directly (beside the fact that the problem is undecidable). MAS can only be practically used if a test for subtyping can be automated, and since the problem is undecidable, the solution will necessarily entail approximation. This paper has exactly this purpose: automation of MAS. Automation still raises the question “how can one trust the algorithm?” Our paper also answers this: our black-box (automatically) generates a certificate which can be, if needed, further checked off with a proof assistant [23].
In this introduction, to clarify the purpose of our work, we have provided an overview of the problem space, and hinted at the underlying asynchronous communication model and the notion of safety that subtyping preserves. However, these details are neither needed nor used in the technical development which follows, since our work builds entirely on the declarative definition of MAS [27] that elegantly abstracts over the communication model.
1.1 Challenges and contributions
The undecidability of MAS is unfortunate, as safety-preserving substitutions are most valuable in the asynchronous setting to check the validity of performance optimisations, namely sending messages earlier or postponing receives [38]. A MAS subtyping checker would encourage developers to experiment with communication structures, providing a litmus test for checking the correctness of an optimisation. While polynomial checking algorithms do exist [36], they do not support optimisation even for the simpler binary case. A potential solution lies in abstract interpretation, previously applied to binary subtyping, where sets of words model asynchronicity [3]. This addresses undecidability with systematic (lattice-theoretic) approximation. To apply abstract interpretation to multiparty interaction, we reformulate MAS as subtyping on sets of session trees, and make the following contributions:
-
We introduce an equivalent but more tractable formulation of MAS [27], based on a new lite refinement preorder. MAS [27] is defined using nested quantification over infinite structures. One of the challenges of checking MAS is that it requires a check for inclusion of the actions being postponed over infinite structures. Lite refinement provides a way to automation by reducing the inclusion check to a simple, local check.
-
Abstraction has been applied to binary subtyping by adapting subtyping to sets of words and then representing these sets with regular expressions [3]. MAS is formulated in terms of session trees, and likewise we generalise subtyping to sets of session trees. To derive continuations after performing an action, we adapt the Brzozowski derivative [10] from regular expressions to session trees, and further extend it to sets of session trees. This provides a semantic foundation for subtyping, similar to a collecting semantics [17], ready for abstract interpretation and the deployment of an abstract domain.
-
We provide a new abstract domain for representing sets of session trees based on type graphs [43] and provide new domain operations for send and receive. Since the abstract domain is not finite, we show how widening can be applied to derive a terminating MAS algorithm founded on lite refinement.
Overall, we show how the theoretical formulation of MAS [27] can be distilled into an algorithm for checking subtyping. Moreover, our algorithm yields a certificate (enabling subtyping to be double-checked by a third-party without consideration of low-level algorithmic details). We complement our theoretical contribution by evaluating our algorithm on some challenging problems and show it can prove subtyping more often than existing methods, whilst being an order of magnitude faster than the state-of-the-art binary algorithm [3].
2 Preliminaries
2.1 Syntax
Let denote a finite set of roles and denote a finite alphabet of communication labels. Let , and . The syntactic category of session types, , is inductively defined by:
where is drawn from the category of (finite) index sets . Session type is for selection/send: the role selects one label in , sends it to role , and continues as the corresponding . Session type is a branching/receive action, where the role receives a label from . is for termination, for recursion, and is a type variable used for recursive call.
Asynchronous multiparty subtyping [27] is based on a co-inductive representation of session types called session trees. The category for session trees is defined co-inductively below. Subtyping is defined using three sub-classes of session trees called single-output (SO) trees , single-input (SI) trees , and single-input-single-output (SISO) trees , also defined co-inductively below:
We let , , , and denote typical members , , , and , respectively.
If a sequence contains the action where , we write . Given the sets , and we define the mapping where . Given a set of actions and a sequence of actions , we define and .
2.2 MAS: a declarative definition
MAS [27] is formulated in terms of two classes of sequence of actions, and , which are parameterised by a participant . Classes and embed the principles of swapability encoded into MAS. These finite sequences are inductively defined as follows:
Definition 1 (Finite sequences).
and where and .
defines the sequences of actions that can be anticipated before a receive action from (namely any receive action that is not from ), whereas defines the sequences of actions that can be anticipated before a send action to (namely any receive action – outputs can always be done before inputs – and any send action that is not to ). Note in particular that and . Using and , we can now define refinement for SISO trees:
Definition 2 (SISO refinement).
The refinement relation for SISO-trees is co-inductively defined as below, where and :
Example 3.
Since is the largest relation which is closed backwards under these rules it follows holds as well as . To see observe therefore if then holds too. Thus is applicable. Rule is not violated since hence no rule is contradicted.
Example 4.
Let denote the infinite sequence of actions and consider the following SISO trees: and . Observe that cannot be derived by since does not start with or since does not contain .
SISO-tree refinement provides an elegant vehicle for expressing swapability over the sequences of actions. However, a session type is not a sequence of actions, but rather a tree with selection and branching points. Definition 5 decomposes session trees in sets of SI- and SO- trees so as to express the co- and contra-variance of selection and branching.
Definition 5 (SO- and SI-tree decomposition for session trees).
The tree decomposition maps and are defined:
The intuition is that SO-tree decomposition removes the selection points in a session tree and expresses them using sets of single-output sequences, and dually for SI-trees. The maps and lift to a set of session trees by, respectively, and .
Example 6.
where .
Multiparty Asynchronous Subtyping (MAS) is formally defined as a binary relation on session trees in a forall-exists construction. Covariance and contravariance are encoded as a forall requirement on the SO-trees (resp. SI-trees) of the subtype (resp. supertype). The problem is then reduced to checking SISO-tree refinement:
Definition 7 (MAS).
The binary relation on is defined by holds iff .
Example 8.
To illustrate MAS, consider showing where and . Since is an SO-tree, . is not an SI-tree hence . Universal quantification over requires that is checked against both and . To do so, note and likewise and since
3 Lite SISO-tree refinement
To develop a subtyping algorithm we introduce a novel form of SISO-refinement on , called lite SISO-tree refinement, that is equivalent to classical SISO-refinement but is more attractive computationally. Lite refinement builds on the observation that the equality checks and in the premises and of classical SISO-refinement can be relaxed to inclusion checks and without enlarging the refinement relation. Furthermore, the inclusions can be further relaxed to lightweight checks and involving only the single actions and where denotes head:
Definition 9.
The lite refinement relation on SISO-trees is co-inductively defined as:
where and with , and as in Definition 2.
Corollary 10.
iff .
In the sequel, we develop a subtyping algorithm, based on , the correctness of which follows from the equivalence asserted by Corollary 10.
4 Subtyping Sets of Session Trees
Reasoning on sets of session trees paves the way for abstract interpretation [17] to be applied, where an algorithm is obtained by representing sets of session trees using an abstract domain constructed from type graphs [32]. Let to faciliate the following generalisaton of classical subtyping [27] to sets of session trees:
Definition 11.
The binary relation is defined holds iff and : : : : .
The section builds towards a subtyping relation on sets of subtrees, given in Figure 1, that provides a basis for abstract interpretation. Subtyping is defined in terms two notions of derivative: one for receive actions (Definition 16) and one for send actions (Definition 17). These operations scan a session tree from its root for a specific action, and return the session trees obtained by removing that action and any sub-trees that do not include it. These operations are inspired by the Brzozowski derivative [10] of a regular expression wrt to a symbol : if represents a set of words , the derivative represents . Our derivatives, presented in Sections 4.1 and 4.2, generalise the Brzozowski derivative to operate on (sets of) session trees rather than (sets of) words. Section 4.3 formulates subtyping using the derivatives. The subtyping relation is defined co-inductively, each deduction reading the action at the head of the subtype to apply either the send or receive derivative to the supertype. Our approach is justified by lite refinement.
4.1 Receive derivative of a session tree
Derivatives differ depending on whether they look for receive or send actions. A receive derivative is calculated using a depth bound derived using the predicate:
Definition 12.
The predicate is inductively defined as follows:
Furthermore holds iff there exists such that holds.
Example 13.
Let and . Since and then . However, does not hold () since is defined inductively.
Lemma 14 asserts that the absence of a bound implies the absence of subtyping. Lemma 15 asserts that there exists at most one for which holds. The receive derivative, which follows, is then defined in terms of the bound.
Lemma 14.
If and then .
Lemma 15.
If , and then .
Definition 16 (Receive derivative).
The receive derivative map is defined as , where the derivative relation for some is inductively defined:
Following MAS, a receive action from can only be found immediately (first rule) or after other receive actions from other roles (second rule). The second rule can be applied non-deterministically for any and derives at least distinct derivatives (which returns as a set). We write for the concatenation of , the action preceding , with a subtree that was the continuation of in that path. The receive derivative is well-defined because there exists at most one such that holds.
4.2 Send derivative of a session tree
Unfortunately, Lemma 14 does not help us define a send derivative on supertypes as we no longer rely on a known bound . Hence, the definition of is parametric in .
Definition 17 (Send derivative).
The -th order send derivative map is defined as
and the derivative relation is, itself, inductively defined by:
The -th derivative is defined to be the set of derivatives for which , the degree is maximal and . If for all then the -th derivative is itself null. Following MAS, in a supertype, a send action can be found immediately (first rule), after receive actions (e.g., the subtype may have anticipated the output), or after other send actions from different roles (third rule). Condition maximal means: . The third rule derives at least one derivative equipped with branches , where the are again selected to maximise their degree .
Example 18 (Derivatives).
Let . The receive derivative exists because both branches of possess a receive action . Indeed holds, hence . Now consider . For , the send derivatives = . Yet for , . In this case, does not need to occur in all branches of for the derivative to exist.
4.3 Subtyping with receive and send derivatives
To apply one derivative after another in a chain of actions, receive and send derivatives are lifted to operators on sets of supertypes as follows:
Definition 19.
The operators and are defined:
The use of in reflects covariance over sends: the action of the subtype must be supported by all session-trees . Conversely, the use of in models contravariance over receives: the of the subtype does not need to be found in all .
Definition 20.
Given a partial map , the update and accumulate operations are respectively defined:
-
-
where
Definition 21 (Subtyping on sets of session trees).
The ternary subtyping relation is co-inductively defined by the rules of Figure 1.
The ternary subtyping relation is defined using an environment , a partial map , that records the actions performed by before is encountered again as a sub-tree. This device assumes that session trees are regular [40, Section 21.7.2] (aka rational [16]). is regular iff its set of distinct subtrees, , is finite. This is not limiting since session types correspond to regular session trees. The premises of and are partitioned by the dotted lines into: (bottom) requirements based on the syntax of the subtype that decompose the problem onto sub-problems of the form and ensure a progress condition, and (top) subtyping requirements based on derivatives. In both rules, the premise stipulates that the actions at the head of must be performed within one cycle of , that is, before is revisited while traversing the subtype. This progress condition [15] ensures that a head action of is not postponed indefinitely.222 Binary subtyping [3, 5, 6, 13] makes use of a check that tests for cycles of send actions in the candidate subtype. We reframed these checks here as a more intuitive and simple progress condition, which amounts to no more than a set inclusion test that discharges a requirement on swapability.
Rule lifts and of lite refinement (Definition 9) to sets of session trees. The first premise of (top) is a coverage condition which ensures that for every a receive derivative is defined for least one . This guarantees that the selection of receive actions offered by cover those occurring in .
Rule lifts and (Definition 9) to session trees by applying the send derivative. Note permits a relaxation to be used for ; likewise a superset is used for in . Observe is not fixed upfront: it can vary with .
Theorem 22.
If is regular, and then .
Example 23 (Violated progress condition).
Consider and the subtyping problem where and . Observe that if then hence is finite which presents a contradiction therefore . Likewise as is demonsrated below:
In the first application of , = and for all . In the second, but thus is a singleton. The development cannot be progressed since , in effect, detecting that is an orphan.
Example 24 (Satisfied progress conditions).
To illustrate where a message is postponed, but is not orphan, consider the question where and :
To show , it is sufficient to put since . To establish the second, it is necessary to use because but . To show the fourth, is needed, illustrating that it is not sufficient to fix throughout. Notice too that is first revisited when attempting to establish the the fourth judgement. Its environment includes and hence the environment (orphan) premise is satisfied, and the development continues.
5 Subtyping sets of session trees using type graphs
Type graphs [32, Section 4.1.2] were proposed for representing (possibly infinite) sets of finite trees. We adapt them to represent (possibly infinite) sets of session trees by inductively defining the category of type graphs to be: . Thus the leaves of a type graph are session trees drawn from . A type graph is interpreted by a concretisation map [17] which describes the set of session trees it represents.
|
|
|
|
|
|
Definition 25 (Concretisation map).
The concretisation map is defined as the least solution to the following equations:
Example 26.
Consider (co-inductively) defined by and the type graph where is (inductively) defined by . and are illustrated in Figure 2 (i) and (ii) as regular trees where the terminal symbols distinguish from . If and then . Observe that has a finite representation even though is infinite.
Concretisation induces a preorder on by iff . The preorder may possess a bottom element but admits infinite ascending chains, as shown below:
Example 27.
Define and . Observe but for all . Nevertheless the chain has an upper bound: of Example 26 since for all .
As we shall see, calculating the upper bound of a sequence of type graphs is key to finitely computing a co-inductive proof. Such an upper bound can classically [17] be found with a widening operator . Widening provides a way to finitely derive an upper bound: given any increasing sequence the (widened) sequence defined by and is a sequence which is ultimately stable with a limit . Widening is required [17] to be monotonic in both arguments: and . Then the limit is an upper bound of the whole sequence, that is, for all .
Example 28.
Type graphs can be widened [43] by introducing back-arcs to curb growth and thereby induce stability. To provide some intuition, consider widening the type graph given in Figure 2(iii). Widening is achieved by repeatedly introducing cycles into the type graph by replacing a sub-tree with a back-arc to an ancestor. To illustrate, is transformed into , see Figure 2(iv), by replacing the sub-tree with a back-arc to an ancestor. Observe . Moreover, the deepest of has a direct ancestor which is disjunctive and has as a child. This triggers the introduction of another back-arc which finally yields , see Figure 2(ii). Again . The widening algorithm of [43] guarantees [43, Theorem 7.1] that a widened sequence is ultimately stable, while attempting to minimise the introduction of cycles. The widening of [43] will terminate with , though a more aggressive widening would also replace the deepest of with a back-arc to the root.
5.1 An abstract domain for sets of session trees
Operations on type graphs can be designed to mimic those on sets of session trees. In particular, to faithfully mimic the derivatives, it is both necessary to detect the absence of a derivative and preserve the derivation in a relaxation. The following definition formulates these requires and the proposition shows how they can be satisfied by lifting and :
Definition 29.
An abstract send derivative is any operator such that:
-
if then
-
for all . An abstract receive derivative is specified analogously.
Proposition 30.
The
operator is an
abstract send derivative where:
with additional rules for
and
that follow
Definition 17.
An abstract receive derivative can also be constructed using an environment .
Example 31.
|
|
|
|
|
An algorithm for checking subtyping follows from Figure 1 by substituting with and with ; thus operations on sets of session trees are simulated with operations on type graphs. We provide insight by first showing how widening can be applied to type graphs to create a co-inductive proof of subtyping, for a subtype that is linearly recursive.
Example 32.
To illustrate our strategy, consider where and . For brevity, define , , and thus . Suppose and for all where
Observe constitutes an increasing sequence, albeit one that is possibility infinite. Repeating the construction with , however, yields a sequence which is ultimately stable, that contains its limit . Because it follows . An infinite co-inductive derivation can then be assembled by repeating the derivation on the right (since and support relaxation). Figure 3 illustrates , , , and whereas Figure 4 gives the widened sequence which has as its limit. Altogether this shows . Note that constitutes a certificate. Finally observe that existence of , hence an infinite co-inductive derivation, follows by widening, which was originally conceived [17] as a device for enforcing termination.
|
|
|
|
5.2 Subtyping algorithm for type graphs
Example 32 illustrates how widening can be applied to establish the existence of an infinite co-inductive proof for . Algorithm 1 outlines an algorithm, which applies the same strategy for proving , but is applicable when is not linearly recursive. The key caveat for our algorithm is that is regular. This ensures is finite. It follows there exists a finite set such that every cycle of crosses at least one sub-tree of . ( is inspired by the idea of widening points which are program locations [4] where widening is applied.)
Example 33.
Continuing Example 32, observe and the only cycle of crosses each sub-tree of . Thus put , though other choices are possible.
In addition to , which is fixed throughout, our subtyping algorithm has a worklist and a partial map as parameters. mirrors the strategy used Example 32 which associates each sub-tree of with its own type graph. The algorithm is primed with where and (recall ). The algorithm exits successfully at line (2) returning the certificate , and otherwise throws an exception at (8), (9), (14) or (15) indicating an inconclusive verdict. The body of Subtyping removes the first pair from the worklist (if not empty), and checks whether the action at the root of is a receive, a send, or an . In the latter case, if then rule of Figure 1 holds and processing continues, otherwise an exception is thrown.
If is a receive, the progress condition of is checked at (8). The coverage condition at (9) can be decided without recourse to by an auxiliary predicate defined thus: , and if . Then holds iff . Line (9) also checks . If these checks are passed, is relaxed to by updating on the keys . If the sub-tree then widening is triggered and . It follows and , both assuring soundness while ensuring that cannot be relaxed ad infinitum. If then = , again yielding a sound relaxation. Widening at is enough to ensure is ultimately stable across all keys [4]: thus after a finite number of updates.
To demonstrate holds it remains to show for all . This is achieved by the list comprehension at (11) which extends the worklist with the pair for each providing the pair actually needs to be considered, that is, if or . Subtyping then reduces to invoking . Observe on any subsequent visit to , and eventually by virtue of widening. Termination thus follows.
The case for send on lines (14)–(18) is arguably simpler since does not need to be computed and coverage does not need to be checked.
6 Implementation
To assess practicality, we have implemented the Subtype algorithm in Scala 3.1.0 in 5800 LOC. Our implementation makes substantial use of immutable data-structure and parser combinator libraries [28] to reconstruct the type graph operations of [32] and the widening of [43]. As well as the derivatives, our codebase provides a visualiser for type graphs which outputs tikz.
We tested our algorithm on 12 binary and 12 multiparty problems, as detailed in Table 1. The problem trickySub < trickySup is taken from Example 24 whereas all other problems are drawn from (or inspired by) existing literature. The binary benchmarks include 8 which possess “complex accumulation patterns” [6] which is a catch-all term for communication patterns which defy heuristic methods [6]. The remaining 4 problems were chosen by size.
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Our algorithm was able to automatically prove subtyping for all problems, strictly improving on [3, 6] for the binary problems and [18] for the multiparty problems. Our algorithm was also able to establishing subtyping for all the remaining 74 binary problems in the benchmark suite of [6]. The strict improvement over the binary algorithm of [3] occurs because the string widening of [14] deployed in [3], imposes a restriction on the syntactic form of consecutive regular sub-expressions, whereas the particular widening developed for type graphs [42] used in the present work has no such limitation. However, Figure 5 depicts a binary problem, doubleb1 < doubleb2, delibrately crafted in response to the reviewers, to subvert the type graph widening of [42]. This example shows that the algorithm is incomplete.
Surprisingly, calculating the send derivatives with was sufficient for all but one problem, trickySub < trickySup, which was crafted to be difficult. The column records how many times the map is updated, which governs complexity. Timings are presented as parse+analysis time and were taken on a 32 GB laptop equipped with a 2.8GHz i7 processor. The zero times are runs beneath the granularity of the clock. The slowest runtime was 1+75=76ms, whereas the subtyping tool of [3], takes 1,757ms worse-case for the binary benchmarks (on the same machine), which suggests that performance-wise, multiparty subtyping is no worse than binary subtyping if carefully designed. All certificates are available at https://www.cs.kent.ac.uk/people/staff/amk/certificates.zip.
7 Related Work
|
|
|
The undecidability of asynchronous subtyping [7, 35] has given rise to a rich line of research aimed at finding sound algorithms. The first work [8] to explore the boundaries of undecidability, showed that synchronous subtyping can be generalised to -bounded asynchronous subtyping [8], where input accumulation depth is bounded by ( is synchronous subtyping). With fixed, -bounded asynchronous subtyping is sound and decidable (though the existence of such a is undecidable [8]).
Asynchronous (binary) approaches include the seminal algorithm from [5, 6] for binary sessions and [3], which uses word approximation [14] to enlarge the class of problems for which asynchronous subtyping can be algorithmically established. The extension from the binary setting to multiparty is not obvious. For example, swapping two send actions or two receive actions (to encode SW2) is not safe in the binary setting: it violates the FIFO ordering of messages, potentially causing communication mismatches (e.g., ) or deadlocks (e.g., ). The multiparty setting adds more interleaving options to handle and requires more machinery to keep track of the actions-role association.
As to multiparty asynchronous subtyping, the algorithm in [18], while applicable to several realistic protocols, does not address “complex accumulation patterns" [6] that can be, instead, handled by the tools of [3, 6]. MAS [27] has been mechanized [23] providing a sound and complete tool for verifying subtyping given a hand-crafted certificate as input, but provides no solution to the fundamental problem of how to compute a certificate.
Interest in subtyping seems to be increasing rather than abating and another approach to asynchronous multiparty subtyping [36], based on projecting global types (a global model of a collection of local types), was proposed in parallel to [3] at a sister conference. The global types in [36] provide richer select and branching primitives with respect to classic global types: in a given state, a sender can select to send a message to different receivers, and likewise a receives can wait on different senders. A central requirement of multiparty subtyping in [36] is sub-protocol fidelity [36, Definition 5.1(i)] which ensures that any refinement (subtype) is consistent with a given global type. Sub-protocol fidelity yields a very different notion of subtyping to the one adopted here (and [5, 6, 12, 13] and formalised as MAS [27]). Sub-protocol fidelity allows some actions to be swapped, but it does not allow the anticipation of outputs before inputs, which is a requirement for performance optimisation [38]. This means that a session type may be a subtype of another according to our algorithm (and MAS), but not that of [36]. Thus it is no paradox when the authors of [36] claim decidability while pointing out that asynchronous subtyping is undecidable [7, 35]. Classically, the subtyping question is answered pairwise: by comparing a type against a candidate subtype, without reference to a global type. This formulation is favourable when the global type is unknown, for instance, if types are mined from source code.
Session subtyping is related to compliance between session contracts [1], which is inspired by testing-preorders [19]. Must-testing, in the binary and synchronous setting, can be seen as a sort of inductive compliance relation [39]. Multiparty synchronous must-testing has been studied in [20], binary asynchronous in [2]. Another interesting preorder is fair subtyping [9], which takes its cues from should testing preorder [41], and preserves the possibility of correct termination. Difference nuances of session subtyping, such as those mentioned above, suggest the need of generic subtyping algorithms, parameterised by the underlying preorder.
8 Conclusion
The application of abstract interpretation to asynchronous session subtyping is challenging in the multiparty setting. To provide a semantic basis for abstraction, an alternative notion of SISO-tree refinement is given, and as well as new notions of derivative which, together, enables the MAS subtyping relation to be re-expressed over sets of session-trees. This provides a foundation for abstract interpretation, akin to a classical collecting semantics, whose use is illustrated with a new abstract domain for session trees, constructed from type graphs, that were originally proposed for type recovery. Overall, we provide the first algorithmic formulation of MAS together with experimental results which are truly encouraging.
References
- [1] Franco Barbanera and Ugo de’Liguoro. Sub-behaviour relations for session-based client/server systems. Mathematical Structures in Computer Science, 25(6):1339–1381, 2015. doi:10.1017/S096012951400005X.
- [2] Giovanni Bernardi, Ilaria Castellani, Paul Laforgue, and Léo Stefanesco. Constructive Characterisations of the MUST-preorder for Asynchrony. In European Symposium on Programming, volume 15694 of Lecture Notes in Computer Science, pages 88–116, 2025. doi:10.1007/978-3-031-91118-7_4.
- [3] Laura Bocchi, Andy King, and Maurizio Murgia. Asynchronous Subtyping by Trace Relaxation. In Tools and Algorithms for the Construction and Analysis of Systems, volume 14570 of Lecture Notes in Computer Science, pages 207–226, Berlin, 2024. Springer-Verlag. doi:10.1007/978-3-031-57246-3_12.
- [4] François Bourdoncle. Efficient Chaotic Iteration Strategies with Widenings. In Formal Methods in Programming and Their Applications, volume 735 of Lecture Notes in Computer Science, pages 128–141, New York, 1993. Springer-Verlag. doi:10.1007/BFb0039704.
- [5] Mario Bravetti, Marco Carbone, Julien Lange, Nobuko Yoshida, and Gianluigi Zavattaro. A Sound Algorithm for Asychronous Session Subtyping. In International Conference on Concurrency Theory, volume 140 of LIPIcs, pages 38:1–38:16, Dagstuhl, 2019. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.CONCUR.2019.38.
- [6] Mario Bravetti, Marco Carbone, Julien Lange, Nobuko Yoshida, and Gianluigi Zavattaro. A Sound Algorithm for Asychronous Session Subtyping and its Implementation. Logical Methods in Computer Science, 17(1):1–35, 2021. doi:10.23638/LMCS-17(1:20)2021.
- [7] Mario Bravetti, Marco Carbone, and Gianluigi Zavattaro. Undecidability of Asynchronous Session Subtyping. Information and Computation, 256:300–320, 2017. doi:10.1016/j.ic.2017.07.010.
- [8] Mario Bravetti, Marco Carbone, and Gianluigi Zavattaro. On the Boundary between Decidability and Undecidability of Asynchronous Session Subtyping. Theoretical Computer Science, 722:19–51, 2018. doi:10.1016/j.tcs.2018.02.010.
- [9] Mario Bravetti, Julien Lange, and Gianluigi Zavattaro. Fair Asynchronous Session Subtyping. Logical Methods in Computer Science, 20:5:1–5:47, 2024. doi:10.48550/arXiv.2101.08181.
- [10] Janusz Brzozowski. Derivatives of Regular Expressions. Journal of the ACM, 11(4):481–494, 1964. doi:10.1145/321239.321249.
- [11] David Castro-Perez and Nobuko Yoshida. CAMP: cost-aware multiparty session protocols. Proc. ACM Program. Lang., 4(OOPSLA):155:1–155:30, 2020. doi:10.1145/3428223.
- [12] Tzu-Chun Chen, Mariangiola Dezani-Ciancaglini, Alceste Scalas, and Nobuko Yoshida. On the Preciseness of Subtyping in Session Types. Logical Methods in Computer Science, 13(2):1–61, 2017. doi:10.23638/LMCS-13(2:12)2017.
- [13] Tzu-Chun Chen, Mariangiola Dezani-Ciancaglini, and Nobuko Yoshida. On the Preciseness of Subtyping in Session Types. In Principles and Practice of Declarative Programming, pages 135–146, New York, 2014. ACM Press. doi:10.1145/2643135.2643138.
- [14] Tae-Hyoung Choi, Oukseh Lee, Hyunha Kim, and Kyung-Goo Doh. A Practical String Analyzer by the Widening Approach. In Asian Symposium on Programming and Systems, volume 4279 of Lecture Notes in Computer Science, pages 374–388, Berlin, 2006. Springer-Verlag. doi:10.1007/11924661_23.
- [15] Liron Cohen. Non-well-founded Deduction for Induction and Coinduction. In Conference on Automated Deduction, volume 12699 of Lecture Notes in Computer Science, pages 3–24. Springer-Verlag, 2021. doi:10.1007/978-3-030-79876-5_1.
- [16] Bruno Courcelle. Fundamental Properties of Infinite Trees. Theoretical Computer Science, 25:95–169, 1983. doi:10.1016/0304-3975(83)90059-2.
- [17] Patrick Cousot and Radhia Cousot. Abstract Interpretation: A Unified Lattice Model for Static Analysis of Programs by Construction or Approximation of Fixpoints. In Principles of Programming Languages, pages 238–252, New York, 1977. ACM Press. doi:10.1145/512950.512973.
- [18] Zak Cutner, Nobuko Yoshida, and Martin Vassor. Deadlock-Free Asynchronous Message Reordering in Rust with Multiparty Session Types. In Symposium on Principles and Practice of Parallel Programming, pages 246–261, New York, 2022. ACM Press. doi:10.1145/3503221.3508404.
- [19] Rocco De Nicola and Matthew Hennessy. Testing Equivalences for Processes. Theoretical Computer Science, 34:83–133, 1984. doi:10.1007/BFb0036936.
- [20] Rocco De Nicola and Hernán Melgratti. Multiparty Testing Preorders. Logical Methods in Computer Science, 19:1:1–1:31, 2016. doi:10.46298/lmcs-19(1:1)2023.
- [21] Romain Demangeon and Kohei Honda. Full Abstraction in a Subtyped pi-Calculus with Linear Types. In International Conference on Concurrency Theory, volume 6901 of Lecture Notes in Computer Science, pages 280–296, Berlin, 2011. Springer-Verlag. doi:10.1007/978-3-642-23217-6_19.
- [22] Romain Demangeon, Kohei Honda, Raymond Hu, Rumyana Neykova, and Nobuko Yoshida. Practical interruptible conversations: distributed dynamic verification with multiparty session types and Python. Formal Methods in Systems Design, 46(3):197–225, 2015. doi:10.1007/s10703-014-0218-8.
- [23] Burak Ekici and Nobuko Yoshida. Completeness of asynchronous session tree subtyping in coq. In Yves Bertot, Temur Kutsia, and Michael Norrish, editors, International Conference on Interactive Theorem Proving, volume 309 of LIPIcs, pages 13:1–13:20. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPICS.ITP.2024.13.
- [24] Simon Fowler. An Erlang Implementation of Multiparty Session Actors. In Interaction and Concurrency Experience, volume 223 of EPTCS, pages 36–50, 2016. doi:10.4204/EPTCS.223.3.
- [25] Simon Gay and Malcolm Hole. Types and Subtypes for Client-Server Interactions. In European Symposium on Programming, volume 1576 of Lecture Notes in Computer Science, pages 74–90, Berlin, 1999. Springer-Verlag. doi:10.1007/3-540-49099-X_6.
- [26] Simon Gay and Malcolm Hole. Subtyping for Session Types in the Pi Calculus. Acta Informatica, 42:191–225, 2005. doi:10.1007/s00236-005-0177-z.
- [27] Silvia Ghilezan, Jovanka Pantovic, Ivan Prokic, Alceste Scalas, and Nobuko Yoshida. Precise Subtyping for Asynchronous Multiparty Sessions. Proc. ACM Program. Lang., 5(POPL):1–28, 2021. doi:10.1145/3434297.
- [28] Steve Hill. Combinators for Parsing Expressions. Journal of Functional Programming, 6(3):445–463, 1996. doi:10.1017/S0956796800001799.
- [29] Kohei Honda, Vasco T. Vasconcelos, and Makoto Kubo. Language Primitives and Type Disciplines for Structured Communication-based Programming. In European Symposium on Programming, volume 1381 of Lecture Notes in Computer Science, pages 22–138, Berlin, 1998. Springer-Verlag. doi:10.1007/BFb0053567.
- [30] Kohei Honda, Nobuko Yoshida, and Marco Carbone. Multiparty asynchronous session types. In Principles of Programming Languages, pages 273–284. ACM, 2008. doi:10.1145/1328438.1328472.
- [31] Raymond Hu, Nobuko Yoshida, and Kohei Honda. Session-Based Distributed Programming in Java. In European Conference on Object-Oriented Programming, volume 5142 of Lecture Notes in Computer Science, pages 516–541, Berlin, 2008. Springer-Verlag. doi:10.1007/978-3-540-70592-5_22.
- [32] Gerda Janssens and Maurice Bruynooghe. Deriving Descriptions of Possible Values of Program Variables by Means of Abstract Interpretation. Journal of Logic Programming, 13(2&3):205–258, 1992. doi:10.1016/0743-1066(92)90032-X.
- [33] Nicolas Lagaillardie, Rumyana Neykova, and Nobuko Yoshida. Stay Safe Under Panic: Affine Rust Programming with Multiparty Session Types. In European Conference on Object-Oriented Programming, volume 222, pages 4:1–4:29, Dagstuhl, 2022. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. doi:10.4230/LIPIcs.ECOOP.2022.4.
- [34] Julien Lange, Nicholas Ng, Bernardo Toninho, and Nobuko Yoshida. Fencing off Go: liveness and safety for channel-based programming. In Principles of Programming Languages, pages 748–761, 2017. doi:10.1145/3009837.3009847.
- [35] Julien Lange and Nobuko Yoshida. On the Undecidability of Asynchronous Session Subtyping. In Foundations of Software Science and Computation Structures, volume 10203 of Lecture Notes in Computer Science, pages 441–457, Berlin, 2017. Springer-Verlag. doi:10.1007/978-3-662-54458-7_26.
- [36] Elaine Li, Felix Stutz, and Thomas Wies. Deciding Subtyping for Asynchronous Multiparty Sessions. In European Symposium on Programming, volume 14576 of Lecture Notes in Computer Science, pages 176–205, Berlin, 2024. Springer-Verlag. doi:10.1007/978-3-031-57262-3_8.
- [37] Dimitris Mostrous and Vasco Vasconcelos. Session Typing for a Featherweight Erlang. In Coordination Models and Languages, Lecture Notes in Computer Science, pages 95–109, 2011. doi:10.1007/978-3-642-21464-6_7.
- [38] Dimitris Mostrous, Nobuko Yoshida, and Kohei Honda. Global Principal Typing in Partially Commutative Asynchronous Sessions. In European Symposium on Programming, volume 5502 of Lecture Notes in Computer Science, pages 316–332, Berlin, 2009. Springer-Verlag. doi:10.1007/978-3-642-00590-9_23.
- [39] Maurizio Murgia. A fixed-points based framework for compliance of behavioural contracts. J. Log. Algebraic Methods Program., 120:100641, 2021. doi:10.1016/j.jlamp.2021.100641.
- [40] Benjamin C. Pierce. Types and Programming Languages. MIT Press, 2002.
- [41] Arend Rensink and Walter Vogler. Fair testing. Information and Computation, 205(2):125–198, 2007. doi:10.1016/j.ic.2006.06.002.
- [42] Pascal Van Hentenryck, Agostino Cortesi, and Baudouin Le Charlier. Type Analysis of Prolog Using Type Graphs. In Programming Language Design and Implementation, pages 337–348. ACM Press, 1994. doi:10.1145/773473.178479.
- [43] Pascal Van Hentenryck, Agostino Cortesi, and Baudouin Le Charlier. Type Analysis of Prolog Using Type Graphs. Journal of Logic Programming, 22(3):179–209, 1995. doi:10.1016/0743-1066(94)00021-W.
