SlideShare a Scribd company logo
Lecture 9: Constraint Resolution
CS4200 Compiler Construction
Hendrik van Antwerpen
TU Delft
September 2018
!2
This lecture
Source
Code
Editor
Abstract
Syntax
Tree
ErrorsCollect Constraints SolveParse
Reading Material
3
The following papers add background, conceptual exposition,
and examples to the material from the slides. Some notation and
technical details have been changed; check the documentation.
!4
Good introduction to unification, which is the basis of many
type inference approaches, constraint languages, and logic
programming languages. Read sections 1, and 2.
https://www.cs.bu.edu/~snyder/publications/UnifChapter.pdf
Baader et al. “Chapter 8 - Unification Theory.” In Handbook of
Automated Reasoning, 445–533. Amsterdam: North-Holland, 2001.
!5
Separating type checking into constraint generation and
constraint solving provides more declarative definition of type
checkers. This paper introduces a constraint language
integrating name resolution into constraint resolution through
scope graph constraints.

This is the basis for the design of the NaBL2 static semantics
specification language.
https://doi.org/10.1145/2847538.2847543
PEPM 2016
!6
This paper describes the next generation of the approach.

Addresses (previously) open issues in expressiveness of scope graphs for
type systems:

- Structural types

- Generic types

Addresses open issue with staging of information in type systems.

Introduces Statix DSL for definition of type systems.

Prototype of Statix is available in Spoofax HEAD, but not ready for use in
project yet.
The future
OOPSLA 2018
To appear
Tiger in NaBL2
7
let
type point1 = { x2 : int, y3 : int }
var p4 := point5{ x6 = 4, y7 = 5 }
in
p8.x9
end
s3
Record Definitions
!8
[[ RecordTy(fields) ^ (s) : ty ]] :=
new s_rec,
ty == RECORD(s_rec),
NIL() <! ty,
distinct/name D(s_rec)/Field,
Map2[[ fields ^ (s_rec, s) ]].
[[ Field(x, t) ^ (s_rec, s_outer) ]] :=
Field{x} <- s_rec,
Field{x} : ty !,
[[ t ^ (s_outer) : ty ]].
s0
s2
s1
s0
Type
point1
s1 s2
RECORD(s2)
Field
x2
Field
y3
s3
INT
INT
let
type point1 = { x2 : int, y3 : int }
var p4 := point5{ x6 = 4, y7 = 5 }
in
p8.x9
end
s1
Record Creation
!9
s0
Type
point1
s1 s2
RECORD(s2)
Field
x2
Field
y3
s3
Var
p4
INT
INT
s0
s2
s3
[[ r@Record(t, inits) ^ (s) : ty ]] :=
[[ t ^ (s) : ty ]],
ty == RECORD(s_rec),
new s_use, s_use -I-> s_rec,
D(s_rec)/Field subseteq/name
R(s_use)/Field,
distinct/name R(s_use)/Field,
Map2[[ inits ^ (s_use, s) ]].
[[ InitField(x, e) ^ (s_use, s) ]] :=
Field{x} -> s_use,
Field{x} |-> d,
d : ty1,
[[ e ^ (s) : ty2 ]],
ty2 <? ty1.
s4
Type
point5
s4
Field
x6
Field
y7
s_rec
RECORD(s_rec)
let
type point1 = { x2 : int, y3 : int }
var p4 := point5{ x6 = 4, y7 = 5 }
in
p8.x9
end
s1
Record Field Access
!10
s0
s2
s3
s0
Type
point1
s1 s2
RECORD(s2)
Field
x2
Field
y3
s3
INT
INT
[[ FieldVar(e, f) ^ (s) : ty ]] :=
[[ e ^ (s) : ty_e ]],
ty_e == RECORD(s_rec),
new s_use, s_use -I-> s_rec,
Field{f} -> s_use,
Field{f} |-> d,
d : ty.
s5
RECORD(s2)
Var
p4
Var
p8
s5
Field
x9
s_rec
s4
Solving Constraints
11
Solving by Rewriting
!12
C
{}; {}
Constraint
{}
{}
Solution
C'
G'; s'
C''
G''; s''
{}
G; s...
Solving by Rewriting
!13
<C; G, s> ---> <C; G, s>
<t == u, C; G, s> ---> <C; G, s'> where unify(s,t,u) = s'
<s1 -L-> s2, C; G, s> ---> <C; G', s> where G + {s1 -L-> s2} = G'
<Ns{x@i} |-> t, C; G, s> ---> <t == d; G, s> where resolve(G,Ns{x@i}) = d
def solve(C):
if <C; {}, {}> --->* <{}; G, s>:
return <G, s>
else:
fail
Solver = rewrite system
- Rewrite a constraints set + solution
- Simplifying and eliminating constraints
‣ Constraint selecting is non-deterministic
‣ Partial order is enforced by side conditions on rewrite rules
- Rely on (other) solvers and algorithms for base cases
‣ Unification for term equality
‣ Scope graph resolution
- The solution is final if all constraints are eliminated
Does the order matter for the outcome?
- Confluence: the output is the same for any solving order
- Conjecture: Partly true for NaBL2
‣ Up to variable and scope names
‣ Only if all constraints are reduced
Solving by Rewriting
!14
Constraint Semantics
15
What is the meaning of constraints?
- What is a valid solution?

