Safe reuse in modelling language engineering using model subtyping with OCL constraints

Low-code software development promises rapid delivery of software cloud applications by employing domain-specific languages (DSLs), requiring minimal traditional coding. Model-driven engineering (MDE) provides tools, modelling notations and practices suited for engineering such DSLs, both from a syntactic and semantic perspective. However, low-code software development is heavily reliant on software reuse. It is imperative to provide safe mechanisms that guarantee valid semantic reuse of structural components and their behaviour, most often in a stepwise manner. This article presents a semantic reuse technique based on model subtyping over metamodels to manage correct model-driven engineering of DSLs. Model subtyping is generalized to structural semantics by considering OCL constraints. Moreover, model subtyping is generalized to behavioural semantics by considering specifications of model transformation operations, which may encode operational or translational semantics. Model subtyping facilitates structural and behavioural refinement. It has been implemented atop a bounded model checker, realizing a semi-decidable procedure for verifying that DSL elements are safely reused. The algorithm finds semantic witnesses of inconsistencies when refinement principles are not satisfied, fostering a correct stepwise engineering of DSLs. Moreover, the algorithm produces an extension metamodel that permits the as-is reuse of implementations of model transformation operation specifications. Finally, the versatility of the model subtyping technique is illustrated with common use cases extracted from the research literature.


Introduction
Software reuse [1] is a recommended software engineering strategy that builds new systems on top of existing software artefacts. Such strategy is driven by a need to cope with increasingly complex software while lowering software development costs, shortening delivery times, and improving software quality. Low-code and no-code software development epitomizes current approaches to reuse-based software engineering [2], where software systems are designed using domain-specific languages (DSLs) so that they can readily be deployed on the cloud as a service, with little or no traditional coding required. Correct engineering of low-code Communicated by Romina Eramo, Benoit Combemale and Juan de Lara.
B Artur Boronat artur.boronat@leicester.ac.uk 1 School of Computing and Mathematical Sciences, University of Leicester, Leicester, UK platforms is critical to ensure the quality of the generated software applications.
The design principles and practices involved in low-code software development overlap greatly with those in modeldriven engineering (MDE) [3]. The structural semantics of domain-specific modelling languages is represented in terms of metamodel specifications, involving a metamodel and possibly additional constraints [4], and their behavioural semantics is represented by model transformation operations, like model interpreters and model compilers. As low-code development platforms become sophisticated, such metamodel specifications and model transformations grow complex and reuse techniques become vital for engineering them correctly. Specially when those reuse techniques come equipped with automated verification support.
A very general form of reuse emerges when we want to learn whether we can extrapolate model transformation operations from one metamodel specification to another one or when we want to engineer a model transformation based on an existing one. On the one hand, (i) when a model transfor-mation is to be applied to a different metamodel specification, whose metamodel and constraints need not be related a priori, involves learning whether the original and new metamodel specifications are compatible, capturing the notion of subtype polymorphism in model transformation operations. On the other hand, reusing model transformations to engineer new ones involves analysing how they are related. In particular, we can find two additional common use cases: (ii) when a model transformation can be safely reused across DSLs; and (iii) when the specification of a model transformation is refined stepwise, reusing and extending the original set of requirements. In all of these cases, appropriate automated verification mechanisms should be provided to ensure the safe reuse of model transformation operations. Specifically, we are interested in ensuring two types of safety properties (nothing bad can happen): invariants, which need to hold for all states (or execution configurations) of the interpreter, and behavioural requirements, which need to hold for all transformation steps.
Depending on how typing is considered [5], we can distinguish semantics where typing (the instanceOf relation) is ontological, explicitly definable in the metamodelling language, or linguistic, implicitly defined by the metamodelling language. In addition, we consider that the semantics of object subtyping corresponds to (static) subclassinggeneralization-in the first approach; and subsumption in the second approach. Hence, we distinguish approaches where models are represented as graphs, where typing is ontological; or as terms, where typing is linguistic. On the one hand, graph transformation theory and well-known (meta)modelling environments, such as the Eclipse Modelling Framework (EMF) and the USE environment [6,7], rely on the first representation, exploiting a set-theoretic representation to implement tools, e.g. for checking model typing and for analysing (OCL) constraints. On the other hand, type-theoretic approaches, such as [8,9], rely on the second representation for exploiting inductive reasoning and higher-order functions.
Our aim in this work is to revisit the research question of whether type subsumption-i.e. the relation capturing that any inhabitant of a given subtype is also an inhabitant of a given supertype-is a valid mechanism for facilitating reuse of model transformation operations in MDE in order to analyse its advantages and limitations. We approach this topic by tackling the three different reuse problems above in modelling language engineering, which we then solve by using structural and behavioural model subtyping. The following results have been developed to solve these reuse problems: (1) Extension of OO types, with multiple inheritance semantics [10], to model types with referential constraints, reusing a type-theoretic framework, with linguistic typ-ing and a convenient semantics for subtyping. Our model types formalize the common features of EMF metamodels, including classes with attributes, cross-references and containments, multiple inheritance, data types and enumeration types, multiplicity, ordering, uniqueness and bidirectionality constraints for cross-references and containments.
(2) Attachment of the USE semantics of OCL constraints [11], with ontological typing, to extended OO types in order to reuse tool support for mechanizing the satisfaction of OCL constraints in our model types. (3) Definition of a subtyping relation ≤: between metamodel specifications that couples extended OO subtyping, between the types in both metamodels, with the compatibility of their OCL constraints. This subtyping relation can be regarded as a structural refinement relation between metamodel specifications. The computation of the subtyping relation for two given metamodel specifications relies on the construction of an extension metamodel that reflects (linguistic) model subtyping using (ontological) subtyping, enabling reasoning about the compatibility of OCL constraints from both metamodel specifications. The extension metamodel also serves as the basis for reusing model transformation operations as-is, i.e. without introducing changes to the operation behaviour. (4) A semi-decidable procedure that solves the proposed problem by using structural model subtyping and its implementation in a tool, facilitating flexibility in MDE by supporting dynamic, partial and multiple typing.
This article is an extension of [12] where: (5) The subtyping relation has been generalized in Sect. 5.5 to behavioural specifications of model transformations, both syntactically and semantically, enabling (i) safe application of operations, (ii) substitutability of operations that satisfy the same set of requirements, and (iii) refinement of model transformation specifications. (6) A semi-decidable procedure in Sect. 5.5 implements the satisfiability of the subtyping relation, automatically verifying (i) application of model transformation operations, (ii) their substitutability, and (iii) stepwise refinement of transformation specifications. (7) Re-typing and type coercion mechanisms are explained in more detail using the EMF-Syncer [13] in Sect. 6.4. (8) A number of use cases in Sect. 7 illustrate the different possibilities of the subtyping relation, including structural and behavioural refinement, and multiple typing.
The structure of the rest of the article is as follows. In Sect. 2, we introduce an example and discuss approaches for model typing, focusing on accepted notions of model subtyping for EMF metamodels and graph transformation theory. In Sect. 3, the main approaches to model subtyping are introduced. In Sect. 4, syntactic representations for model types and structural model subtyping are introduced. In Sect. 5, we map a semantics of metamodels specifications to our model types and extend the subtyping relation to metamodel specifications and operation specifications. In Sect. 6, we present how the tool provides support for the theory developed. In Sect. 7, the subtyping relation is illustrated with additional use cases. In Sect. 8, we compare our approach to related work, finalizing the work with concluding remarks.

