SlideShare a Scribd company logo
1 of 35
Download to read offline
Lecture 8: Type Constraints
CS4200 Compiler Construction
Hendrik van Antwerpen
TU Delft
September 2018
- Type checking with constraints

- The meta-language NaBL2 to write type speciļ¬cations

- Examples of diļ¬€erent name binding and typing patterns in NaBL2

- Deļ¬ning the meaning of constraints with constraint semantics
!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
Type checkers are algorithms that check names and types in programs. 

This paper introduces the NaBL Name Binding Language, which
supports the declarative deļ¬nition of the name binding and scope rules
of programming languages through the deļ¬nition of scopes,
declarations, references, and imports associated.
http://dx.doi.org/10.1007/978-3-642-36089-3_18
SLE 2012
Background
!5
This paper introduces scope graphs as a language-independent
representation for the binding information in programs.
http://dx.doi.org/10.1007/978-3-662-46669-8_9
ESOP 2015
Best EAPLS paper at ETAPS 2015
!6
Separating type checking into constraint generation and
constraint solving provides more declarative deļ¬nition 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
speciļ¬cation language.
https://doi.org/10.1145/2847538.2847543
PEPM 2016
!7
Documentation for NaBL2 at the metaborg.org website.
http://www.metaborg.org/en/latest/source/langdev/meta/lang/nabl2/index.html
!8
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 deļ¬nition 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
Type Checking
with Constraints
9
!10
Source
Code
Editor
Abstract
Syntax
Tree
ErrorsCollect Constraints Solve
Type checking proceeds in two steps
language
specific
language
independent
Parse
What is constraint generation?
- Function that maps a program to constraints

- Deļ¬ned as a top-down traversal, parameters can be passed down

- Speciļ¬cation of what it means to be well-typed!

What are constraints?
- Logical assertions that should hold for well-typed programs

ā€£ Logical variables represent unknown values

- Constraint language determines what assertions can be made

ā€£ Type equality, sub typing, name resolution, ...

- Determines the expressiveness of the speciļ¬cation!

Constraint Solving
- Find an assignment for all logical variables, such that constraints are satisļ¬ed

- More on this next week
!11
Typing Constraints
Challenges for type checker implementations?
- Collecting (non-lexical) binding information before use

- Dealing with unknown (type) values

Constraints separate what from how
- Constraint generator + constraint language says what is a well-typed program

- Constraint solver says how to determine that a program is well-typed

Constraints separate computation from program structure
- Constraint generator follows the structure of the program

- Constraint solver is ļ¬‚exible in order of resolution

Constraint naturally support unknown values
- Variables represent unknown values