- Or: in which models are the constraints satisfied?

- Can we describe this independent of an algorithm?

When are constraints satisfied?
- Formally described by the semantics

- Written as G,s ⊨ C
- Satisfied in a model (substitution + scope graph)

- Describes for every type of constraint when it is satisfied
!16
What gives constraints meaning?
ty == FUN(ty1,ty2)

Var{x} |-> d
ty1 == INT()
Semantics of (a Subset of) NaBL2 Constraints
!17
C = t == t // equality
| r |-> d // resolution
| C / C // conjunction
G,s ⊨ t == u
G,s ⊨ r |-> d
G,s ⊨ C1 / C2
if s(t) = s(u)
if s(r) = Var{x @i}
and s(d) = Var{x @j}
and Var{x @i} resolves to Var{x @j} in G
if G,s ⊨ C1 and G,s ⊨ C2
Constraint syntax
Constraint semantics
Using the Semantics
!18
G,s ⊨ t == u
if s(t) = s(u)
G,s ⊨ r |-> d
if s(r) = Var{x @i}
and s(d) = Var{x @j}
and Var{x @i} resolves to Var{x @j} in G
G,s ⊨ C1 / C2
if G,s ⊨ C1
and G,s ⊨ C2
let
function f1(x2 : int) : int =
x3 + 1
in
f4(14)
end
ty1 == INT()
INT() == INT()
Var{x @3} |-> d1
ty2 == INT()
Var{f @4} |-> d2
ty3 == FUN(ty4,ty5)
ty4 == INT()
…

s = { ty1 -> INT(),
ty2 -> INT(),
ty3 -> FUN(INT(),ty5),
ty4 -> INT(),
d1 -> Var{x @2},
d2 -> Var{f @1}
}
s0
s1
f1 FUN(ty1,ty2)
x2x3
f4
What is the difference?
- Algorithm computes a solution (= model)

- Semantics describes when a constraint is satisfied by a model

How are these related?
- Soundness

‣ If the solver returns <G, s>, then G,s ⊨ C

- Completeness:

‣ If an s exists such that G,s ⊨ C, then the solver returns it

‣ If no such s exists, the solver fails

Principality
- The solver finds the most general s
!19
Semantics vs Algorithm
Term Equality & Unification
20
Syntactic Terms
!21
INT()
FUN(INT(),INT())
f(t0,…,tn)
function symbol
arity
f(t0,…,tn) == g(u0,…,um) if
- f = g, and n = m
- ti == ui for every i
Generic Terms
Syntactic Equality
terms t, u
functions f, g, h
arguments
Variables and Substitution
!22
f(g(),a)
terms t, u
functions f, g, h
variables a, b, c
substitution s
ground term: a term without variables
s = { a -> f(g(),b), b -> h() }
domain
f(g(),f(g(),b))
s(a) = t if { a -> t } in s
s(a) = a otherwise
s(f(t0,…,tn)) = f(s(t0),…,s(tn))
variable substitution
Unifiers
!23
f(a,g()) == f(h(),b)
a -> h()
b -> g()
g(a,f(b)) == g(f(h()),a) a -> f(h())
b -> h()
f(a,h()) == g(h(),b) no unifier, f != g
terms t, u
functions f, g, h
variables a, b, c
substitution s
f(h(),g()) == f(h(),g())
g(f(h()),f(h())) == g(f(h()),f(h()))
f(b,b) == b b -> f(b,b) not idempotent
unifier: a substitution that makes terms equal
Most General Unifiers
!24
terms t, u
functions f, g, h
variables a, b, c
substitution s
f(a,b) == f(b,c)
a -> g()
b -> g()
c -> g()
a -> b
c -> b
f(g(),g()) == f(g(),g())
f(b,b) == f(b,b)
b -> a
c -> a
f(a,a) == f(a,a)most general
unifiers
Most General Unifiers
!25
a -> g()
b -> g()
c -> g()
a -> b
b -> b
c -> b
a -> a
b -> a
c -> a
a -> b
b -> b
c -> b
terms t, u
functions f, g, h
variables a, b, c
substitution s
b -> g()
b -> a
a -> b
b -> b
c -> b
a -> a
b -> a
c -> a
a -> b
every unifier is an instance of a most general unifier
(implicit) identity case
most general unifiers are related by renaming substitutions
global s
def unify(t, u):
if t is a variable:
t := s(t)
if u is a variable:
u := s(u)
if t == u:
pass
else if t == f(t0,...,tn) and u == g(u0,...,um):
if f == g and n == m:
for i := 1 to n:
unify(ti, ui)
else:
fail "different function symbols"
else if t is not a variable:
unify(u, t)
else if t occurs in u:
fail "recursive term"
else:
s += { s -> t }
Unification
!26
terms t, u
functions f, g, h
variables a, b, c
substitution s
t == a