Running example
A low-code development platform usually builds atop a surface modelling language, with which a modeller designs a system in a particular domain. The language's abstract syntax is given as a metamodel, which may be enriched with constraints, specifying structural properties that need to be satisfied by its models. This metamodel specification [4], formed by a metamodel and its OCL constraints, characterizes the structural semantics of the DSL. Traditionally, the behavioural semantics of a DSL is either operational or translational. Operational semantics can be specified declaratively using in-place model transformations in a model interpreter, while translational semantics can be implemented using outplace model transformations in a model compiler.
In the following subsections, we develop a running example in which an abstract specification of a graph-based DSL for evaluating functions is reused, and refined, for engineering a simulator for state machines.

Reuse of structural requirements
The metamodel specifications (M g , g ) and (M sm , sm ), shown in Fig. 1, define modelling languages for abstract graphs and deterministic state machines, respectively. The model types described by both metamodels are structurally similar in that they both describe graphical forms. On the one hand, (M g , g ) characterizes the graph of a function defined over nodes, with the OCL constraint g . On the other hand, (M sm , sm ) characterizes state machines where transitions can be triggered by an event (indicated in the name attribute of the transition) or are triggerless, e.g. they are completion transitions. These metamodels also include notions for engineering the execution context of a model interpreter, namely the notions of Mark to mark nodes as already mapped in M g , and Observation to indicate which states have been observed in M sm . By showing that the abstract graph DSL is a subtype of the state machine DSL, the requirement that abstract graphs define maps can be reused in the context of state machines, where the requirement imposes determinism on the representable state machines. Furthermore, the subtyping operator also checks whether any additional constraints in the metamodel specification (M sm , sm ) are compatible with the constraints g , ensuring that (M sm , sm ) is a valid structural refinement of (M g , g ).
Our notion of subtyping can compare metamodels that are not related a priori by exploiting structural similarities. However, it is most effective when applied to metamodels with known similarities, say as a consequence of evolution, because those similarities are automatically inferred, easing the language engineer's reuse task.

Reuse of model transformation operations
To consider the behavioural semantics of DSLs, we are introducing an ATL transformation that defines a basic interpreter for evaluating functions defined according to the metamodel specification (M g , g ). The ATL transformation applies a function graph to a node, as shown in Listing 1. The interface of the interpreter is given in terms of the metamodel specification (M g , g ). By extending this interface with the metamodel specification (M sm , sm ) via the subtyping operator, the interpreter can be safely reused for state machines.   n1 and not e . source . mark . oclIsUndefined ()) ) to n2 : graph ! Node ( mark <-m ) , m : graph ! Mark ( graph <-n1 . graph , time <-graph ! Edge . allInstances () -> select ( e | e . target = n1 and not e . source . mark . oclIsUndefined ()) -> asSequence () -> first (). source . mark . time + 1 ) } Figure 2 shows one simulation step carried out with the ATL transformation applied to an initial state machine, with an observation of the initial state. The simulation step adds a marking on the successor state with a new timestamp. The marking is an instance of the class Mark as the ATL transformation has no awareness of the classifiers in the subtype model. Type coercion is used in the last step to down cast the resulting state machine to an instance of the subtype model, by retyping object 7 to the class Observation.

Stepwise refinement
In the previous reuse use case, the interpreter is defined using the metamodel specification (M g , g ) as its interface. Thereby, the interpreter is reused for (M sm , sm ) as a blackbox. As explained by Liskov and Wing [14], the subtyping operation only guarantees that the entire space of side effects of the interpreter function within (M sm , sm ) is also present within (M g , g ). That is, that no type errors occur. However, this type of reuse shows very little knowledge about the actual behaviour of the operation. In this section, the specification of the interpreter is refined, for an extension of the metamodel specification (M sm , sm ), with additional constraints that describe the actual behaviour of the simulator of state machines. Figure 3 shows a refined metamodel specification (M sm , sm ) (top) that includes temporal information via the association predecessor. In its metamodel, the classifier StateMachine corresponds to the snapshot notion, which contains a marker for the state currently being observed. In addition, each state machine may have one predecessor, representing the previous snapshot in the execution. The invariant (top, right) specifies the behavioural semantics of the interpretation model transformation in Listing 1 1 . Figure  3 shows the semantics of the model interpreter (bottom), consisting of two transformations, given an initial state machine 1 The specification does not mandate how successor snapshots are to be managed. An implementation may involve ATL rules, and the corresponding ATL engine selects how to process snapshots of the system. snapshot. Hence, by comparing metamodel specifications that contain behavioural semantics, the subtyping operation is also able to reason about behavioural properties of DSLs, both to reuse behavioural semantics and to ensure valid behavioural refinements. This example has been chosen to illustrate how the operation specification subtyping relation can be used to check refinement of model transformation operations. However, the operation specification subtyping relation is more general, as it does not require an initial snapshot to determine whether subtyping is satisfied.

Background on model subtyping
In the recent literature on model transformation, there is an emerging interest in formalizing mechanisms for reuse of model transformations [15][16][17]. Approaches to reuse transformation logic involve mechanisms to facilitate its application in different contexts (through typing) or by extending the logic itself (through transformation rule extension). We will focus on the first one, while laying the foundations for the second one, to study when it is safe to reuse a model transformation operation.
Regarding typing, working with models in MDE processes can be done at two levels of abstraction: a white-box approach (called intra-resource in [18]) where model internals are exposed so that side effects can be analysed as model transformations act upon models; and a more coarse (blackbox) approach (called inter-resource in [18]) where models are treated as first-order citizens in model transformation scenarios [3]. Depending on the desired level of rigour, the former may be regarded as a building block to enable a sound basis for the latter, i.e. by building model management systems based on safe model transformations. Refining this classification around the notion of intra-resource typing, we find approaches that build on a notion of model type, typically considering model subtyping or metamodel adaptation, out of which we are interested in subtyping only.
Model subtyping can be dealt with as a subsumption relation or as model type matching, by generalizing the  homologous notions in OO programming languages [19]. Steel et al. [20] proposed a type system with type groups in order to formalize the type of a metamodel. Substitutability in this type system is facilitated by a model type matching relation, which generalizes the matching relation on type groups presented in [21] to model types, where a model type M' matches a model type M, denoted M' <# M, iff for each class C in M, there is a class C in M' such that the signature of its operations is preserved 2 . The type system proposed relies on class names to match object types, which implies that the model type for state machines of Fig. 1 would not be considered a subtype of the model type for graphs without an explicit adaptation.
In [20], the authors argue that a name-independent structural type system is not able to capture classes with no contents that are solely used for adding structure to a concept taxonomy, e.g. by denoting final states in a state machine. From a design point of view, the use of empty classes may be helpful for modelling new concepts at an early stage in the development process. However, this may be considered a design smell for implementation purposes, as it violates the single-responsibility principle. In addition, there are alternative modelling techniques that permit skipping that case without losing expressive power. For example, one may consider clustering a hierarchy of empty children classes into the superclass by adding a segregative attribute (e.g. a Boolean attribute isFinal) or by designating different types of classes by using references (e.g. by using a reference finalStates from the class StateMachine to the class State).
Guy et al. improved this notion of subtyping as isomorphic model subtyping in [17] and introduced non-isomorphic model subtyping for enabling model adaptation utilizing renaming maps. Guy et al. [17] also discuss the notion of partial and total subtyping in order to facilitate the reuse of model transformations in practical scenarios. Partial model subtyping aims to enable the safe reuse of a model transformation even if only the part of the model type used in the model transformation is present. In this context, Sen et al. [22,23] conceptualized this situation as the notion of effective model type of a transformation: the minimal subset of the elements of the input metamodel that is used in the transformation.
Model transformations based on graph transformation theory rely on the theory of typed attributed graphs with type node inheritance [24,25]. Type checking in this theory is achieved by constructing a graph morphism between a graph (the model) and the type graph (the metamodel) that preserves the graph's structure. Model subtyping is supported in graph transformations employing the notion of abstract production rule where nodes in a graph pattern in the rule may correspond to abstract nodes (similar to an abstract superclass). From a theoretical point of view, given a graph and an abstract production rule that can be applied to it, it has been shown that a unique concrete production rule can be constructed so that the effects of the transformation on the graph are equivalent to the application of abstract production rule directly on the graph. Hence, the usual theory for typed attributed graph transformation can be applied for graph grammars with abstract production rules, with a notion of object subtyping. Using this theory, the type graphs representing the metamodels in Fig. 1 denote different types of graphs that are not related unless adaptation mechanisms are used explicitly.