- Constraint resolution infers appropriate values
!12
Typing Constraints
NaBL2
13
What is NaBL2?
- Domain-speciļ¬c speciļ¬cation languageā€¦
- ā€¦ to write constraint generators
- Comes with a generic solver
What features does it support?
- Rich binding structures using scope graphs
- Type equality and nominal sub-typing
- Type-dependent name resolution
Limitations
- Restricted to the domain-speciļ¬c (= restricted) model
ā€£ Not all name binding patterns in the wild can be expressed
- Hypothesis is that all sensible patterns are expressible
NaBL2
!14
[[ Let(x, e, e') ^ (s) : t' ]] :=
new s', s' -P-> s,
Var{x} <- s', Var{x} : v,
[[ e ^ (s') : t ]],
v == t,
[[ e' ^ (s') : t' ]].
type (optional)
subterm recursion
constraints
scope parametersmatch pattern
Constraint Rules
!15
Tips for writing correct speciļ¬cations
- Rules have an implicit signature: sort of the matched term, number of scopes, whether it has a type or not
- All rules for terms of a certain sort (e.g., all expression rules) must have the same signature
- All subterm rule invocations must follow the signature of the rules of the subterm sort
- Traverse every term at most once
Scope Graph Constraints
!16
new s // create a new scope
s1 -L-> s2 // edge labeled with L from scope s1 to scope s2
N{x} <- s // x is a declaration in scope s for namespace N
N{x} -> s // x is a reference in scope s for namespace N
N{x} =L=> s // declaration x is associated with scope s
N{x} <=L= s // scope s imports via reference x
N{x} |-> d // reference x resolves to declaration d
[[ e ^ (s) ]] // subterm e is scoped by scoped s
s
s s
N xis
N xi s
N xi s
N xis
N xi N xi
Scope Graph Example
!17
let
var x : int := x + 1
in
x + 1
end
s
s_bodyx
x
Let(
[VarDec(
"x"
, Tid("int")
, Plus(Var("x"), Int("1"))
)]
, [Plus(Var("x"), Int("1"))]
)
[[ Let([VarDec(x, t, e)], [e_body]) ^ (s) ]] :=
new s_body, // new scope
s_body -P-> s, // parent edge to enclosing scope
Var{x} <- s_body, // x is a declaration in s_body
[[ e ^ (s) ]], // init expression
[[ e_body ^ (s_body) ]]. // body expression
[[ Var(x) ^ (s') ]] :=
Var{x} -> s', // x is a reference in s'
Var{x} |-> d, // check that x resolves to a declaration
sā€™
x
?
P
Name Set Constraints & Expressions
!18
distinct S distinct/name S // elements/names in S are distinct
S1 subseteq S2 S1 subseteq/name S2 // elements/names in S1 are a subset of S2
S1 seteq S2 S1 seteq/name S2 // elements/names in S1 are equal to S2
0 // empty set
D(s) D(s)/N // all/namespace N declarations in s
R(s) R(s)/N // all/namespace N references in s
V(s) V(s)/N // visible declarations in s (w/ shadowing)
W(s) W(s)/N // reachable declarations in s (no shadowing)
(S1 union S2) // union of S1 and S2
(S1 isect S2) (S1 isect/name S2) // intersection of elements/names S1 and S2
(S1 lsect S2) (S1 lsect/name S2) // elements/names in S1 that are in S2
(S1 minus S2) (S1 minus/name S2) // elements/names in S1 that are not in S2
Name Set Examples
!19
s0
s1
s2
Var
x1
Var
x2
Type
y5
Type
y3
Var
x4
D(s0)
D(s1)
W(s1)/Var
R(s2)
(W(s1) minus D(s1)/Var)
V(s1)/Var
(R(s1) lsect/name D(s1))
(R(s1) isect/name D(s1))
Type Constraints
!20
ty1 == ty2 // types ty1 and ty2 are equal
ty1 <R! ty2 // declare ty1 to be related to ty2 in R
ty1 <R? ty2 // require ty1 to be related to ty2 in R
.... // ā€¦ extensions ā€¦
d : ty // declaration d has type ty
[[ e ^ (s) : ty ]] // subterm e has type ty
N xi ty
Type Example
!21
s
s_bodyx
x
[[ Let([VarDec(x, t, e)], [e_body]) ^ (s) : ty' ]] :=
new s_body, // new scope
s_body -P-> s, // parent edge to enclosing scope
Var{x} <- s_body, // x is a declaration in s_body
Var{x} : ty, // associate type
[[ t ^ (s) : ty ]], // type of type
[[ e ^ (s) : ty ]], // type of expression
[[ e_body ^ (s_body) : ty' ]]. // constraints for body
[[ Var(x) ^ (s') : ty ]] :=
Var{x} -> s', // x is a reference in s'
Var{x} |-> d, // check that x resolves to a declaration
d : ty. // type of declaration is type of reference
sā€™
x
let
var x : int := x + 1
in
x + 1
end
Let(
[VarDec(
"x"
, Tid("int")
, Plus(Var("x"), Int("1"))
)]
, [Plus(Var("x"), Int("1"))]
)
INT
NaBL2 Conļ¬guration
!22
signature
namespaces
Var
name resolution
labels P I
order D < P, D < I, I < P
well-formedness P* I*
relations
reflexive, transitive, anti-symmetric sub : Type * Type
Tiger in NaBL2
23
Variable Declarations and References
!24
x1x2 s1
Dec[[ VarDec(x, t, e) ^ (s, s_outer) ]] :=
[[ t ^ (s_outer) ]],
[[ e ^ (s_outer) ]],
Var{x} <- s.
[[ Var(x) ^ (s) ]] :=
Var{x} -> s,
Var{x} |-> d.
s0
s1
s0 Let(
[VarDec("x", INT(), Int("1"))]
, [Plus(Var("x"), Int("1"))]
)
let
var x1 : int := 1
in
x2 + 1
end
s0
s1
s2
let
var x1 : int := 0
in
for i2 := 1 to 4 do
x3 := x4 + i5;
x6 * 7
end
Scoping of Loop Variable
!25
s1 x1
s2 i2x3
i5x4
x6
[[ stm@For(Var(x), e1, e2, e3) ^ (s) ]] :=
new s_for,
s_for -P-> s,
Var{x} <- s_for,
Loop{Break()@stm} <- s_for,
[[ e1 ^ (s) ]],
[[ e2 ^ (s) ]],
[[ e3 ^ (s_for) ]].
s0
let
function pow1(b2 : int, n3 : int) : int =
if n4 < 1
then 1
else (b5 * pow6(b7, n8 - 1))
in
pow9(2, 7)
end
s0
s1
Function Declarations and References
!26
[[ FunDec(f, args, t, e) ^ (s, s_outer) ]] :=
Var{f} <- s,
new s_fun,
s_fun -P-> s,
Map2[[ args ^ (s_fun, s_outer) ]],
distinct/name D(s_fun),
[[ e ^ (s_fun) ]].
[[ FArg(x, t) ^ (s_fun, s_outer) ]] :=
Var{x} <- s_fun,
[[ t ^ (s_outer) ]].
[[ Call(f, exps) ^ (s) ]] :=
Var{f} -> s,
Var{f} |-> d,
Map1[[ exps ^ (s) ]].
s2
s0
s1
s2
pow1pow9
b2
n3
n4
b5
n8
b7
pow6
Sequential Let
!27
s2 x1
s3 y2
s1 z4x5
z7
y6
z3
[[ Let(blocks, exps) ^ (s) ]] :=
new s_body,
Decs[[ blocks ^ (s, s_body) ]],
Seq[[ exps ^ (s_body) ]],
distinct D(s_body).
Decs[[ [] ^ (s_outer, s_body) ]] :=
s_body -P-> s_outer.
Decs[[ [block] ^ (s_outer, s_body) ]] :=
s_body -P-> s_outer,
Dec[[ block ^ (s_body, s_outer) ]].
Decs[[ [block | blocks@[_|_]] ^ (s_outer, s_body) ]] :=
new s_dec,
s_dec -P-> s_outer,
Dec[[ block ^ (s_dec, s_outer) ]],
Decs[[ blocks ^ (s_dec, s_body) ]],
distinct/name D(s_dec).
s0
s0
s2
s3
s1
let
var x1 := 2
var y2 := z3 + 11
var z4 := x5 * y6
in z7 end
Mutually Recursive Functions
!28
s1 odd1 even6
s2
s3
even11
x2
x7odd9
even4
x3
x8
Dec[[ FunDecs(fdecs) ^ (s, s_outer) ]] :=
Map2[[ fdecs ^ (s, s_outer) ]].
[[ FunDec(f, args, t, e) ^ (s, s_outer) ]] :=
new s_fun,
s_fun -P-> s,
distinct/name D(s_fun),
MapTs2[[ args ^ (s_fun, s_outer) ]],
s0
s0
s1
s2
s3
x5
x10
let
function odd1(x2 : int) : int =
if x3 > 0 then even4(x5-1) else 0
function even6(x7 : int) : int =
if x8 > 0 then odd9(x10-1) else 1
in
even11(34)
end
Namespaces
!29
s1
s2
Type
foo1
Var
foo2
Type
foo4
Var
foo5
s3
Var
x3
Var
x6
[[ TypeDec(x, t) ^ (s) ]] :=
[[ t ^ (s) ]],
Type{x} <- s.
[[ VarDec(x, t, e) ^ (s, s_outer) ]] :=
[[ t ^ (s_outer) ]],
[[ e ^ (s_outer) ]],
Var{x} <- s.
s0
s0
s1
s2
s3
let
type foo1 = int
var foo2 : int := 24
var x3 : foo4 := foo5
in
x6
end
Explicit versus Inferred Variable Type
!30
let
var x : int := 20 + 1
var y := 21
in
x + y
end
[[ VarDec(x, t, e) ^ (s, s_outer) ]] :=
[[ t ^ (s_outer) : ty1 ]],
[[ e ^ (s_outer) : ty2 ]],
ty2 <? ty1,
Var{x} <- s,
Var{x} : ty1 !.
[[ VarDecNoType(x, e) ^ (s, s_outer) ]] :=
[[ e ^ (s_outer) : ty ]],
ty != NIL(),
Var{x} <- s,
Var{x} : ty !.
let
type point1 = { x2 : int, y3 : int }
var p4 := point5{ x6 = 4, y7 = 5 }
in
p8.x9
end
s3
Record Deļ¬nitions
!31
[[ 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
!32
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
!33
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
Full Tiger Speciļ¬cation Online
!34
https://github.com/MetaBorgCube/metaborg-tiger
https://github.com/MetaBorgCube/metaborg-tiger/blob/master/org.metaborg.lang.tiger/trans/static-semantics/static-semantics.nabl2
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 DefinitionEelco Visser
Ā 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersEelco Visser
Ā 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionEelco 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 ServicesEelco Visser
Ā 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type CheckingEelco Visser
Ā 
Declare Your Language: Name Resolution
Declare Your Language: Name ResolutionDeclare Your Language: Name Resolution
Declare Your Language: Name ResolutionEelco 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 RewritingEelco Visser
Ā 
Programming languages
Programming languagesProgramming languages
Programming languagesEelco Visser
Ā 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)Sami Said
Ā 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingGuido Wachsmuth
Ā 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Eelco Visser
Ā 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesEelco Visser
Ā 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bisonvip_du
Ā 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesGuido Wachsmuth
Ā 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flexvip_du
Ā 
C++ Language
C++ LanguageC++ Language
C++ LanguageVidyacenter
Ā 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQIntro C# Book
Ā 

What's hot (20)

Declare Your Language: Syntax Definition
Declare Your Language: Syntax DefinitionDeclare Your Language: Syntax Definition
Declare Your Language: Syntax Definition
Ā 
Compiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | InterpretersCompiler Construction | Lecture 14 | Interpreters
Compiler Construction | Lecture 14 | Interpreters
Ā 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Ā 
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
Ā 
Declare Your Language: Type Checking
Declare Your Language: Type CheckingDeclare Your Language: Type Checking
Declare Your Language: Type Checking
Ā 
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
Ā 
Programming languages
Programming languagesProgramming languages
Programming languages
Ā 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
Ā 
Lex (lexical analyzer)
Lex (lexical analyzer)Lex (lexical analyzer)
Lex (lexical analyzer)
Ā 
Declarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term RewritingDeclarative Semantics Definition - Term Rewriting
Declarative Semantics Definition - Term Rewriting
Ā 
Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing Compiler Construction | Lecture 4 | Parsing
Compiler Construction | Lecture 4 | Parsing
Ā 
Declare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) ServicesDeclare Your Language: Syntactic (Editor) Services
Declare Your Language: Syntactic (Editor) Services
Ā 
Introduction of bison
Introduction of bisonIntroduction of bison
Introduction of bison
Ā 
Introduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented LanguagesIntroduction - Imperative and Object-Oriented Languages
Introduction - Imperative and Object-Oriented Languages
Ā 
Introduction of flex
Introduction of flexIntroduction of flex
Introduction of flex
Ā 
LEX & YACC TOOL
LEX & YACC TOOLLEX & YACC TOOL
LEX & YACC TOOL
Ā 
Antlr V3
Antlr V3Antlr V3
Antlr V3
Ā 
C++ Language
C++ LanguageC++ Language
C++ Language
Ā 
Chapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQChapter 22. Lambda Expressions and LINQ
Chapter 22. Lambda Expressions and LINQ
Ā 

Similar to Compiler Construction | Lecture 8 | Type Constraints

Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory buildingClarkTony
Ā 
Decaf language specification
Decaf language specificationDecaf language specification
Decaf language specificationSami Said
Ā 
Declare Your Language (at DLS)
Declare Your Language (at DLS)Declare Your Language (at DLS)
Declare Your Language (at DLS)Eelco Visser
Ā 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminZoumanaDiomande1
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxmonicafrancis71118
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxcargillfilberto
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxdrandy1
Ā 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginnersAbishek Purushothaman
Ā 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Guy Lebanon
Ā 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
Ā 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
Ā 
Compilers Design
Compilers DesignCompilers Design
Compilers DesignAkshaya Arunan
Ā 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)bolovv
Ā 
Programming in Scala - Lecture Three
Programming in Scala - Lecture ThreeProgramming in Scala - Lecture Three
Programming in Scala - Lecture ThreeAngelo Corsaro
Ā 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awkYogesh Sawant
Ā 

Similar to Compiler Construction | Lecture 8 | Type Constraints (20)

Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory building
Ā 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Ā 
Compiler notes--unit-iii
Compiler notes--unit-iiiCompiler notes--unit-iii
Compiler notes--unit-iii
Ā 
Decaf language specification
Decaf language specificationDecaf language specification
Decaf language specification
Ā 
Declare Your Language (at DLS)
Declare Your Language (at DLS)Declare Your Language (at DLS)
Declare Your Language (at DLS)
Ā 
awkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux adminawkbash quick ref for Red hat Linux admin
awkbash quick ref for Red hat Linux admin
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Ā 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
Ā 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Ā 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
Ā 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
Ā 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
Ā 
Syntaxdirected
SyntaxdirectedSyntaxdirected
Syntaxdirected
Ā 
Syntaxdirected (1)
Syntaxdirected (1)Syntaxdirected (1)
Syntaxdirected (1)
Ā 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
Ā 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
Ā 
Chapter Two(1)
Chapter Two(1)Chapter Two(1)
Chapter Two(1)
Ā 
Programming in Scala - Lecture Three
Programming in Scala - Lecture ThreeProgramming in Scala - Lecture Three
Programming in Scala - Lecture Three
Ā 
Learning sed and awk
Learning sed and awkLearning sed and awk
Learning sed and awk
Ā 

More from Eelco Visser

CS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionCS4200 2019 Lecture 1: Introduction
CS4200 2019 Lecture 1: IntroductionEelco 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 RulesEelco 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 ConstructionEelco 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 ManagementEelco Visser
Ā 
Compiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationCompiler Construction | Lecture 13 | Code Generation
Compiler Construction | Lecture 13 | Code GenerationEelco Visser
Ā 
Compiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksCompiler Construction | Lecture 11 | Monotone Frameworks
Compiler Construction | Lecture 11 | Monotone FrameworksEelco 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 AnalysisEelco Visser
Ā 
Compiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingCompiler Construction | Lecture 7 | Type Checking
Compiler Construction | Lecture 7 | Type CheckingEelco 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 AnalysisEelco 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 GenerationEelco Visser
Ā 
Declare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsDeclare Your Language: Dynamic Semantics
Declare Your Language: Dynamic SemanticsEelco Visser
Ā 
Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Declare Your Language: Constraint Resolution 2
Declare Your Language: Constraint Resolution 2Eelco Visser
Ā 
Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Eelco 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 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
Ā 
Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1Declare Your Language: Constraint Resolution 1
Declare Your Language: Constraint Resolution 1
Ā 

Recently uploaded

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
Ā 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
Ā 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
Ā 
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)jennyeacort
Ā 
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024StefanoLambiase
Ā 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
Ā 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
Ā 
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...soniya singh
Ā 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
Ā 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
Ā 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
Ā 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
Ā 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
Ā 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
Ā 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
Ā 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
Ā 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
Ā 
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1åˆ¶ä½œč‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作qr0udbr0
Ā 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
Ā 

Recently uploaded (20)

CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
Ā 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
Ā 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
Ā 
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)
Call UsšŸ”>ą¼’+91-9711147426ā‡›Call In girls karol bagh (Delhi)
Ā 
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024
Dealing with Cultural Dispersion ā€” Stefano Lambiase ā€” ICSE-SEIS 2024
Ā 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
Ā 
2.pdf Ejercicios de programaciĆ³n competitiva
2.pdf Ejercicios de programaciĆ³n competitiva2.pdf Ejercicios de programaciĆ³n competitiva
2.pdf Ejercicios de programaciĆ³n competitiva
Ā 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
Ā 
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Ā 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
Ā 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Ā 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
Ā 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Ā 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
Ā 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
Ā 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
Ā 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
Ā 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
Ā 
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1åˆ¶ä½œč‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作
č‹±å›½UN学位čƁ,åŒ—å®‰ę™®é”æ大学ęƕäøščƁ书1:1制作
Ā 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
Ā 

Compiler Construction | Lecture 8 | Type Constraints

  • 1. Lecture 8: Type Constraints CS4200 Compiler Construction Hendrik van Antwerpen TU Delft September 2018
  • 2. - Type checking with constraints - The meta-language NaBL2 to write type speciļ¬cations - Examples of diļ¬€erent name binding and typing patterns in NaBL2 - Deļ¬ning the meaning of constraints with constraint semantics !2 This lecture Source Code Editor Abstract Syntax Tree ErrorsCollect Constraints SolveParse
  • 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 Type checkers are algorithms that check names and types in programs. This paper introduces the NaBL Name Binding Language, which supports the declarative deļ¬nition of the name binding and scope rules of programming languages through the deļ¬nition of scopes, declarations, references, and imports associated. http://dx.doi.org/10.1007/978-3-642-36089-3_18 SLE 2012 Background
  • 5. !5 This paper introduces scope graphs as a language-independent representation for the binding information in programs. http://dx.doi.org/10.1007/978-3-662-46669-8_9 ESOP 2015 Best EAPLS paper at ETAPS 2015
  • 6. !6 Separating type checking into constraint generation and constraint solving provides more declarative deļ¬nition 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 speciļ¬cation language. https://doi.org/10.1145/2847538.2847543 PEPM 2016
  • 7. !7 Documentation for NaBL2 at the metaborg.org website. http://www.metaborg.org/en/latest/source/langdev/meta/lang/nabl2/index.html
  • 8. !8 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 deļ¬nition 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
  • 10. !10 Source Code Editor Abstract Syntax Tree ErrorsCollect Constraints Solve Type checking proceeds in two steps language specific language independent Parse
  • 11. What is constraint generation? - Function that maps a program to constraints - Deļ¬ned as a top-down traversal, parameters can be passed down - Speciļ¬cation of what it means to be well-typed! What are constraints? - Logical assertions that should hold for well-typed programs ā€£ Logical variables represent unknown values - Constraint language determines what assertions can be made ā€£ Type equality, sub typing, name resolution, ... - Determines the expressiveness of the speciļ¬cation! Constraint Solving - Find an assignment for all logical variables, such that constraints are satisļ¬ed - More on this next week !11 Typing Constraints
  • 12. Challenges for type checker implementations? - Collecting (non-lexical) binding information before use - Dealing with unknown (type) values Constraints separate what from how - Constraint generator + constraint language says what is a well-typed program - Constraint solver says how to determine that a program is well-typed Constraints separate computation from program structure - Constraint generator follows the structure of the program - Constraint solver is ļ¬‚exible in order of resolution Constraint naturally support unknown values - Variables represent unknown values - Constraint resolution infers appropriate values !12 Typing Constraints
  • 14. What is NaBL2? - Domain-speciļ¬c speciļ¬cation languageā€¦ - ā€¦ to write constraint generators - Comes with a generic solver What features does it support? - Rich binding structures using scope graphs - Type equality and nominal sub-typing - Type-dependent name resolution Limitations - Restricted to the domain-speciļ¬c (= restricted) model ā€£ Not all name binding patterns in the wild can be expressed - Hypothesis is that all sensible patterns are expressible NaBL2 !14
  • 15. [[ Let(x, e, e') ^ (s) : t' ]] := new s', s' -P-> s, Var{x} <- s', Var{x} : v, [[ e ^ (s') : t ]], v == t, [[ e' ^ (s') : t' ]]. type (optional) subterm recursion constraints scope parametersmatch pattern Constraint Rules !15 Tips for writing correct speciļ¬cations - Rules have an implicit signature: sort of the matched term, number of scopes, whether it has a type or not - All rules for terms of a certain sort (e.g., all expression rules) must have the same signature - All subterm rule invocations must follow the signature of the rules of the subterm sort - Traverse every term at most once
  • 16. Scope Graph Constraints !16 new s // create a new scope s1 -L-> s2 // edge labeled with L from scope s1 to scope s2 N{x} <- s // x is a declaration in scope s for namespace N N{x} -> s // x is a reference in scope s for namespace N N{x} =L=> s // declaration x is associated with scope s N{x} <=L= s // scope s imports via reference x N{x} |-> d // reference x resolves to declaration d [[ e ^ (s) ]] // subterm e is scoped by scoped s s s s N xis N xi s N xi s N xis N xi N xi
  • 17. Scope Graph Example !17 let var x : int := x + 1 in x + 1 end s s_bodyx x Let( [VarDec( "x" , Tid("int") , Plus(Var("x"), Int("1")) )] , [Plus(Var("x"), Int("1"))] ) [[ Let([VarDec(x, t, e)], [e_body]) ^ (s) ]] := new s_body, // new scope s_body -P-> s, // parent edge to enclosing scope Var{x} <- s_body, // x is a declaration in s_body [[ e ^ (s) ]], // init expression [[ e_body ^ (s_body) ]]. // body expression [[ Var(x) ^ (s') ]] := Var{x} -> s', // x is a reference in s' Var{x} |-> d, // check that x resolves to a declaration sā€™ x ? P
  • 18. Name Set Constraints & Expressions !18 distinct S distinct/name S // elements/names in S are distinct S1 subseteq S2 S1 subseteq/name S2 // elements/names in S1 are a subset of S2 S1 seteq S2 S1 seteq/name S2 // elements/names in S1 are equal to S2 0 // empty set D(s) D(s)/N // all/namespace N declarations in s R(s) R(s)/N // all/namespace N references in s V(s) V(s)/N // visible declarations in s (w/ shadowing) W(s) W(s)/N // reachable declarations in s (no shadowing) (S1 union S2) // union of S1 and S2 (S1 isect S2) (S1 isect/name S2) // intersection of elements/names S1 and S2 (S1 lsect S2) (S1 lsect/name S2) // elements/names in S1 that are in S2 (S1 minus S2) (S1 minus/name S2) // elements/names in S1 that are not in S2
  • 19. Name Set Examples !19 s0 s1 s2 Var x1 Var x2 Type y5 Type y3 Var x4 D(s0) D(s1) W(s1)/Var R(s2) (W(s1) minus D(s1)/Var) V(s1)/Var (R(s1) lsect/name D(s1)) (R(s1) isect/name D(s1))
  • 20. Type Constraints !20 ty1 == ty2 // types ty1 and ty2 are equal ty1 <R! ty2 // declare ty1 to be related to ty2 in R ty1 <R? ty2 // require ty1 to be related to ty2 in R .... // ā€¦ extensions ā€¦ d : ty // declaration d has type ty [[ e ^ (s) : ty ]] // subterm e has type ty N xi ty
  • 21. Type Example !21 s s_bodyx x [[ Let([VarDec(x, t, e)], [e_body]) ^ (s) : ty' ]] := new s_body, // new scope s_body -P-> s, // parent edge to enclosing scope Var{x} <- s_body, // x is a declaration in s_body Var{x} : ty, // associate type [[ t ^ (s) : ty ]], // type of type [[ e ^ (s) : ty ]], // type of expression [[ e_body ^ (s_body) : ty' ]]. // constraints for body [[ Var(x) ^ (s') : ty ]] := Var{x} -> s', // x is a reference in s' Var{x} |-> d, // check that x resolves to a declaration d : ty. // type of declaration is type of reference sā€™ x let var x : int := x + 1 in x + 1 end Let( [VarDec( "x" , Tid("int") , Plus(Var("x"), Int("1")) )] , [Plus(Var("x"), Int("1"))] ) INT
  • 22. NaBL2 Conļ¬guration !22 signature namespaces Var name resolution labels P I order D < P, D < I, I < P well-formedness P* I* relations reflexive, transitive, anti-symmetric sub : Type * Type
  • 24. Variable Declarations and References !24 x1x2 s1 Dec[[ VarDec(x, t, e) ^ (s, s_outer) ]] := [[ t ^ (s_outer) ]], [[ e ^ (s_outer) ]], Var{x} <- s. [[ Var(x) ^ (s) ]] := Var{x} -> s, Var{x} |-> d. s0 s1 s0 Let( [VarDec("x", INT(), Int("1"))] , [Plus(Var("x"), Int("1"))] ) let var x1 : int := 1 in x2 + 1 end
  • 25. s0 s1 s2 let var x1 : int := 0 in for i2 := 1 to 4 do x3 := x4 + i5; x6 * 7 end Scoping of Loop Variable !25 s1 x1 s2 i2x3 i5x4 x6 [[ stm@For(Var(x), e1, e2, e3) ^ (s) ]] := new s_for, s_for -P-> s, Var{x} <- s_for, Loop{Break()@stm} <- s_for, [[ e1 ^ (s) ]], [[ e2 ^ (s) ]], [[ e3 ^ (s_for) ]]. s0
  • 26. let function pow1(b2 : int, n3 : int) : int = if n4 < 1 then 1 else (b5 * pow6(b7, n8 - 1)) in pow9(2, 7) end s0 s1 Function Declarations and References !26 [[ FunDec(f, args, t, e) ^ (s, s_outer) ]] := Var{f} <- s, new s_fun, s_fun -P-> s, Map2[[ args ^ (s_fun, s_outer) ]], distinct/name D(s_fun), [[ e ^ (s_fun) ]]. [[ FArg(x, t) ^ (s_fun, s_outer) ]] := Var{x} <- s_fun, [[ t ^ (s_outer) ]]. [[ Call(f, exps) ^ (s) ]] := Var{f} -> s, Var{f} |-> d, Map1[[ exps ^ (s) ]]. s2 s0 s1 s2 pow1pow9 b2 n3 n4 b5 n8 b7 pow6
  • 27. Sequential Let !27 s2 x1 s3 y2 s1 z4x5 z7 y6 z3 [[ Let(blocks, exps) ^ (s) ]] := new s_body, Decs[[ blocks ^ (s, s_body) ]], Seq[[ exps ^ (s_body) ]], distinct D(s_body). Decs[[ [] ^ (s_outer, s_body) ]] := s_body -P-> s_outer. Decs[[ [block] ^ (s_outer, s_body) ]] := s_body -P-> s_outer, Dec[[ block ^ (s_body, s_outer) ]]. Decs[[ [block | blocks@[_|_]] ^ (s_outer, s_body) ]] := new s_dec, s_dec -P-> s_outer, Dec[[ block ^ (s_dec, s_outer) ]], Decs[[ blocks ^ (s_dec, s_body) ]], distinct/name D(s_dec). s0 s0 s2 s3 s1 let var x1 := 2 var y2 := z3 + 11 var z4 := x5 * y6 in z7 end
  • 28. Mutually Recursive Functions !28 s1 odd1 even6 s2 s3 even11 x2 x7odd9 even4 x3 x8 Dec[[ FunDecs(fdecs) ^ (s, s_outer) ]] := Map2[[ fdecs ^ (s, s_outer) ]]. [[ FunDec(f, args, t, e) ^ (s, s_outer) ]] := new s_fun, s_fun -P-> s, distinct/name D(s_fun), MapTs2[[ args ^ (s_fun, s_outer) ]], s0 s0 s1 s2 s3 x5 x10 let function odd1(x2 : int) : int = if x3 > 0 then even4(x5-1) else 0 function even6(x7 : int) : int = if x8 > 0 then odd9(x10-1) else 1 in even11(34) end
  • 29. Namespaces !29 s1 s2 Type foo1 Var foo2 Type foo4 Var foo5 s3 Var x3 Var x6 [[ TypeDec(x, t) ^ (s) ]] := [[ t ^ (s) ]], Type{x} <- s. [[ VarDec(x, t, e) ^ (s, s_outer) ]] := [[ t ^ (s_outer) ]], [[ e ^ (s_outer) ]], Var{x} <- s. s0 s0 s1 s2 s3 let type foo1 = int var foo2 : int := 24 var x3 : foo4 := foo5 in x6 end
  • 30. Explicit versus Inferred Variable Type !30 let var x : int := 20 + 1 var y := 21 in x + y end [[ VarDec(x, t, e) ^ (s, s_outer) ]] := [[ t ^ (s_outer) : ty1 ]], [[ e ^ (s_outer) : ty2 ]], ty2 <? ty1, Var{x} <- s, Var{x} : ty1 !. [[ VarDecNoType(x, e) ^ (s, s_outer) ]] := [[ e ^ (s_outer) : ty ]], ty != NIL(), Var{x} <- s, Var{x} : ty !.
  • 31. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s3 Record Deļ¬nitions !31 [[ 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
  • 32. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s1 Record Creation !32 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)
  • 33. let type point1 = { x2 : int, y3 : int } var p4 := point5{ x6 = 4, y7 = 5 } in p8.x9 end s1 Record Field Access !33 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
  • 34. Full Tiger Speciļ¬cation Online !34 https://github.com/MetaBorgCube/metaborg-tiger https://github.com/MetaBorgCube/metaborg-tiger/blob/master/org.metaborg.lang.tiger/trans/static-semantics/static-semantics.nabl2
  • 35. Except where otherwise noted, this work is licensed under