instantiate variable
t == k(t0,...,t5), u == k(u0,...,u5)

matching terms
t == k(t0,...,t5), u == f(u0,...,u3)

mismatching terms
t == k(t0,...,t5), u == b

mismatching terms
t == a, u == k(g(a,f()))

recursive terms
t == a, u == k(u0,...,u5)

extend unifier
u == b

instantiate variable
equal terms
Unification (rewriting)
!X
{ t == u } U C; s ———> C’ U C; s’

{ t == t } U C; s ———>
C; s

{ f(t0,…,tn) == f(u0,…,un) } U C; s ———>
{ t0 == u0, …, tn == un } U C; s

{ f(t0,…,tn) == g(u0,…,um) } U C; s ———>
FAIL
if f != g

{ a == t } U C; s ———>
C{a -> t}; s{a -> t}
if a ∉ vars(t)

{ a == t } U C; s ———>
FAIL
if a ∈ vars(t)

{ t == a } U C; s ———>
{ a == t } U C; s
equalities
rewrite function
{ f() == f() }
{}
{ f(g()) == f(h()) }
{ g() == h() }
{ g(b,a) == g(a,h(b)) }
{ b == a, a == h(b) }
{ a == h(a) }
{ f(g(),h(a)) == f(b,h(b)) }
{ g() == b, h(a) == h(b) }
{ b == g(), h(a) == h(b) }
{ h(a) == h(g()) }
{ a == g() }
{}
{}
{}
{}
FAIL
{}
{b -> a}
FAIL
{}
{}
{b -> g()}
{b -> g()}
{b -> g(),a -> g()}
{b -> g(),a -> g()}
substitution
terms t, u
functions f, g, h
variables a, b, c
substitution s
equalities C substitution s
Soundness
- If the algorithm returns a unifier, it makes the terms equal
Completeness
- If a unifier exists, the algorithm will return it
Principality
- If the algorithm returns a unifier, it is a most general unifier
Termination
- The algorithm always returns a unifier or fails
Properties of Unification
!27
Efficient Unification
with Union-Find
X
Space complexity
- Exponential
- Representation of unifier
Time complexity
- Exponential
- Recursive calls on terms
Solution
- Union-Find algorithm
- Complexity growth can be
considered constant

Complexity of Unification
!28
h(a1 , …,an , f(b0,b0), …, f(bn-1,bn-1), an) ==
h(f(a0,a0), …,f(an-1,an-1), b1, …, bn-1 , bn)
a1 -> f(a0,a0)
a2 -> f(f(a0,a0), f(a0,a0))
ai -> … 2i+1-1 subterms …
b1 -> f(a0,a0)
b2 -> f(f(a0,a0), f(a0,a0))
bi -> … 2i+1-1 subterms …
terms t, u
functions f, g, h
variables a, b, c
substitution s
a1 -> f(a0,a0)
a2 -> f(a1,a1)
ai -> … 3 subterms …
b1 -> f(a0,a0)
b2 -> f(a1,a1)
bi -> … 3 subterms …
fully applied triangular
Set Representatives
!29
FIND(a):

b := rep(a)

if b == a:

return a

else

return FIND(b)





UNION(a1,a2):

b1 := FIND(a1)

b2 := FIND(a2)

LINK(b1,b2)

LINK(a1,a2):

rep(a1) := a2









a == b

c == a
u == w

v == u

x == v
x == c
a
b c
u
w v
x
representative
Path Compression
!30
FIND(a):
b := rep(a)
if b == a:
return a
else
b := FIND(b)
rep(a) := b
return b
UNION(a1,a2):

b1 := FIND(a1)
b2 := FIND(a2)
LINK(b1,b2)

LINK(a1,a2):

rep(a1) := a2
…
x == b
x == c
x == w
x == v
a
b c
u
w v
x
Tree Balancing
!31
FIND(a):
b := rep(a)
if b == a:
return a
else
b := FIND(b)
rep(a) := b
return b
UNION(a1,a2):
b1 := FIND(a1)
b2 := FIND(a2)
LINK(b1,b2)

LINK(a1,a2):