Model types and subtyping
One of the contributions of this work consists in giving an interpretation to metamodels (and object-oriented models), where refinement extension is achieved by (static) subclassing, with model types where refinement is achieved by subtyping (subsumption). To distinguish both kinds of type representations, we are going to use M → to denote metamodels and M < to denote model type expressions. This distinction is necessary in order to consider OCL constraints in model types, as discussed in the following section.
In this section, we first introduce model type expressions M < for representing model types M < and, subsequently, define them. Then, we define a notion of model subtyping based on subsumption. In Sect. 5, we show how a metamodel M → is related to its model type expression M < .

Model type expressions
Models in software engineering have a dual interpretation, namely as "a related collection of instances of metaobjects, representing (describing or prescribing) an information system, or parts thereof, such as a software product or as semantics", or as "a semantically closed abstraction of a system or a complete description of a system from a particular perspective" [26]. That is, as syntax or as semantics [27]. Since metamodels are also models, we differentiate a metamodel from a model type by saying that a metamodel denotes a unique model type [28,29].
Our model types are used as classifiers of objects, and their operations are applied to models, even if they act on the internals of the model representation. For example, a model transformation may consist of a sequence of updates of property values or alter the structure of the model.
In [10], record types are used to model classes of objects, and thus object types, and union types define tagged values. That is, whereas an record type (name: String) denotes objects with a property name, a union type ] defines the type of those values that contain a single literal, defining an enumeration type. In the following, we extend the syntax for types presented in [10], by including referential types and by including notation both for the types themselves and for their name. The reason for this is to enable the definition of recursive structures through referential types.

PropSetType
: [] denotes the bottom type as the least informative type, Void denotes its name, () denotes the most general type, Any denotes its name, and τ → τ denotes the type of a function. Optional sentential forms are denoted with grouping parentheses and a question mark.
We will use the Boolean predicates isRef (ρ), isCmt(ρ), isOrdered(ρ) and isUnique(ρ) to check whether a property type expression is a cross-reference type expression or a containment reference type, whether it is ordered and whether it is unique, respectively. In addition, the projections c(ρ), lower(ρ), upper(ρ), and op(ρ) obtain the class name, the lower bound, the upper bound and the opposite property name (when present), respectively. In our approach, a model may consist of heterogeneous root objects. When considering models in a purely graphtheoretic sense, one needs to consider all classes as roots. The model type expression corresponding to the state machine metamodel of Figure1 has the root class name StateMachine and type is defined as follows:

Semantics of model type expressions
We borrow the semantic domain from [10], where V is the universal value domain of all computable values. We consider that V contains the set of typed object identifiers O and refer to object identifiers of objects that are instances of a particular class c as O c .
We refine the semantics for type expressions as model type expressions in order to consider referential types and the different types of constraints definable in a metamodel. The semantics of a referential type expression ρ of the form is given by the expression ρ r where r is an optional parameter referring to the record containing the field p. The expression ρ r is defined as follows: Also, there may be constraints regarding multiplicities, uniqueness and bidirectionality that restrict the corresponding referential types. Such constraints are encoded as follows: -For referential types, assuming we have a collection of identifiers ic (either a list or a bag), multiplicity constraints [n.
.m] are encoded as follows |ic| ≥ n ∧ (|ic| ≤ m ∨ |ic| = * ). The constraint is encoded likewise for containment types. -For referential types, assuming we have a collection of identifiers ic (either a list or a bag), the uniqueness constraint is encoded as follows |ic| = |set(ic)|, where set is the operator that extracts a set from a list or a bag by filtering out duplicates. The constraint is encoded likewise for containment types. -For referential types, when the parameter r in ρ r is present, the bidirectionality constraint p : For containment types, the constraint is encoded likewise, but we fetch the object identifier of the contained object by inspecting the field id.
For a property p : α defined in an object type ς , a full encoding of the semantics denoted by the expression α r , where r ∈ ς , can be obtained by enumerating the 16 combinations of constraints definable in referential and containment type expressions in addition to the cases for attributes.
For defining model types, we consider the universal value domain V of all computable values, the domain R of records, the domain μ of union values (variants) and the set F of continuous functions f from V to V. We refine the semantics for type expressions as model type expressions in order to consider referential types and the different types of constraints definable in a metamodel as follows: where the notation p, q denotes pairs of values p and q.

Model subtyping
In this section, we extend the object subtyping (subsumption) relation [10] to model types. Model subtyping emerges from object subtyping, and it is implicitly defined when a pair of model type expressions are given.
To extend the subtyping relation, we need to introduce how referential types and containment types are related by means of an incompatibility relation. To do so, we use the incompatibility relation ⊆ RefTName × RefTName which captures the subtyping violations (regarding multiplicities, ordering, uniqueness and bidirectionality) between two property type expressions. That is, an object type expression ς 1 containing a referential type expression p : α 1 that is incompatible with a referential type expression p : α 2 , with the same name p, of another object type expression ς 2 means that ς 1 does not denote a subtype of the type denoted by ς 2 . The incompatibility relation is defined as follows 4 : where ≤: denotes the negation of the subtyping relation between class names as defined below. Given two model types M < sub and M < super , the extended subtyping relation ≤: β ⊆ Type × Type, where β ⊆ C × C captures the names of those object types that have been related already, is defined as shown in Fig. 4. Whenever β is empty, we will refer to the subtyping relation as ≤: − without the suffix.
The semantics of subtyping is given by set inclusion of domains [10,Theorem Semantic Subtyping].
The proof is similar to that of Theorem Semantic Subtyping in [10] while considering the 16 types of constraints imposable on referential types and noting that β acts as a memory of already paired class names for traversing referential types effectively.
We generalize the notion subtyping to the notion of model subtyping through the object type of the root objects of a model as follows:

