SLE meets MDE and CompilationClément Guy, Steven Derrien, Benoît Combemale, Jean-Marc Jézéquel
Triskell & Cairn teams
IRISA-INRIA
2
General-purpose
Language
<<represents>>
<<conformsTo>>
Complex software systems (including
compilers)
3
<<represents>>
DSL1
DSL2 DSL3
DSL4
<<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
DSL1
DSL2 DSL3
DSL4
<<represents>>
<<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
DSL1
DSL2 DSL3
DSL4
<<represents>>
<<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
4
<<represents>>
<<conformsTo>>
DSL1
DSL2 DSL3
DSL4
<<represents>>
<<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
Our Motivations and Challenges
• Language multiplication
▫ Need for operations capitalization
▫ Need for inter-languages mappings
• Language operations multiplication
▫ Need for ways to ensure a sound combination of these operations
• Need for “best practices” for language definition
5
Capitalization Example:
Dead Code Elimination/Trimming
6
if (true) {
…
• Introduction: From Software Language “Craft” to Software Language Engineering
• Compilation, MDE and Programming Languages
• Typing in MDE
7
Motivations of SLE[Dagstuhl Seminar Proceedings: Language Engineering for Model-Driven Software
Development, 2004]
• Need for systematic approach of languages definition and tooling
• Go from “Software Language Craft” to Software Language Engineering
• Goals:
▫ Capture expert domains (DSLs)
▫ Process expert domains (analyses + transf.)
▫ Automate the path from expert domain to executable languages (compiler generation)
8
Challenges
• Facilities for the definition of languages (abstract syntax, concrete syntax, semantic domain, semantic mapping)
• Suitable user interfaces
• Automate process whenever possible
• Coping with many languages
9
• Introduction: From Software Language “Craft” to Software Language Engineering
• Compilation, MDE and Programming Languages
• Typing in MDE
10
Cross-Fertilization of MDE and
Compilers Research Communities
11
MDE
CompilationProgramming
Languages
Compilers Research
• Pros:
▫ Introduction of formal methods in languages
▫ Experience in program refactoring (e.g., tree rewritings)
▫ Experience in complex optimization problems (e.g., registers allocation, instructions selection, etc.)
• Cons:
▫ The number of transformations and their complexity increase:
Need for reuse and consistency
12
General-Purpose Programming
Languages• Pros:
▫ Software languages formalization
Abstract syntax, concrete syntax, semantic domain, semantic mapping
▫ Type systems
• Cons:
▫ Difficult to use for a non-expert
13
MDE
• System abstraction using domain specific models
• A model:
▫ Address one particular concern (security, business, UI…)
▫ Conforms to a metamodel
• A metamodel:
▫ Defines the concepts used in models (abstract syntax of a Domain Specific Modeling Language)
▫ Conforms to a metalanguage
14
MDE
15
The BPO has 154 agencies in 7 departments, employing 1470 persons. It has 341000 clients.…
Real world
Model BPO: Bank
RennesCentre:
Agency
RennesGare:
Agency
ClémentGuy:
Client: Account
: Account…
Metalanguage Class Reference
DSML
Bank: Class
Agency: Class Client: Class
Account: Classcontext Bank inv:
agencies.forall{ag|
accounts.forall{ac|
ac.owner.agency = ag
}
}
MDE
• Pros:
▫ Expertise on DSMLs definition and tooling:
Design by contract, generative approaches, metatools
• Cons:
▫ Lack of reuse
→Reuse of model operations through genericity
16
17
MDE
CompilationProgramming
Languages
Compilers
generators
Genericity
in MDE
Automatic
parallelization
Genericity
Inheritance &
Polymorphism
Function
typing &
Higher order
V & V
Tree
rewriting
[CLU: reference manual, Liskov et al., 1981]
[Genericity in Java with virtual types, Thorup, 1997]
[The essence of functional programming, Wadler, 1992]
[Simula, an Algol-based simulation language, Dahl, 1966]
[A semantics of multiple inheritance, Cardelli, 1992]
[Subtyping is not a good "Match" for object-oriented languages, Bruce et al., 1997]
[Advanced compiler design and implementation, Muchnick, 1997]
[A brief history of just-in-time, Aycock, 1997]
[Eclipse Modeling Framework, Budinsky et al., 2003]
[GMF, http://www.eclipse.org/modeling/gmp/]
[Domain-specific modeling: enabling full code generation, Kelly et al., 2008]
[On Model Typing, Steel et al., 2007]
[Generic model refactorings, Moha et al., 2009]
[Templatable metamodels for semantic variation points, Cuccuru et al., 2007]
[Generic meta-modelling with concepts, templates and mixin layers, de Lara et al., 2010]
[Xtext, http://www.eclipse.org/Xtext/]
[ANTLR: A predicated-LL(k) parser generator, Parr et al., 1995]
[A pattern matching compiler for multiple target languages, Moreau et al., 2003]
[A structured approach to proving compiler optimizations based on dataflow analysis, Bertotet al., 2006]
[Genericity versus inheritance, Meyer, 1986]
[Typing in Model Management, Vignaga et al., 2009]
Domain
Specific
Modeling
Optimization
[Automatic Program Parallelization, Banerjeeet al, 1993]
Function
typing in
MDE Typing in MDE
• Introduction: From Software Language “Craft” to Software Language Engineering
• Compilation, MDE and Programming Languages
• Typing in MDE
18
19
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1
<<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
<<conformsTo>><<conformsTo>><<conformsTo>>
<<conformsTo>><<conformsTo>>
<<conformsTo>>
<<conformsTo>>
<<conformsTo>>
<<represents>>
<<represents>><<represents>>
20
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1 Model Typing
ModelType1
ModelType2 Model
Type3 ModelType4
21
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1
DSL2 DSL3
DSL4
DSL1 Model Typing
ModelType1
ModelType2 Model
Type3 ModelType4
Define a type system allowing substitutability of models, reusability of model operations and operations typing
Typing in MDE
• Type models with respect to:
▫ Their model elements
▫ Their model operations
• Type model operations with respect to:
▫ The type of their parameters (models or other transformations)
22
Typing in MDE
• Type of a model:
MT = (C, O) s.t. C a set of classes and O a set of model operations
• Type of a model operation:
OT = T1 x … x Tn → Tr s.t. T1, …, Tn, Tn = MT or OT
23
Type vs Metamodel vs Language
• Model typing with respect to:
▫ Their model elements
Looks like a metamodel
▫ Their model operations
Not so much
• Metamodel + Model operations = Abstract syntax + Semantics = Language
24
Substitutability and Reuse
Genericity• Already existing approaches
• Parameterize languages with other languages
• Parameters have to match a structure on which operations are defined
[Generic model refactorings, Moha et al., 2009]
[Templatable metamodels for semantic variation points, Cuccuru et al., 2007]
[Generic meta-modelling with concepts, templates and mixin layers, de Lara et al., 2010]
25
Substitutability and Reuse
Genericity• Operations defined on a structure
• Languages which match this structure can reuse the operations
26
A
B C
Str1
A
B C
D
L1
var a: L1::A init L1::A.new
op<L1>(a)
operation op<T:Str1>(a: T::A)
is do
…
Substitutability and Reuse
Inheritance• Inherit structure and operations from “super-
languages”
• Define languages incrementally
• Need to define when a language is a subtype of an other
[On Model Typing, Steel et al., 2007]
27
Substitutability and Reuse
Inheritance• Allow to define a new language
from existing one(s)
▫ Allow to reuse operations defined on “super-languages”
28
var a2: L2::A init L2::A.new
a2.op()
A
B C
L1
A
B C
D
L2
<<inherits>>
class L1::A {
operation op() is do
…
Substitutability and Reuse
Inheritance• Allow to define a new language
from existing one(s)
▫ Allow to reuse operations defined on “super-languages”
▫ Allow a type hierarchy
29
var a2: L2::A init L2::A.new
a2.op()
class L1::A {
operation op() is do
…
var a4: L4::A init L4::A.new
a4.op()
L1
L2 L3
L5L4
<<inherits>>
<<inherits>>
Covariance, Contravariance
30
Mammal FoodMammal m := Mammal.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
food
Covariance, Contravariance
31
Mammal FoodMammal m := Mammal.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
food
Covariance, Contravariance
32
Mammal Food
Herbivore Plant
Mammal m := Mammal.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
Mammal m := Herbivore.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
food
food
Covariance, Contravariance
33
Mammal Food
Herbivore Plant
Mammal m := Mammal.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
Mammal m := Herbivore.new
Food f1 := Food.new
Food f2 = m.getFood()
m.setFood(f1)
food
food
Covariance, Contravariance
34
L1
A’
L2
A B
B’ C
Substitutability and Reuse
Adaptation• When languages are too different for inheritance
or genericity
• Differences may include:
▫ Renaming
▫ Gathering and separation of concepts
▫ …
• Need to know when an adaptation is possible
[IGraphAdapters@Cairn]
[An experiment of a MDE approach for the design of reusable DSL tools, Kerboeuf et al., IDM2011]
35
Conclusion and Perspectives
• Multiplication of languages brings a need for Software Language Engineering
• MDE, compilers research and programming languages communities have experience in languages definition and tooling
• One of the challenges SLE must face is the need for reasoning on sets of languages
• We propose to define a type system for models, model operations, etc.
• And to validate this type system with real use cases from compilation community
36
Questions, discussions ?
37