if size(a2) > size(a1):
rep(a1) := a2
size(a2) += size(a1)
else:
rep(a2) := a1
size(a1) += size(a2)
…
x == c
a
b c
u
w v
x
1
21
4
11
3
3 steps
2 steps
?
The Complex Case
!32
h(a1 , …,an , f(b0,b0), …, f(bn-1,bn-1), an) ==
h(f(a0,a0), …,f(an-1,an-1), b1, …, bn-1 , bn)
a1
a0
an-1
an
b1
b0
bn-1
bn
f(a0,a0)
f(an-2,an-2)
f(an-1,an-1)
f(b0,b0)
f(bn-2,bn-2)
f(bn-1,bn-1)
an == bn
f(an-1,an-1) == f(bn-1,bn-1)
an-1 == bn-1 an-1 == bn-1
f(an-2,an-2) == f(bn-2,bn-2)
⠸
a1 == b1 a1 == b1
f(a0,a0) == f(b0,b0)
a0 == b0 a0 == b0
How about occurrence checks? Postpone!
Main idea
- Represent unifier as graph
- One variable represent equivalence class
- Replace substitution by union & find operations
- Testing equality becomes testing node identity
Optimizations
- Path compression make recurring lookups fast
- Tree balancing keeps paths short
Complexity
- Linear in space and almost linear in time (technically inverse Ackermann)
- Easy to extract triangular unifier from graph
- Postpone occurrence checks to prevent traversing (potentially) large terms
Union-Find
!33
Martelli, Montanari. An Efficient Unification Algorithm. TOPLAS, 1982
Conclusion
34
What is the meaning of constraints?
- Formally described by constraint semantics
- Semantics classify solutions, but do not compute them
- Semantics are expressed in terms of other theories
‣ Syntactic equality
‣ Scope graph resolution
What techniques can we use to implements solvers?
- Constraint Simplification
‣ Simplification rules
‣ Depends on built-in procedures to unify or resolve names
- Unification
‣ Unifiers make terms with variables equal
‣ Unification computes most general unifiers
What is the relation between solver and semantics?
- Soundness: any solution satisfies the semantics
- Completeness: if a solution exists, the solver finds it
- Principality: the solver computes most general solutions
Summary
!35
Except where otherwise noted, this work is licensed under

More Related Content

What's hot

Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
Eelco Visser
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
Eelco Visser
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
Eelco Visser
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
Eelco Visser
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
Eelco Visser
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
Eelco Visser
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
Guido Wachsmuth
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
Sami Said
 
Programming languages
Programming languagesProgramming languages
Programming languages
Eelco Visser
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
Eelco Visser
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
Guido Wachsmuth
 
Dynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter GenerationDynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter Generation
Eelco Visser
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
Eelco Visser
 
Functional programming
Functional programmingFunctional programming
Functional programming
Prashant Kalkar
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
Eelco Visser
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
Prashant Kalkar
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
Sreedhar Chowdam
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
DhivyaSubramaniyam
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
Sreedhar Chowdam
 

What's hot (20)

Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name Resolution
 
Declare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term RewritingDeclare Your Language: Transformation by Strategic Term Rewriting
Declare Your Language: Transformation by Strategic Term Rewriting
 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
 
Compiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual MachinesCompiler Construction | Lecture 12 | Virtual Machines
Compiler Construction | Lecture 12 | Virtual Machines
 
CS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | ParsingCS4200 2019 | Lecture 3 | Parsing
CS4200 2019 | Lecture 3 | Parsing
 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
 
Dynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter GenerationDynamic Semantics Specification and Interpreter Generation
Dynamic Semantics Specification and Interpreter Generation
 
Advanced C - Part 2
Advanced C - Part 2Advanced C - Part 2
Advanced C - Part 2
 
Static name resolution
Static name resolutionStatic name resolution
Static name resolution
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
Python unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabusPython unit 2 as per Anna university syllabus
Python unit 2 as per Anna university syllabus
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 

Similar to Compiler Construction | Lecture 9 | Constraint Resolution

Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1
Eelco Visser
 
Week 4
Week 4Week 4
Week 4
a_akhavan
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
SrinivasaReddyPolamR
 
smtlecture.7
smtlecture.7smtlecture.7
smtlecture.7
Roberto Bruttomesso
 
Ijmet 10 01_046
Ijmet 10 01_046Ijmet 10 01_046
Ijmet 10 01_046
IAEME Publication
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
vsssuresh
 
Murphy: Machine learning A probabilistic perspective: Ch.9
Murphy: Machine learning A probabilistic perspective: Ch.9Murphy: Machine learning A probabilistic perspective: Ch.9
Murphy: Machine learning A probabilistic perspective: Ch.9
Daisuke Yoneoka
 
A common random fixed point theorem for rational inequality in hilbert space
A common random fixed point theorem for rational inequality in hilbert spaceA common random fixed point theorem for rational inequality in hilbert space
A common random fixed point theorem for rational inequality in hilbert space
Alexander Decker
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
Amrinder Arora
 
Ch06 6
Ch06 6Ch06 6
Ch06 6
Rendy Robert
 
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
IOSR Journals
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processes
Emmanuel Hadoux
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Codemotion
 
C2.0 propositional logic
C2.0 propositional logicC2.0 propositional logic
C2.0 propositional logic
Melaku Bayih Demessie
 
Ch8a
Ch8aCh8a
2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf
RajuSingh806014
 
On Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular IntegralsOn Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular Integrals
VjekoslavKovac1
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.ppt
ZohairMughal1
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).ppt
ZohairMughal1
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
Prakash Dabhi
 

Similar to Compiler Construction | Lecture 9 | Constraint Resolution (20)

Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1
 
Week 4
Week 4Week 4
Week 4
 
time_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdftime_complexity_list_02_04_2024_22_pages.pdf
time_complexity_list_02_04_2024_22_pages.pdf
 
smtlecture.7
smtlecture.7smtlecture.7
smtlecture.7
 
Ijmet 10 01_046
Ijmet 10 01_046Ijmet 10 01_046
Ijmet 10 01_046
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Murphy: Machine learning A probabilistic perspective: Ch.9
Murphy: Machine learning A probabilistic perspective: Ch.9Murphy: Machine learning A probabilistic perspective: Ch.9
Murphy: Machine learning A probabilistic perspective: Ch.9
 
A common random fixed point theorem for rational inequality in hilbert space
A common random fixed point theorem for rational inequality in hilbert spaceA common random fixed point theorem for rational inequality in hilbert space
A common random fixed point theorem for rational inequality in hilbert space
 
Introduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic NotationIntroduction to Algorithms and Asymptotic Notation
Introduction to Algorithms and Asymptotic Notation
 
Ch06 6
Ch06 6Ch06 6
Ch06 6
 
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
Adomian Decomposition Method for Certain Space-Time Fractional Partial Differ...
 
Optimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processesOptimization of probabilistic argumentation with Markov processes
Optimization of probabilistic argumentation with Markov processes
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
C2.0 propositional logic
C2.0 propositional logicC2.0 propositional logic
C2.0 propositional logic
 
Ch8a
Ch8aCh8a
Ch8a
 
2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf2. Definite Int. Theory Module-5.pdf
2. Definite Int. Theory Module-5.pdf
 
On Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular IntegralsOn Twisted Paraproducts and some other Multilinear Singular Integrals
On Twisted Paraproducts and some other Multilinear Singular Integrals
 
Lecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.pptLecture 4 - Growth of Functions.ppt
Lecture 4 - Growth of Functions.ppt
 
Lecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).pptLecture 4 - Growth of Functions (1).ppt
Lecture 4 - Growth of Functions (1).ppt
 
Complex analysis notes
Complex analysis notesComplex analysis notes
Complex analysis notes
 

More from Eelco Visser

CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
Eelco Visser
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
Eelco Visser
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Eelco Visser
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Eelco Visser
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
Eelco Visser
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
Eelco Visser
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
Eelco Visser
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
Eelco Visser
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Eelco Visser
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor Services
Eelco Visser
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
Eelco Visser
 
Declare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code GenerationDeclare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code Generation
Eelco Visser
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
Eelco Visser
 
Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2
Eelco Visser
 

More from Eelco Visser (15)

CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: Introduction
 
A Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation RulesA Direct Semantics of Declarative Disambiguation Rules
A Direct Semantics of Declarative Disambiguation Rules
 
Compiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler ConstructionCompiler Construction | Lecture 17 | Beyond Compiler Construction
Compiler Construction | Lecture 17 | Beyond Compiler Construction
 
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)Domain Specific Languages for Parallel Graph AnalytiX (PGX)
Domain Specific Languages for Parallel Graph AnalytiX (PGX)
 
Compiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory ManagementCompiler Construction | Lecture 15 | Memory Management
Compiler Construction | Lecture 15 | Memory Management
 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code Generation
 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone Frameworks
 
Compiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow AnalysisCompiler Construction | Lecture 10 | Data-Flow Analysis
Compiler Construction | Lecture 10 | Data-Flow Analysis
 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type Checking
 
Compiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static AnalysisCompiler Construction | Lecture 6 | Introduction to Static Analysis
Compiler Construction | Lecture 6 | Introduction to Static Analysis
 
Compiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor ServicesCompiler Construction | Lecture 3 | Syntactic Editor Services
Compiler Construction | Lecture 3 | Syntactic Editor Services
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Declare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code GenerationDeclare Your Language: Virtual Machines & Code Generation
Declare Your Language: Virtual Machines & Code Generation
 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic Semantics
 
Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2
 

Recently uploaded

The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
aisafed42
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
ToXSL Technologies
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 

Recently uploaded (20)

The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabhQuarter 3 SLRP grade 9.. gshajsbhhaheabh
Quarter 3 SLRP grade 9.. gshajsbhhaheabh
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?How Can Hiring A Mobile App Development Company Help Your Business Grow?
How Can Hiring A Mobile App Development Company Help Your Business Grow?
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 