Evaluation of model subtyping
In this section, we show the expressivity of our structural subtyping operation (without OCL constraints) with respect to model typing [17,20]. We compare our approach to model subtyping by considering their example with the state machine metamodels shown in Fig. 5. Each state machine represents a version of the first one, where changes have been highlighted. Table1 shows the subtyping relation over the set of state machines in Fig. 5, according to our structural subtyping algorithm, with subtype operands shown on the rows and supertype operands shown on the columns. These results are consistent with those presented in [20] but for the cases where many-bounded references in a supertype are constrained by a lower upper bound in the corresponding subtype. In our approach, those cases are valid.

Structural and behavioural subtyping
In this section, we are going to use the notion of metamodel specification to refer to metamodels M → enriched with a set of OCL constraints . We are going to abuse the notation M → to refer to any OO representation for metamodels where object subtyping is represented ontologically and   Moreover, we will introduce the notion of operation specification for DSLs, based on model transformations, to capture the behavioural requirements of DSLs. Such specifications are declarative, not necessarily executable, and defined in terms of OCL constraints that capture temporal properties. An additional subtyping operator is developed both syntactically and semantically for operation specifications.
Liskov and Wing [14] discussed how structural and behavioural subtyping could be used to reason about safety properties in object-orientated systems. Inspired by this work, metamodel specifications allow us to reason about subtyping of invariants in DSL semantics, properties that must hold for all of the states (or execution configurations) of the interpreter. In contrast, operation specifications allow us to reason about subtyping of behavioural properties (history properties in [14]), which are properties that hold for all sequences of interpreter states.
Next, we introduce a representation for metamodels M → and recall their semantics as object models σ (M → ), given in [11], by slightly adapting their syntax. Then, we show how a metamodel M → determines a model type expression M < by means of a syntax transformation impl : M → → M < , which is used to triangulate σ (M → ) with M < , reflecting the notion of model subtyping from model type expressions to metamodels. Based on this construction to couple ontological typing with linguistic typing, the subtyping relation is defined over metamodel specifications syntactically and semantically. Then, operation signatures are extended with metamodel specifications and the notion of operation specification is introduced to capture behavioural properties. Finally, the subtyping relation is defined for extended operation signatures and for operation specifications. The subtyping relation is illustrated with the three use cases of Sect. 2.

Syntax of metamodel specifications
As the typical representation of metamodels (normally depicted as class diagrams) is not aware of some typetheoretic constructs (such as union types) and the object subtyping relation is explicitly defined as a subclassing relation, we provide an alternative representation for metamodels M → . Given the countable sets B of base type names b, E of enumeration type names , C of class names c, P of property names p, a metamodel M → is a tuple (Class, ≺ , Enum, Cons) where: Class ⊆ C is a countable set of class names; ≺ ⊆ C × C is a subclassing relation (allowing for multiple inheritance); Enum ⊆ E is a countable set of enumeration type names; and Cons is the set of constraints defined by a metamodel.
The constraints in Cons are given as propositions of the form: isAbstract(c) holds if class c is abstract; p(c) holds if class c contains a structural feature with name p; l( ) holds if l is a literal of the enumeration type denoted by ; type(c, p) = t, where t ∈ B Enum Class defines the type of a structural feature, which is an attribute if t ∈ B Enum and a reference if t ∈ Class; cont(c, p) holds if the structural feature p is a containment reference; for n ∈ N and m ∈ N ∪ { * }, lower(c, p) = n and upper(c, p) = m, such that n ≤ m, denote the lower and upper bounds of references; unique(c, p) holds if the structural feature is unique (when upper(c, p) > 1); ordered(c, p) holds if the structural feature is ordered (when upper(c, p) > 1); opposite(c, p, c , p ) holds if the structural feature p(c) is defined as opposite of p (c ), defining a bidirectional association.

Mapping metamodels to their model types
The interpretation σ (M → ) of a metamodel M → is usually given in terms of the set of metamodel-conformant models, which are normally represented as object diagrams. In this section, we map a semantics σ (M → ) to M → ⊆ V in our semantic domain in order to enable structural model subtyping for metamodels M → .
We focus on the abstract syntax of object diagrams by using attributed graphs [24], which are defined in terms of E-graphs. An E-graph has two different types of nodes, graph and data nodes, and three kinds of edges, namely regular edges, and edges for node and edge attribution. An E-graph [24, Def. 8.1] is defined as a tuple where: N G and N D are the sets of graph and data nodes, resp.; E G , E N A and E E A are the sets of graph, node attribute and edge attribute, resp.; and source and target functions are defined as be a data signature with attribute value sorts S D ⊆ S D , AG is defined as the set of attributed graphs of the form (G, D), where G is an E-graph and D is a DS I G-algebra.
To define the model type that corresponds to each metamodel, we need to relate the semantics of a metamodel M → to a model type M < . Given the set Union of union values, such link will be achieved through a map ↑ < → : AG → Union that obtains a union value from an attributed graph (or object diagram). Then, we generalize ↑ < → to all possible attributed graphs definable by a metamodel, mapping the semantics of metamodels to the semantics of model types.
↑ < → is defined by the equation where oc consists of objects {id = id(n), ps} defined from nodes n ∈ N G , where ps is defined as the set union of properties defined from edges in E G and E E A as follows: such that e ∈ E N A and src(e) = n and name(e) = p; p = ic where ic = {id(target(e)) | e ∈ E G , src(e) = n, name(e) = p}.
We denote the function space AG → Union as ⇑ < → . The interpretation of a metamodel M → is given as the set σ (M → ) of system states definable using M → . Ignoring the representational gap, we assume that 5

σ (M → ) ⊆ P(AG)
Hence, the model type of a metamodel M → is given as And, consequently, there must be a syntax transformation impl : M → → M < so that Note that, in this setting, we are not considering a metamodel M → as just the abstract syntax for a model type expression M < , as both syntactic representations, which have different semantics, are only related by impl. The map impl gives us sufficient equipment for reflecting the subtyping relation from model type expressions to metamodels:

Semantics of metamodel specifications
In this section, we present how metamodel specifications (M → , ) declare model types by extending metamodels M → with OCL expressions . The semantics of OCL expressions is reused from [11,30]. It is worth noting that Clark et al. provided a formal semantics for OCL [8] that is more amenable to our model type expressions from a semantic point of view if we consider the MML calculus [31]. However, the USE semantics comes equipped with the tool support we need in subsequent sections. We first define the semantics of a metamodel specification (M → , ) using the original USE semantics I (M → , ), where is a set of OCL invariants and is the environment of variables for evaluating the OCL invariants , and then, we define the corresponding model type.
The original OO semantics of a metamodel specification (M → , ) (representing an object model 6 ) can be extended 5 This proposition relies on the following observation: a system state for a metamodel M → is defined as a structure σ (M → ) = (σ Class , σ Att , σ Assoc ) in [11], where σ Class resembles N G , σ Att resembles E N A , and σ Assoc resembles E G . The direction of the set inclusion is justified by the fact that E-graphs in AG are not necessarily typed. 6 Noting: that the syntax we introduced for object models only considers binary associations (without an explicit name for the association); that attribute operation signatures p : Class → B Enum can be extracted from propositions of the form p(c) and type(p) = t where t ∈ B Enum; and that compositions are immaterial in USE format. as follows: We define the satisfaction of OCL constraints in a metamodel M → as follows ((M → , )).
The model type of a metamodel specification (M → , ) is defined as follows:

Metamodel specification subtyping
and it reifies M → sub ≤: M → super as an explicitly declared (static) subclassing relation ≺ between classes of M → sub and classes of M → super − that is, for any c sub ∈ Class sub and c super ∈ Class super , In the following, the synthesis process is discussed and illustrated with the running example. We assume that the set of classifier names for M → sub and M → super are disjoint. If that is not the case, a renaming has to be applied to the classifiers of the subtype metamodel first so as to ensure that precondition. Given to Cons sub,super . These constraints are added to narrow down the search for inconsistencies to M → sub . Virtual superclass extraction. ≺ sub,super is analysed and for each class that inherits the same feature f declared in two different superclasses sc 1 and sc 2 , we extract an abstract virtual superclass sc 1,2 , where the order in the subscript 1, 2 is inessential, of the two superclasses sc 1 and sc 2 in order to ensure the diamond property. The feature f is pulled up to the virtual superclass sc 1,2 (and removed from the superclasses sc 1 and sc 2 ). Class sub,super is augmented with sc 1,2 , and ≺ sub,super is augmented with (sc 1 , sc 1,2 ) and (sc 2 , sc 1,2 ). This analysis is repeated recursively until all virtual superclasses and the corresponding specialization links are added. Preserving the semantics of subclassing. The next step consists in pulling up common features from classes in the subtype metamodel M → sub to classes in the supertype metamodel M → super . For each class c sub ∈ Class sub that declares a feature p(c sub ) ∈ Cons sub such that there is an ancestor class c super ∈ Class super declaring a feature p(c super ) ∈ Cons super , the structural feature p(c super ) is added to Cons sub,super and removed from Cons super together with all the constraints defined for p. In addition, the constraints of feature p for c sub in Cons sub are redefined for c super and added to Cons sub,super while they are removed from Cons sub together with p(c sub ). This means that the feature p is pulled up from c sub to the ancestor c super (and removed from c sub ). The rest of constraints from Cons sub and Cons super are added to Cons sub,super . Hence, M → sub,super ⊆ M → super . The resulting extension metamodel M → sm,g for the running example is depicted in Fig. 6, where the multiplicities for the references nodes and edges from M → sm have been preserved. In M → sm,g , two virtual classes, GraphNode and GraphNodeEdge, have been extracted in two consecutive iterations.
For extending model subtyping to metamodel specifications using the construction presented above, we are going to use the extension metamodel M → sub,super synthesized by On the other hand, the property (2) is ensured by constructing ≺ as explained above, since the extracted virtual classes have a counterpart in the semantic domain as the meet types of the corresponding object types.
The notion of metamodel extension enables the articulation of syntactic model subtyping of metamodel specifications, coupling the semantics of metamodels with the semantics of OCL constraints, as follows:

Model transformation operation specifications
In this section, we extend function types to metamodel specifications in order to specify model transformation operations where (M → pre , pre ) specifies its preconditions and (M → post , post ) specifies its postconditions. First, we extend the notion of model transformation operation signature over metamodel specifications and augment the subtyping relation for operation signatures to enable safe substitution of operations. Second, operation application is defined, showing how operations can be reused across model types that are related via signature subtyping. Third, we develop the semantic notion of model transformation operation specification that enables refinement checking via operation specification subtyping.
While an extended operation signature is mostly a syntactic construct, it can also be regarded as the contract of a blackbox operation where the source metamodel specification details the operation pre-conditions, explaining where the operation can be applied. In contrast, the target metamodel specification provides the post-conditions, explaining the effects of the operation. For an extended signature ρ s→t to define a subtype of another extended signature ρ s →t , the precondition defined by (M → s , s ) can be more liberal in order to accept all models in (M → s , s ) while the postcondition (M → t , t ) needs to be constrained in order to produce at most those models in (M → t , t ). The following definition captures these considerations using the subtyping relation: Definition 8 (Extended operation signature subtyping) Given two extended operation signatures ρ s→t and ρ s →t , ρ s→t ≤: Subtyping of extended operation signatures characterizes when it is safe to substitute model transformation operations. Safe substitution of operations is useful for defining higherorder model transformation operations, like higher-order model transformations (HOTs) [32]. An extended operation signature can be used to define a formal parameter, and subtyping can be used to check if it is safe to replace the formal parameter with a more specific extended operation signature. This check treats operations as blackboxes and only considers their pre-/post-condition contracts.
For example, an extended operation signature (M → pre , pre ) → (M → post , post ) can be applied to models conforming to a metamodel specification (M → ac , ac ) if (M → ac , ac ) ≤: (M → pre , pre ). On the other hand, we can reuse the results of this operation as models conforming to a (possibly different) metamodel specification (M → ac , ac ) if (M → post , post ) ≤: (M → ac , ac ). The first condition ensures that the operation can rely on values of (M → ac , ac ), and the second condition guarantees that its outputs will not create any problem in the expecting context. In our running example of Sect.
can be applied to a model in (M → sm , sm ) as is for simulating a deterministic state machine. This will result in the creation of objects Mark, which can be automatically coerced to the type Observation as explained in Sect. 6.3.
A model transformation operation specification (ρ s→t , s→t ) is formed by an extended operation signature ρ s→t and a set of invariant constraints s→t extending the invariants in the precondition metamodel specification (M → s , s ) and in the postcondition metamodel specification (M → t , t ), capturing the operation semantics, that is, its intent. Model transformation operations can be encoded as invariants by considering the notion of transformation model [32], already exploited for encoding model transformations represented in ATL [33], QVT-R [34], and triple graph grammars [34].
For enabling the definition of operations with OCL invariants, the metamodels involved must define a notion of a snapshot capturing the set of models on which the operation is going to be applied, another set of snapshots capturing the models resulting from applying the operation, and a relation over sets of snapshots encoding temporal information in the model type. That is operation invariants must be declared over the relation M → s × M → t . With this assumption in mind, the semantics of an operation specification is defined as follows. This relation was captured via the predecessor association in the example of Sect. 2.3.

Definition 9 (Operation specification semantics)
Given an operation specification (ρ s→t , s→t ), A model transformation operation specification is defined with its signature and intent, thus capturing the operation's behaviour. The subtyping relation is generalized to model transformation operation specifications as follows.
Definition 10 (Operation specification subtyping) Given two operation specifications (ρ s→t , s→t ) and (ρ s→t , s→t ), That is, the extended operation signature ρ s→t must be a subtype of the extended operation signature ρ s →t and the behaviour of the supertype operation must be preserved in the subtype operation. The subtyping relation characterizes behavioural subtyping, and it can be used to check stepwise refinement between model transformation operations automatically (within the appropriate selection of bounds for the model finder).
In the example of Sect. 2.3, an operation specification capturing the behaviour of the state machine simulator is introduced for the metamodel specification containing the association predecessor. In this example, operation specification subtyping is trivially satisfied, as the operation is not defined for the supertype. However, subtyping is still helpful for automatically finding unintended inconsistencies between the effects of the operation and the valid class of models. Cabot et al. [34] described an alternative approach for capturing declarative specifications of modelto-model transformations using OCL invariants, without having to include temporal information in the metamodel. Our approach would also work with this alternative representation, after adapting the notion of satisfaction of behavioural constraints, although the resulting behavioural specifications would be more verbose and, thereby, more expensive to verify. While our notion of operation specification is based on invariants, operation specifications given in terms of OCL pre-and post-conditions can be translated to the proposed representation by using the filmstripping technique proposed by Hilken et al. [35], implemented in USE.

