Zvonimir Pavlinovic Tim King Thomas Wies New York University An example Rank error sources by some criterion Report top ranked sources to the programmer x int ID: 343282
Download Presentation The PPT/PDF document "Finding Minimum Type Error Sources" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Finding Minimum Type Error Sources
Zvonimir
Pavlinovic
Tim King Thomas
Wies
New York UniversitySlide2
An example
Rank error sources by some criterion
Report top ranked sources to the programmer
x:
int
list
p
rint_string
: string -> unitSlide3
Another example
[Zhang & Myers,
POPL ‘14
]
Error: This expression has type ‘a list but an expression was expected of type unitSlide4
Solutions?
Previous research attempts:
s
lice of type inference deduction [Wand `86, Duggan & Bent `95]program slice involved in error
[Tip & Dinesh `01, Gast `05]specially crafted type systems
[Chitil `01, Neubauer & Thiemann `03, Chen & Erwig `
14]Drawbacks:focus on a single ranking criterionfocus on a specific type systemsubstantial compiler modificationsSlide5
Challenge
Can we enable compilers localize type errors
abstracting from a specific ranking criterion
for various type systemswith modest compiler modifications?In this work: general framework for type error localization using constraint solvingSlide6
Definitions
?
Error Source
An error source is a set of program expressions that, once corrected, yield a well-typed programSlide7
Definitions
Rank sources by some
useful
criterionby assigning weights to expressionspositive weights: minimum error sources are also minimal
?
Minimum Error Source
An error source with minimum cumulative weightSlide8
Ranking criteria - example
Prefer error sources requiring fewer corrections?
a
ssign weights equal to expression’s AST size
? (1)
? (1)
? (3)
? (1)
? (5)Slide9
Problem definition
How?
search through all hole versions of an input program
reduction to constraint solving: weighted maximum satisfiability
modulo theories
Computing Minimum Error SourcesGiven a program and a compiler-provided ranking criterion, find a minimum error source subject to the criterionSlide10
Framework
Support for various type systems due to SMT
Modest compiler modifications
Fast prototyping of new ranking criteria
Compiler
Typing Constraint
Generation
Weighted MaxSMTSolver
i
nput program and
r
anking criterion
constraint
m
inimum error
sourcesSlide11
Weighted MaxSMT
Input:
hard clauses must holdsoft clauseseach clause assigned a weight
each clause belongs to a fixed first-order theoryalgebraic data types, linear integer arithmetic, …
Output:A satisfiable subset of soft clauses with maximum cumulative weight (hard clauses must hold)Slide12
Encoding
?Slide13
Supported Type Systems
Already supported
Hindley
-Milnerstructural subtyping (OCaml)tagged unionsFuture workliquid types [
Rondon, Kawaguchi, and Jhala, `08]generalized algebraic data types [Jones et al., `07]
Scala [Gvero et al., `11]Slide14
Implementation
Subset of
OCaml
(Caml)Hindley-Milner type systemConstraint generation using EasyOCaml
constraint encoded in the theory of inductive data typesWeighted MaxSMT procedures using Sat4j and CVC4c
irca 500 Java lines of codeEvaluation on ~350 programs from [Lerner et al., `07]Slide15
Type inference
Typing relation
Type checking
via type inference: infer types of program expressions based on how they are usedSlide16
Reduction to constraint solvingSlide17
Constraint generation formally
Constraint generation done using typing rulesSlide18
Constraint sizeSlide19
Complexity
EXP-complete [
Mairson
`90, Kfoury et al. `90]Slide20
PolymorphismSlide21
Polymorphism blow-up
Copying assertions leads to a blow-up
a common problem in constraint-based type inference
Can we tame the blow-up?Lazy quantifier-based instantiationLazy unification-based instantiationSlide22
Lazy quantifier-based instantiation
s
et as a hard assertionSlide23
Lazy quantifier-based instantiation
Solver lazily instantiates predicates
s
ome instantiations might get avoided due to search pruningIn worst case all predicates instantiatedPossible fix?lazy unification-based instantiationSlide24
Lazy unification-based instantiation
Freshly instantiate
mgu
for each function usageRecursively compute minimum error source for function definitionIterative algorithm --- multiple SMT calls
but all assertion sets lazily instantiated
mguSlide25
Conclusions
General framework for type error localization
b
ased on constraint solving using weighted MaxSMT proceduressupports various type systems due to SMTmodest compiler modificationsabstracts from ranking
criteria - fast prototyping
Thank you!