Compiler Construction | Lecture 9 | Constraint Resolution

  • 1. Lecture 9: Constraint Resolution CS4200 Compiler Construction Hendrik van Antwerpen TU Delft September 2018
  • 3. Reading Material 3 The following papers add background, conceptual exposition, and examples to the material from the slides. Some notation and technical details have been changed; check the documentation.
  • 4. !4 Good introduction to unification, which is the basis of many type inference approaches, constraint languages, and logic programming languages. Read sections 1, and 2. https://www.cs.bu.edu/~snyder/publications/UnifChapter.pdf Baader et al. “Chapter 8 - Unification Theory.” In Handbook of Automated Reasoning, 445–533. Amsterdam: North-Holland, 2001.
  • 5. !5 Separating type checking into constraint generation and constraint solving provides more declarative definition of type checkers. This paper introduces a constraint language integrating name resolution into constraint resolution through scope graph constraints. This is the basis for the design of the NaBL2 static semantics specification language. https://doi.org/10.1145/2847538.2847543 PEPM 2016
  • 6. !6 This paper describes the next generation of the approach. Addresses (previously) open issues in expressiveness of scope graphs for type systems: - Structural types - Generic types Addresses open issue with staging of information in type systems. Introduces Statix DSL for definition of type systems. Prototype of Statix is available in Spoofax HEAD, but not ready for use in project yet. The future OOPSLA 2018 To appear
  • 8. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s3 Record Definitions !8 [[ RecordTy(fields) ^ (s) : ty ]] := new s_rec, ty == RECORD(s_rec), NIL() <! ty, distinct/name D(s_rec)/Field, Map2[[ fields ^ (s_rec, s) ]]. [[ Field(x, t) ^ (s_rec, s_outer) ]] := Field{x} <- s_rec, Field{x} : ty !, [[ t ^ (s_outer) : ty ]]. s0 s2 s1 s0 Type point1 s1 s2 RECORD(s2) Field x2 Field y3 s3 INT INT
  • 9. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s1 Record Creation !9 s0 Type point1 s1 s2 RECORD(s2) Field x2 Field y3 s3 Var p4 INT INT s0 s2 s3 [[ r@Record(t, inits) ^ (s) : ty ]] := [[ t ^ (s) : ty ]], ty == RECORD(s_rec), new s_use, s_use -I-> s_rec, D(s_rec)/Field subseteq/name R(s_use)/Field, distinct/name R(s_use)/Field, Map2[[ inits ^ (s_use, s) ]]. [[ InitField(x, e) ^ (s_use, s) ]] := Field{x} -> s_use, Field{x} |-> d, d : ty1, [[ e ^ (s) : ty2 ]], ty2 <? ty1. s4 Type point5 s4 Field x6 Field y7 s_rec RECORD(s_rec)
  • 10. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s1 Record Field Access !10 s0 s2 s3 s0 Type point1 s1 s2 RECORD(s2) Field x2 Field y3 s3 INT INT [[ FieldVar(e, f) ^ (s) : ty ]] := [[ e ^ (s) : ty_e ]], ty_e == RECORD(s_rec), new s_use, s_use -I-> s_rec, Field{f} -> s_use, Field{f} |-> d, d : ty. s5 RECORD(s2) Var p4 Var p8 s5 Field x9 s_rec s4
  • 12. Solving by Rewriting !12 C {}; {} Constraint {} {} Solution C' G'; s' C'' G''; s'' {} G; s...
  • 13. Solving by Rewriting !13 <C; G, s> ---> <C; G, s> <t == u, C; G, s> ---> <C; G, s'> where unify(s,t,u) = s' <s1 -L-> s2, C; G, s> ---> <C; G', s> where G + {s1 -L-> s2} = G' <Ns{x@i} |-> t, C; G, s> ---> <t == d; G, s> where resolve(G,Ns{x@i}) = d def solve(C): if <C; {}, {}> --->* <{}; G, s>: return <G, s> else: fail
  • 14. Solver = rewrite system - Rewrite a constraints set + solution - Simplifying and eliminating constraints ‣ Constraint selecting is non-deterministic ‣ Partial order is enforced by side conditions on rewrite rules - Rely on (other) solvers and algorithms for base cases ‣ Unification for term equality ‣ Scope graph resolution - The solution is final if all constraints are eliminated Does the order matter for the outcome? - Confluence: the output is the same for any solving order - Conjecture: Partly true for NaBL2 ‣ Up to variable and scope names ‣ Only if all constraints are reduced Solving by Rewriting !14
  • 16. What is the meaning of constraints? - What is a valid solution? - Or: in which models are the constraints satisfied? - Can we describe this independent of an algorithm?
 When are constraints satisfied? - Formally described by the semantics - Written as G,s ⊨ C - Satisfied in a model (substitution + scope graph) - Describes for every type of constraint when it is satisfied !16 What gives constraints meaning? ty == FUN(ty1,ty2)
 Var{x} |-> d ty1 == INT()
  • 17. Semantics of (a Subset of) NaBL2 Constraints !17 C = t == t // equality | r |-> d // resolution | C / C // conjunction G,s ⊨ t == u G,s ⊨ r |-> d G,s ⊨ C1 / C2 if s(t) = s(u) if s(r) = Var{x @i} and s(d) = Var{x @j} and Var{x @i} resolves to Var{x @j} in G if G,s ⊨ C1 and G,s ⊨ C2 Constraint syntax Constraint semantics
  • 18. Using the Semantics !18 G,s ⊨ t == u if s(t) = s(u) G,s ⊨ r |-> d if s(r) = Var{x @i} and s(d) = Var{x @j} and Var{x @i} resolves to Var{x @j} in G G,s ⊨ C1 / C2 if G,s ⊨ C1 and G,s ⊨ C2 let function f1(x2 : int) : int = x3 + 1 in f4(14) end ty1 == INT() INT() == INT() Var{x @3} |-> d1 ty2 == INT() Var{f @4} |-> d2 ty3 == FUN(ty4,ty5) ty4 == INT() …
 s = { ty1 -> INT(), ty2 -> INT(), ty3 -> FUN(INT(),ty5), ty4 -> INT(), d1 -> Var{x @2}, d2 -> Var{f @1} } s0 s1 f1 FUN(ty1,ty2) x2x3 f4
  • 19. What is the difference? - Algorithm computes a solution (= model) - Semantics describes when a constraint is satisfied by a model How are these related? - Soundness ‣ If the solver returns <G, s>, then G,s ⊨ C - Completeness: ‣ If an s exists such that G,s ⊨ C, then the solver returns it ‣ If no such s exists, the solver fails Principality - The solver finds the most general s !19 Semantics vs Algorithm
  • 20. Term Equality & Unification 20
  • 21. Syntactic Terms !21 INT() FUN(INT(),INT()) f(t0,…,tn) function symbol arity f(t0,…,tn) == g(u0,…,um) if - f = g, and n = m - ti == ui for every i Generic Terms Syntactic Equality terms t, u functions f, g, h arguments
  • 22. Variables and Substitution !22 f(g(),a) terms t, u functions f, g, h variables a, b, c substitution s ground term: a term without variables s = { a -> f(g(),b), b -> h() } domain f(g(),f(g(),b)) s(a) = t if { a -> t } in s s(a) = a otherwise s(f(t0,…,tn)) = f(s(t0),…,s(tn)) variable substitution
  • 23. Unifiers !23 f(a,g()) == f(h(),b) a -> h() b -> g() g(a,f(b)) == g(f(h()),a) a -> f(h()) b -> h() f(a,h()) == g(h(),b) no unifier, f != g terms t, u functions f, g, h variables a, b, c substitution s f(h(),g()) == f(h(),g()) g(f(h()),f(h())) == g(f(h()),f(h())) f(b,b) == b b -> f(b,b) not idempotent unifier: a substitution that makes terms equal
  • 24. Most General Unifiers !24 terms t, u functions f, g, h variables a, b, c substitution s f(a,b) == f(b,c) a -> g() b -> g() c -> g() a -> b c -> b f(g(),g()) == f(g(),g()) f(b,b) == f(b,b) b -> a c -> a f(a,a) == f(a,a)most general unifiers
  • 25. Most General Unifiers !25 a -> g() b -> g() c -> g() a -> b b -> b c -> b a -> a b -> a c -> a a -> b b -> b c -> b terms t, u functions f, g, h variables a, b, c substitution s b -> g() b -> a a -> b b -> b c -> b a -> a b -> a c -> a a -> b every unifier is an instance of a most general unifier (implicit) identity case most general unifiers are related by renaming substitutions
  • 26. global s def unify(t, u): if t is a variable: t := s(t) if u is a variable: u := s(u) if t == u: pass else if t == f(t0,...,tn) and u == g(u0,...,um): if f == g and n == m: for i := 1 to n: unify(ti, ui) else: fail "different function symbols" else if t is not a variable: unify(u, t) else if t occurs in u: fail "recursive term" else: s += { s -> t } Unification !26 terms t, u functions f, g, h variables a, b, c substitution s t == a
 instantiate variable t == k(t0,...,t5), u == k(u0,...,u5)
 matching terms t == k(t0,...,t5), u == f(u0,...,u3)
 mismatching terms t == k(t0,...,t5), u == b
 mismatching terms t == a, u == k(g(a,f()))
 recursive terms t == a, u == k(u0,...,u5)
 extend unifier u == b
 instantiate variable equal terms
  • 27. Unification (rewriting) !X { t == u } U C; s ———> C’ U C; s’
 { t == t } U C; s ———> C; s
 { f(t0,…,tn) == f(u0,…,un) } U C; s ———> { t0 == u0, …, tn == un } U C; s
 { f(t0,…,tn) == g(u0,…,um) } U C; s ———> FAIL if f != g
 { a == t } U C; s ———> C{a -> t}; s{a -> t} if a ∉ vars(t)
 { a == t } U C; s ———> FAIL if a ∈ vars(t)
 { t == a } U C; s ———> { a == t } U C; s equalities rewrite function { f() == f() } {} { f(g()) == f(h()) } { g() == h() } { g(b,a) == g(a,h(b)) } { b == a, a == h(b) } { a == h(a) } { f(g(),h(a)) == f(b,h(b)) } { g() == b, h(a) == h(b) } { b == g(), h(a) == h(b) } { h(a) == h(g()) } { a == g() } {} {} {} {} FAIL {} {b -> a} FAIL {} {} {b -> g()} {b -> g()} {b -> g(),a -> g()} {b -> g(),a -> g()} substitution terms t, u functions f, g, h variables a, b, c substitution s equalities C substitution s
  • 28. Soundness - If the algorithm returns a unifier, it makes the terms equal Completeness - If a unifier exists, the algorithm will return it Principality - If the algorithm returns a unifier, it is a most general unifier Termination - The algorithm always returns a unifier or fails Properties of Unification !27
  • 30. Space complexity - Exponential - Representation of unifier Time complexity - Exponential - Recursive calls on terms Solution - Union-Find algorithm - Complexity growth can be considered constant
 Complexity of Unification !28 h(a1 , …,an , f(b0,b0), …, f(bn-1,bn-1), an) == h(f(a0,a0), …,f(an-1,an-1), b1, …, bn-1 , bn) a1 -> f(a0,a0) a2 -> f(f(a0,a0), f(a0,a0)) ai -> … 2i+1-1 subterms … b1 -> f(a0,a0) b2 -> f(f(a0,a0), f(a0,a0)) bi -> … 2i+1-1 subterms … terms t, u functions f, g, h variables a, b, c substitution s a1 -> f(a0,a0) a2 -> f(a1,a1) ai -> … 3 subterms … b1 -> f(a0,a0) b2 -> f(a1,a1) bi -> … 3 subterms … fully applied triangular
  • 31. Set Representatives !29 FIND(a):
 b := rep(a)
 if b == a:
 return a
 else
 return FIND(b)
 
 
 UNION(a1,a2):
 b1 := FIND(a1)
 b2 := FIND(a2)
 LINK(b1,b2)
 LINK(a1,a2):
 rep(a1) := a2
 
 
 
 
 a == b
 c == a u == w
 v == u
 x == v x == c a b c u w v x representative
  • 32. Path Compression !30 FIND(a): b := rep(a) if b == a: return a else b := FIND(b) rep(a) := b return b UNION(a1,a2):
 b1 := FIND(a1) b2 := FIND(a2) LINK(b1,b2)
 LINK(a1,a2):
 rep(a1) := a2 … x == b x == c x == w x == v a b c u w v x
  • 33. Tree Balancing !31 FIND(a): b := rep(a) if b == a: return a else b := FIND(b) rep(a) := b return b UNION(a1,a2): b1 := FIND(a1) b2 := FIND(a2) LINK(b1,b2)
 LINK(a1,a2):
 if size(a2) > size(a1): rep(a1) := a2 size(a2) += size(a1) else: rep(a2) := a1 size(a1) += size(a2) … x == c a b c u w v x 1 21 4 11 3 3 steps 2 steps ?
  • 34. The Complex Case !32 h(a1 , …,an , f(b0,b0), …, f(bn-1,bn-1), an) == h(f(a0,a0), …,f(an-1,an-1), b1, …, bn-1 , bn) a1 a0 an-1 an b1 b0 bn-1 bn f(a0,a0) f(an-2,an-2) f(an-1,an-1) f(b0,b0) f(bn-2,bn-2) f(bn-1,bn-1) an == bn f(an-1,an-1) == f(bn-1,bn-1) an-1 == bn-1 an-1 == bn-1 f(an-2,an-2) == f(bn-2,bn-2) ⠸ a1 == b1 a1 == b1 f(a0,a0) == f(b0,b0) a0 == b0 a0 == b0 How about occurrence checks? Postpone!
  • 35. Main idea - Represent unifier as graph - One variable represent equivalence class - Replace substitution by union & find operations - Testing equality becomes testing node identity Optimizations - Path compression make recurring lookups fast - Tree balancing keeps paths short Complexity - Linear in space and almost linear in time (technically inverse Ackermann) - Easy to extract triangular unifier from graph - Postpone occurrence checks to prevent traversing (potentially) large terms Union-Find !33 Martelli, Montanari. An Efficient Unification Algorithm. TOPLAS, 1982
  • 37. What is the meaning of constraints? - Formally described by constraint semantics - Semantics classify solutions, but do not compute them - Semantics are expressed in terms of other theories ‣ Syntactic equality ‣ Scope graph resolution What techniques can we use to implements solvers? - Constraint Simplification ‣ Simplification rules ‣ Depends on built-in procedures to unify or resolve names - Unification ‣ Unifiers make terms with variables equal ‣ Unification computes most general unifiers What is the relation between solver and semantics? - Soundness: any solution satisfies the semantics - Completeness: if a solution exists, the solver finds it - Principality: the solver computes most general solutions Summary !35
  • 38. Except where otherwise noted, this work is licensed under