Tool support
The theory described in previous sections is implemented as a Java library that facilitates reuse in MDE. Specifically, given two metamodel specifications (M → sub , sub ) and (M → super , super ), where M → sub and M → super are EMF metamodels and sub and super are sets of OCL constraints in USE format (whose contextual types are defined in M → sub and M → super resp.), the tool will determine whether (M → sub , sub ) denotes a model subtype of the model type denoted by (M → super , super ). Note that any of the sets of OCL constraints may be empty.
If the check fails, there are two main sources of incompatibilities: the model types denoted by the metamodels and the OCL constraints. In the first case, the tool points at the source of the problem by showing the classes of the super-type metamodel M → super that are not extended by classes of M → sub . That information is useful to assess the advantage of, for example, pruning the supertype metamodel by computing the effective metamodel [23] w.r.t. a specific model transformation operation. In the second case, the tool will provide evidence that contradicts the compatibility property in Definition 6 of M → sub w.r.t. M → super in the form of a model G ∈ M → sub,super , represented in EMF notation (that is in XMI format), that invalidates a constraint in super .
If the check succeeds, the tool guarantees that (M → sub , sub ) is a structural refinement of (M → super , super ). Hence, any model transformation operation that is defined for (M → super , super ) can be safely applied to models of (M → sub , sub ). Going one step further, the tool also facilitates the reuse of such operation, when it is based on EMF, by automatically synthesizing an extension metamodel M → sub,super that can be substituted for M → super in the signature of the operation ensuring its application to models conforming to (M → sub , sub ) without any further change. In the following subsections, we explain how the tool reuses a third-party bounded model finder for verifying the compatibility property of Definition 6, and we discuss how our subtyping relation ≤: can be used to deal with multiple, dynamic and partial model typing.

Analysing OCL constraints
In our tool, we have adapted excerpts of TOTEM-MDE [36] in order to integrate the USE Validator [37] , where (M → sm , ∅) denotes a model type of nondeterministic state machines.

Multiple and strict typing
Given two metamodel specifications (M → 1 , 1 ) and , we obtain multiple inheritance semantics [10], that is multiple typing, by default. However, we can force strict typing in contexts where multiple typing is not allowed by obtaining the synthesized metamodel using a strict specialization relation ≺ s ⊆ Class sub × Class super where Note that there may be many such strict specialization relations in ( The strict specialization relation ≺ s with the lowest rank is the solution that provides the maximal model subtype w.r.t. strict model subtyping. When computing (M → sub , sub ) ≤: (M → super , super ) using strict typing mode, the tool recommends the specialization relation ≺ s with the lowest rank and will compute the satisfaction of OCL constraints using the synthesized metamodel synth(M → sub , M → super , ≺ s ). In the case of a tie, one strict specialization relation is chosen arbitrarily. However, the user can still inspect the other strict specialization relations enumerated by recommendation order, together with their corresponding synthesized metamodel and complement metamodels.
In the example, when forcing strict model subtyping, the extension metamodel synth(M → sm , M → g , ≺ s ) that is recommended is depicted in Fig. 7, together with the complement of the subtype metamodel The complement of the supertype metamodel is empty, indicating that all object types have been covered by the model subtyping relation induced by ≺ s .

Dynamic typing
Dynamic typing, understood as the property of an object to change its type while preserving its identity, can be implemented by constructing synthesized metamodels. A model operation can be reused for models conforming to a metamodel specification (M → cr eation , cr eation ) such that which entails the existence of an extension metamodel M → cr eation,in . That is the subtyping relation between two model types is inferred in M → cr eation,in , if it exists within the bounded search space. The extension metamodel is synthesized as explained in Sect. 5.4, but without adding constraints of the form (3) in order to enable side effects of model transformation operations that work with supertype classes. The extension metamodel facilitates the reuse of model transformation operations that may be implemented using EMF-based technology.

Retyping and type coercion
Throughout the paper, we assume that subtype and supertype have disjoint names. When this is not the case, the tool will automatically rename the classifiers in the subtype to ensure this condition. Metamodels must be defined in the same package for mapping the metamodel spec to USE. In such cases, the subtyping operator can yield several type renamings when computing the extension metamodel. In particular, to resolve this ambiguity, the algorithm that generates the extension metamodel renames classes in the subtype by prefixing the package's name. The tool reifies the subtyping relation between object types as annotations in the extension metamodel, including any implicit renaming.
As a consequence, as EMF relies on a nominal type system, two cases need to be considered when applying the operation to be reused: following up with the example in (b) (a) Fig. 8 Retyping and type coercion the previous section, when no new instances of classes in Class cr eation,in are created, but implicit renamings were added in the extension metamodel, that is only queries or updates are applied; and when new instances of classes in Class cr eation,in are created. Both cases are illustrated in Fig. 8, where an excerpt of a subtype metamodel and a supertype metamodel with a shared type are shown, together with the extension metamodel that infers their binding with inheritance and a renaming. The bold arrows represent the application of either a retyping or type coercion between models, and the dashed arrows represent the typing of each object, showing to which type each model belongs.
In the first case, when classifier names are disjoint in the supertype and the subtype, the resulting model conforms to (M → cr eation , cr eation ) without further changes. When implicit renamings are used (case a)), retyping G of models G ∈ M → cr eation is required so that G ∈ M → cr eation,in . Retyping is implemented using the EMF-Syncer [13]. In this context, the EMF-Syncer is a bidirectional synchronization tool between EMF metamodels that automatically matches the structural features of classes from one metamodel to other features in classes of the second metamodel by name, thus relying on a nominal type system for metamodels. Mapping strategies between metamodels may also be defined explicitly when matching cannot be inferred by name. Forward model synchronization can be done either eagerly, when the whole source model needs to be retyped, or on demand, when only those model excerpts that are used by the corresponding model transformation operation need to be retyped, and backward synchronization is done incrementally. The EMF-Syncer will read the annotations that were generated while the extension metamodel was inferred, meta-representing the subtyping relations between specific object types. With such data, the EMF-Syncer instantiates the most concrete object type in the extension metamodel, corresponding to the subtype metamodel. In our tool, retyping is performed via the operations asExtended, for retype a subtype-conforming model, and asOriginal, for retyping back the extension-conforming model to its original subtype.
In the second case (b)), also illustrated in Fig. 8, a type coercion operation is needed to cast down objects to classes defined in (M → cr eation , cr eation ). For a model G ∈ (M → in , in ) , the coercion operation where ≺ s is a strict subtyping relation between classes in Class cr eation and Class in , requires all mandatory features in (M → cr eation , M → in , ≺ s ) to have a default value. That is, those mandatory structural features that are not initialized in the operation need to be properly defined in a model.
The coercion operator changes the type of those objects in G, whose type is a class c super ∈ Class ∈ , for the greatest class c sub , with respect to ≺ cr eation , in Class cr eation such that c sub ≺ s c super . The operator is not defined when the choice of c sub is not unique −, e.g. when multiple inheritance is used in M → in . The coercion operator is also implemented using the EMF-Syncer , as a forward model transformation from supertype to subtype, similar to the retyping operations. The chosen strict inheritance relation, meta-represented as annotations in the extension metamodel, provides the renamings to be used as mapping specification by the EMF-Syncer . The main difference with the retyping operations is that up casting (corresponding to backward propagation of changes) is not needed. In case b) of Fig. 8, newly created objects by a model transformation operation defined for the supertype, need to be casted down and then mapped back to the original subtypes.

