Budapest	University	of	Technology	and	Economics
Department	of	Measurement	and	Information	Systems
Program	Analysis Techniques for
Model Queries and	Transformations
Zoltán	Ujhelyi
Advisor:	Dr.	Dániel	Varró
Model-driven	Engineering
§ Modeling	tools	are	ubiquitous	in	
systems	engineering
o SW/HW	Architecture
o Platform	description
§ Common	tasks	in	tools
o Model	validation
o Artifact	generation
o Graphical	views
§ Inside	these	tools
o Models	as	graphs
o Constraints	as	graph	patterns
o Model	updates	as	graph	transformations
Model	Queries	and	Transformations
Graph	Patterns
• Conditions	and	constraints	expressed	as	graphs
• Different	pattern	matching	strategies
• Local	search
• Incremental	evaluation	(e.g.	Rete	networks)
Graph	Transformation	Rules
• Elementary	transformation	steps
• LHS	pattern	as	condition
• RHS	pattern	describes	action
Complex	Transformations
• Ordered	rule	applications
• Rule	calls and	dependencies
• Often	formulated	using	imperative	constructs
pl :	Place
LHS	- precondition RHS	- action
to	:	Token
X:	tokens
pl :	Place
to	:	Token
X:	tokens
pl :	Place
Analysis	of	Model	Queries	and	Transformations
§ Existing:	verification	and	validation	approaches
o E.g.	testing,	theorem	proving	or	model	checking
o High	level	of	effort	required	to	use
§ Goal:	lightweight	analysis	techniques
o To	assist	developers	of	queries	and	transformations
Transformation
Programs
Incremental
Graphical Views
Lightweight Static
Analysis
Graph
Pattern
Graph
Transformation
Complex Model
Transformation
Slicing
Lightweight	Static	Analysis	of	
Model	Queries	and	Transformations
Transformation	Language	Assumptions
• Misspellings
• Parameter	mismatches
Textual	language
• Declarative:	graph	patterns	and	graph	transformation	rules
• Imperative:	complex	control	structure
Imperative	and	declarative	parts
• Multiple	inheritance
• Dynamic	typing
Complex	type	system
Type	Checking	and	Inference
§ Problem:	Mistyping	variables	results	in	subtle	issues
o Empty	result	set	for	model	queries
§ Solution
o Type	rules:	collect	type	judgements	from	language	elements
o Type	safety	as	constraint	satisfaction	problems	(CSP)
o Back-annotation	of	results	to	program
pattern placeWithToken(pl : Place, to : Token) {
Place.tokens(to, pl);
}
TS	⊢ pl :	Place
TS	⊢ to	:	Token
Type	judgements
TS	⊢ to	:	Place	∧pl :	Token
CSP
Constraint	Graph	Analysis	– 1.
§ Connectedness	analysis
o Identifies	independent	subpatterns
o Expensive	match	set	calculation	(Cartesian	product)
o Suggests	missing	constraint
pattern sourcePlaceUnconnected
(p1 : Place, p2: Place) {
Transition(t1);
Transition(t2);
find sourcePlace(t1, p1);
find targetPlace(t2, p2);
// Missing: t1 == t2;
}
p1
p2
t1
t2
Ccall
sourcePlace
Ccall
targetPlace
Param #2
Param #2 Param #1
Param #1 Cent
Place
Cent
Place
entity
entity
Constraint	Graph	Analysis	– 2.
§ Variable	usage	counting
o Identify	unused	variables	(referenced	only	once)
o Suggest	misspelt	variable	name
pattern placeWithTokenUnused
(pl : Place) {
//pl and p1 are different
Place.tokens(p1, _);
}
pl
p1_
Crel
Place.tokens
Param #2 Param #1
Cent
Place
entity
C1:	Lightweight	Static	Analysis	Techniques
C1.1.	Type checking and	type inference with constraint
satisfaction problems
C1.2.	Type judgements of	model queries
C1.3.	Type judgements of	transformation rules
C1.4.	Variable	usage	counting	and	connectedness analysis	
for	graph	patterns
Collaboration:
Gábor	Bergmann
Evaluation	and	Exploitation
§ Evaluation
o Type	checking
• Good	performance	for	
declarative	parts
• Slowdown	in	imperative	control	structures
o Usage	counting	and	connectedness	analysis
• Positive	feedback	from	external	VIATRA	users
§ Exploitation	of	results:
o Available	in	current	release	of	VIATRA
o Influenced	the	pattern	language	of	EMF-IncQuery
• More	compact	syntax	assuming	type	inference
• Live	type	checking	while	typing
Program LoC Time	(s)
Petri	net	simulator 120 0.1	/	0.1
Petri	net	generator 94 1.2 /	0.9
Antworld 300 0.2	/	0.3
BPEL2SAL 8339 - /	69
Publications	Related	to	Contribution	1
Journal	paper
• Z.	Ujhelyi,	Á.	Hegedüs,	G.	Bergmann,	Á.	Horváth,	I.	Ráth and	D.	Varró.	‘EMF-
IncQery:	An	Integrated	Development	Environment	for	Live	Model	Queries’.	In:	
Science	of	Computer	Programming	98,	Part	1	(2015).	
• Z.	Ujhelyi,	Á.	Horváth,	and	D.	Varró.	“Static	Type	Checking	of	Model	
Transformation	Programs”.	In:	ECEASST	38	(2010).	
International	conferences
• G.	Bergmann,	Z.	Ujhelyi,	I.	Ráth,	and	D.	Varró.	“A	Graph	Query	Language	for	EMF	
Models”.	In:	Theory	and	Practice	of	Model	Transformations.	LNCS	6707.
Incremental	Graphical	Views
Challenges	for	Graphical	View	Models
• Capture	an	aspect	of	an	underlying	model
• Displayed	in	a	human	understandable	notation
Abstract	views	of	models
• A	subset	of	the	model	is	often	related	to	the	current	issue
• Requires	easy	definition	of	views
Views	for	debugging
• How	to	define	the	required	abstraction?
• How	to	update	the	view	models	on	model	changes?
• Different	view	models	require	different	rendering
View	development	is	expensive
Defining	View	Models
Model
RenderersRenderersView
Notation	
Transformation
Notation	
model
Graph	
patterns
Graph	
patterns
Graph	
patterns
&'()'("
&*+('"
,-'(."
/'01+23"
456'2*"
Any	model	
can	be	reused Multiple	renderers	
available,	e.g.	list,	
tree	or	graph
Simple	notation	model	
with	base	elements,	
such	as	items,	edges	or	
containment	relations
@Item(item = pl, label = "$pl.name$")
pattern place(pl : Place) { … }
@Containment(container = pl, item = to)
pattern tokens(pl : Place, to : Token) { … }
Transformation	
defined	by	annotated	
graph	patterns
C2:	Incremental	Graphical	Views
C2.1.	Graphical view definition
using annotated queries
C2.2.	Workflow	for	incremental
graphical view maintenance
Collaboration:
Csaba	Debreceni,	Péter	Lunk
Evaluation	and	Exploitation
§ Scalability	of	view	calculation	(by	C.	Debreceni)
o Models	up	to	100k	model	elements
o Initialization	time	acceptable
o Update	time	instantaneous
§ Exploitation
o VIATRA	Debugger
o Model	Visualization	in	Trans-IMA	project
Publications	related	to	Contribution	2
Journal	paper
• Z.	Ujhelyi,	Á.	Hegedüs,	G.	Bergmann,	Á.	Horváth,	I.	Ráth and	D.	Varró.	“EMF-
IncQuery:	An	Integrated	Development	Environment	for	Live	Model	Queries”.	In:	
Science	of	Computer	Programming	98,	Part	1	(2015).	
International	conferences
• C.	Debreceni,	Á.	Horváth,	Á.	Hegedüs,	Z.	Ujhelyi,	I.	Ráth,	and	D.	Varró.	“Query-
driven	Incremental	Synchronization	of	View	Models”.	In:	Proceedings	of	the	2nd	
Workshop	on	View-Based,	Aspect-Oriented	and	Orthographic	Software	
Modelling.
Slicing
Model	Queries	and	Transformations
Challenge	of	Debugging	Model	Transformations
• Why	has	a	certain	match	appeared	in	the results?
• Why	are	some	matches	missing	from	the	results?
Debugging	questions	related	to	model	queries
• Why	is	a	certain	statement	executed?
• Why	is	a	certain	model	element	created?
Debugging	questions	related	to	transformations
• Hidden	data	dependencies
• Declarative	rules
• Control	flow	dependencies
Identifying	dependencies
Similar to program	
slicing problem
Slicing	Model	Transformations
§ As	in	program	slicing
o Systematic	collection	of	dependencies
o BUT:	slicing of	(input)	models	is	also required
§ Two approaches
o Transformation slicing based on execution traces
o Query slicing based on Rete networks
Model	
transformation
slicing
Query	/	
Transformation
Models
Transformation	
Slice
Model	Slice
Criterion
Slicing	Model	Transformations	– An	Example
rule fireTransition(in T) = {
if (find isFireable(T)) {
// remove tokens from source places
forall Pl1
with find sourcePlace(T,Pl1)
do apply removeToken(Pl1);
// creates tokens on target places
forall Pl2
with find targetPlace(T,Pl2)
do apply addToken(Pl2);
}
}
Client
Server
Query
Respond
Store
C3:	Slicing	Model	Queries	and	Transformations
C3.1.	Slicing of	Model Transformations
C3.2.	Dynamic Backward Slicing of	Model Queries
C3.3.	Dynamic Backward Slicing of	Model Transformation
Programs
C3.4.	Evaluation	of	the	Dynamic	Backward	Slicing	
Approaches
Evaluation
§ Case	studies
§ Results
o Slices	reflect	the	characteristics	of	the	transformation
o Approach	scales	both	with
• Model	size	and	transformation	complexity
§ Exploitation
o Rete	visualizer	and	debugger	architecture	in	VIATRA
• Baseline	of	future	slicing	support
Petri	net	simulation
• Simple	transformation,	
large	models
Antworld	Case	
Study
• Complex	simulation
• Ever-growing	models
BPEL2SAL	
transformation
• Complex	imperative	
control	structure
Reengineering	Case	
Study
• Model	Extraction
Publications	Related	to	Contribution	3
International	conferences
• Z.	Ujhelyi,	G.	Bergmann,and D.	Varró.	“Rete	network	slicing	for	model	queries”.	
In:	Graph	Transformation.	LNCS	9761.	2016
• Z.	Ujhelyi,	Á.	Horváth,	and	D.	Varró.	“Dynamic	Backward	Slicing	of	Model	
Transformations”.	In:	Proceedings	of	the	2012	IEEE	Fifth	International	
Conference	on	Software	Testing,	Verication and	Validation.	ICST	’12.	IEEE	
Computer	Society,	2012
• Z.	Ujhelyi,	Á.	Horváth,	and	D.	Varró.	“Towards	Dynamic	Backwards	Slicing	of	
Model	Transformations”.	In:	Automated	Software	Engineering,	26th	IEEE/ACM	
Int.	Conf.	on.	2011,	pp.	404–407
Summary
New	Research	Results
Lightweight	
static	
analysis
Incremental	
Graphical	
Views
Slicing	
Techniques
Publication	Overview
§ Number	of	publications:	26
o International	journal	articles:	5
o International	conference	papers:	9
o International	workshop	papers:	6
o National	conference	papers:	4
o Technical	reports:	2
§ Independent	citations	(MTMT):	59
§ IEEE	Best	Paper	award	in	2014
o Z.	Ujhelyi,	Á.	Horváth,	D.	Varró,	N.	I.	Csiszár,	G.	Szőke,	L.	Vidács	and	R.	
Ferenc.	‘Anti-pattern	detection	with	model	queries:	A	comparison	of	
approaches’.	In:	Software	Maintenance,	Reengineering	and	Reverse	
Engineering	(CSMR-WCRE)
§ VIATRA	model	transformation	framework
o Type	checking	for	the	transformation	language
o Incremental	Graphical	Viewers	implementation
§ EMF-INCQUERY model	query	framework
o Static	type	checking	in	pattern	language
o Constraint	graph	analysis	included	in	pattern	language
§ Known	users	of	the	framework	include
Applications	of	Results	in	Modeling Tools
Co-lead	since 2013
Project	merged into VIATRA	in	2016
New	Research	Results
Lightweight	
static	
analysis
Incremental	
Graphical	
Views
Slicing	
Techniques

Program Analysis Techniques for Model Queries and Transformations