Semantic structural refinement
The first use case follows from the running example illustrated in Fig. 1, where the subtyping operator can be used to check whether a metamodel specification (M → sub , sub ) is a refinement of another one (M → super , super ). This use case demonstrates the optionality of OCL constraints in metamodel specifications when using the subtyping operator.
The model types described by both metamodels are structurally similar in that they both describe languages of graphs. On the one hand, the top metamodel specification characterizes the graph of a function defined over nodes. On the other hand, the bottom metamodel specification characterizes deterministic state machines where an event can trigger transitions (indicated in the name attribute of the transition) or are triggerless, e.g. in the case of completion transitions.
Moreover, consider non-deterministic state machines by removing the OCL constraint defining the deterministic condition from the state machine metamodel specification. We obtain a non-deterministic state machine that does not satisfy the graph constraint, which is represented in object diagram notation in Fig. 9. In this case, subject to appropriate selection of type bounds, the subtyping operator finds a counterexample, showing that the subtyping relation does not hold. The counterexample is a model conforming to the extension metamodel and can be casted down to the subtype as explained in the sections below.

Multiple typing
The subtyping relation intrinsically supports multiple typing, enabling subtyping where strict typing is too stringent. In the example of Fig. 10, borrowed from Bruel et al. [38], where an abstract structural containment design pattern is Metamodel b) describing goals only contains a class Goal with a containment reference subgoals. The subtyping relation, illustrated with a dashed arrow, identifies the class Goal as subtype of both Container and Element at the same time. However, the metamodels defining state machines (c)) and projects (d)) are not valid subtypes of the abstract container metamodel. In the state machine metamodel, StateMachine is not a subtype of Container since the feature states cannot be matched to the feature roots. The reason for this is that the type State is not a subtype of the type Element, as it has no feature corresponding to subs. In the project metamodel, the type Package is not a subtype of the type Element because the type of the feature elems is not compatible with the type of the feature subs, as its type Namespace is not a subtype of the type Element.
To enable reuse in metamodels c) and d), metamodel pruning is not enough to extract the effective metamodel, where the class Basic in c) and the class Class in d) would be removed, leaving a singleton class inheritance relationship in each metamodel that would have to be flattened.

DSML evolution (Reuse, Partial Typing)
In this use case, we are going to show how to reuse a model transformation operation-a model-to-text transformation with ATL-defined for a metamodel version 1, a modified version of the state machine metamodel, for models of a metamodel version 2. In Fig. 11, metamodel version 1 enables observable behaviour in state machines, where state observations are timestamped. Code generation from state machines to the format proposed by Fowler [39] is implemented using ATL. Figure 11, bottom part, from left to right, shows the model transformation, a state machine and its serialized counterpart.
In this hypothetical case of evolution, it becomes essential to track which operations are executed, instead of their states. Metamodel version 2 captures the dual notion of observability by using events to mark when a transition is trig-  gered. The metamodel version 1 is not exactly a supertype of the metamodel version 2. This change is not a structural refinement and is not backward compatible using traditional object-oriented extension mechanisms. In addition, metamodel version 2 is enriched with an OCL constraint on the name of the events that can be created: context Transition inv event_consistency : not ( self . event . oclIsUndefined ) implies self . name = self . event . name Our subtyping operator assists us in determining that version 2 of the metamodel together with the OCL constraint is not a refinement of version 1. Figure 12 shows the complement of the supertype obtained from the structural subtyping operator, explaining why models of metamodel version 2 can only be partially typed by metamodel version 1. To resolve this issue, the complement of the supertype is pruned from metamodel version 1 and the subtyping operator is then used to check whether the metamodel version 1, pruned is supertype of metamodel version 2. The extension metamodel, also shown in Fig. 12, that is generated by the subtyping operator shows that subtyping is satisfied. The extension metamodel contains renamings for the classes StateMachine, State and Transition to avoid name clashes.
The signature of the ATL operation should point to the extension metamodel, and the state machine that is an instance of the metamodel version 2 must be adapted in order to take into account renamings. Such adaptation is automatically handled by the operator asExtended(), as explained in Sect. 6.4.

Related work
Steel et al. [20] formalized the notion of model type as a type group, generalizing the notion of object typing. Ours is formalized as a union type instead, enabling the possibility of having heterogeneous root objects in a model. In [17], as the isomorphic subtyping relation based on model type matching is too strict, a non-isomorphic subtyping relation based on adaptation was introduced in order to facilitate more flexible reuse of model transformation operations, such as class renamings. However, our subtyping relation approach can work both for nominal and structural type systems providing support for metamodels. Subtyping is not simply isomorphic as it works modulo class renaming for any possible renaming, which need not be known a priori.
Based on the notion of model subtyping in [20], Sen et al. [22] presented a mechanism to reuse model transforma-tions by means of their effective metamodel M → in . A model transformation is then made reusable by manually weaving aspects of the effective metamodel M → in with the metamodel M → actual for which the transformation is to be applied so that M → actual becomes a subtype of M → in . In our approach, the extension metamodel M → actual,in , which facilitates the satisfiability of the model subtyping relation between two metamodel specifications, corresponds to the weaved metamodel that enables the reuse of the transformation. However, in our case, the extension metamodel is synthesized automatically and OCL constraints are considered.
Degueule et al. [40,41] define model types using interfaces in Melange, providing support for flexible model loading and structural subtyping. On the one hand, flexible model loading is used to reuse operations across languages, e.g. to load a UML model with a new version of UML, while ensuring safety by checking that the model type of the loading operation and that of the inferred model type of the model (effective footprint of the model) are appropriately related via the subtypeOf relation. To implement this safety check Melange requires the user to declare the model type explicitly. The tool automatically generates adapters for each object type involved in the model type, decoupling object types from their implementation in EMF. On the other hand, model subtyping is used to ensure safe substitutability and corresponds to total isomorphic subtyping studied in [17], as discussed above.
In EMF-Subtyping, model types are represented using model type expressions, which are in correspondence with EMF metamodels via the syntactic transformation impl as shown in Sect. 5.2. Hence, each metamodel declares a model type, which is built as a union type of the structural types emerging from the classifiers in the package of the metamodel and the EMF metamodel is another representation of a model type expression. Reuse of operations across languages is done via subtyping polymorphism using the synthesized extension metamodel, which reifies the subtyping relation between the model type of the model and that of the operation to be reused as shown in Sect. 5.4. When such subtyping requires renamings or more complex mappings, retyping occurs on-demand and incrementally via the EMF-Syncer. The problem of flexible model loading, where there is uncertainty about the metamodel of a given model, is left out of the scope of this paper. Working on EMF metamodels as direct representations of model types has two advantages while retaining the ability to ensure type safety via subtyping: first, the modeller does not need to add additional syntax to models in order to declare model types and, second, it does not require an intermediate layer of adapters delegating dynamic dispatch to the EMF objects. The signature of model transformation operations needs to be updated to refer to the extension metamodel, although this change does not affect the implementation or body of the operation. Our approach added advantage is that contracts, both for model types and model transformation operations, and the subtyping relation can be semantically enriched with OCL constraints.
Leroy et al. [42] propose a metalanguage for specifying behavioural interfaces for executable DSLs in the GEMOC studio [43]. Such interfaces define sets of events, enabling interoperability and reuse of components for enriching the behavioural semantics of DSLs. Subtyping of interfaces fosters event abstraction hierarchies and implementation relations tie behavioural interfaces to specific operational semantics implementations. The semantics of the proposed metalanguage relies on an event manager to handle message exchange via behavioural interfaces, translating event occurrences from external tools into actual behaviour, and emitting event occurrences to external tools as a reaction to an observable behaviour of the interpreter. Hence, Leroy et al. promote reuse in DSLs equipped with operational semantics, whereas our work focuses on the reuse of structural and declarative behavioural specifications, represented with metamodel and model transformation specifications, and of their implementations. The notion of extension metamodel enables an implicit implementation relation that does not need to be declared explicitly and the re-typing mechanisms, supported by the EMF-Syncer , handle translations of input and output values from the context to the operation, and vice versa. An important difference in our approach consists in the safe reuse of requirements in structural and behavioural specifications, which need not be executable, in addition to reuse of specification implementations. Moreover, our approach comes equipped with tool support for verifying reuse and refinement, whereas guaranteeing the soundness of implementation relations is delegated to the language engineer in [42].
Regarding as-is reuse of model transformations, Lara et al. proposed a-posteriori typing specifications [44] for decoupling the role creation of a metamodel, when regarded as a template for new models, from their role interpretation, when regarded as a classifier for existing models. These specifications can be applied both to the type level and to the instance level, providing support for multiple, partial and dynamic typing. Bidirectional typing specifications are formalized in [45], providing support for backward compatibility to the original metamodel when reusing another operation. Our synthesis of the extension metamodel resembles the construction of the analysis metamodel for reasoning about OCL constraints in [45]. An important difference lies in the inference of inheritance relationships. When there are name clashes in features from the resulting superclasses and subclasses, they rename the features in the superclass and add an OCL constraint to enforce that their values are the same. We solve this problem by applying a refactoring that preserves the type of the feature in the subtype, which may be more restrictive. This refactoring avoids duplicate code and skipping the use of auxiliary OCL constraints. Their approach cannot solve the problem described in the introduction as typing specifications are defined explicitly and require knowledge about the involved metamodel specifications a priori. The motivation behind our approach focuses on checking subtyping automatically without up-front manual intervention, leaving out explicit adaptation. In our case, retyping is implicitly handled through the model subtyping relation, and explicit re-typings (type coercion) are only required when reusing EMF model transformation operations, as explained in Sect. 6.3. On the other hand, our approach is framed at the type level.
Varró et al. also use ontological typing of objects in VPM [46] for defining metamodel conformant models. More interestingly, they provide a refinement calculus that handles (multiple) inheritance and instantiation, which provides a subsumption relationship between metamodels. Although they consider refinement of behavioural specifications, they can only reason with a subset of the metamodels expressible in EMF as they do not consider well-formedness constraints.
Graph constraints, introduced by Heckel et al. in [47] for plain graphs, and later extended by Taentzer et al. to graphs with type node inheritance in [48], capture a notion of metamodel specification that is similar to the one that we are dealing with. Propagation of constraints along model transformations, which can be regarded as adaptations, specified by triple graph grammars, is considered by Harmut in [49]. Constraint propagation determines when a target metamodel, which can have its own constraints, is compatible with respect to the constraints of the source metamodel. Our proposal does not require an explicitly defined up-front mapping, and the underlying theory is available in an executable tool.
Zschaler [50] introduced an abstract notion of model type with constraints as a graph, with class names as nodes and associations as edges, coupled with a conjunction of firstorder constraints over the graph signature. A model matching relation is used to match a metamodel to its model type, and a type system is provided to infer the minimal model types of a model transformation operation. The constraints that can be inferred refer to multiplicity bounds and to whether a class is abstract or not. When a model transformation operation is invoked over a model, the type system checks that the model satisfies the constraints of the model type associated with the parameter. Thus, model subtyping is implicitly taken care of by constraint satisfaction allowing for reuse. The inferred minimal model type is similar, in its intent, to the model type of an effective metamodel, which is assumed to be inferred from a model transformation, in our approach. On the other hand, the notion of model type has not been discussed independently of type inference for a model transformation operation and is, then, tied to the language used for defining model transformation operations, which is, at present, less expressive than those used in practice.
Bruel et al. [38] classified state-of-the-art approaches for reuse model transformation operations across metamodels. However, metamodels are not enriched with OCL constraints, and behavioural subtyping for the operations is not considered.
None of the approaches researched above considers reasoning on metamodels, which are unrelated a priori, enriched with OCL constraints in model subtyping.
Regarding refinement, Büttner et al. [51] propose a notion of contract-based transformation specification and of their (weak) refinement that is similar to our notion of operation specification and subtyping, respectively. They also use model finders, integrated into USE, to check the refinement of contract-based transformation specifications. In our presentation, however, we have used subtyping as a unifying framework both for structural and behavioural refinement, in addition to other use cases. Vallecillo et al. [52] proposed Tracts to encode transformation contracts using OCL invariants and proposed a notion of refinement that is semantically equivalent to ours. Refinement checking is based on testing, relying on the manual creation of input test models and the executability of the refined specification. In our case, as well as in [51], operation specifications need not be executable and manual creation of input models is not required.

Concluding remarks
The notion of model subtyping has been revisited from a subsumption perspective. Structural model subtyping has been extended to metamodel specifications as the problem of whether two groups of OCL constraints are compatible when their metamodels (or class diagrams) are not related a priori. We have implemented a procedure for solving this problem that, in addition, gives us: an extension metamodel for reusing model transformation operations whose signature involves the supertype metamodel when the metamodel specifications are compatible; and the reason why their metamodels are not subtype of each other, or else a metamodel-conformant model that satisfies the constraints of the subtype but not some of the supertype, when they are not compatible. The procedure is decidable when appropriate bounds are used for finding the witness model.
Structural model subtyping can be used for developing metamodel specification refinements without losing expressive power with respect to other approaches to subtyping. Structural model subtyping is robust enough so as to provide some adaptations for free without having to provide any explicit information relating metamodel specifications a priori, becoming both isomorphic and non-isomorphic [17]. We have also discussed that structural model subtyping provides a convenient theoretical framework to deal with dynamic, partial and multiple model typing. Nevertheless, structural model subtyping suffers from being too liberal in contexts where all the object subtypings need to be analysed. Our tool provides a recommendation algorithm that suggests an optimal strict model subtyping to mitigate this threat to usability. Including a more prescriptive approach that limits the number of valid object subtypings or dictates how subtypings should be performed with user information provided upfront is a potential extension.
Model subtyping has been generalized to model transformation operation specifications, which need not be executable, to ensure safe application of operations, substitutability and operation specification refinement, hence providing support for behavioural subtyping. This approach is independent of the language used to implement model transformations and is amenable for automatically verifying operation specifications.
The logic that was reused from TOTEM-MDE [36] for mapping Ecore models and OCL constraints to the USE validator in [12] has since been generalized in the EFinder [53], which accepts different dialects of OCL and provides support for model consistency, example generation, partial solution completion and scrolling. Exploring structural subtyping together with such additional facilities is left for future work.