zvonimir*pavlinovic*(new*york*university)*zvonimir/posters/pldi14.pdf ·...
TRANSCRIPT
-
Compilers consider only a single poten2al error source. Therefore, type error reports are o9en not useful. Be;er: rank error sources by some useful criterion and then show the top ranked sources to the programmer.
Compilers provide a ranking criterion to prefer type error sources of par2cular interest. A ranking criterion assigns weights to program expressions. A smaller weight indicates that the expression more likely contributes to the error. For example, to prefer error sources that require fewer correc2ons, assign a weight equal to the expression’s size.
a hole expression represen2ng a generic fix
Compiler
Typing Constraint Genera2on
Weighted MaxSMT Solver
input program and ranking criterion
constraint
minimum error source
How? Reduce the problem to weighted maximum sa2sfiability modulo theories (MaxSMT). We propose a general framework for type error localiza2on using constraint solving.
A general framework for type error localiza2on that • abstracts from the par2cular ranking criterion • supports various type systems by appropriately instan2a2ng the SMT solver • requires no substan2al compiler modifica2ons due to use of SMT solvers
each proposi2onal variable is a so9 clause with the weight that the given ranking criterion assigns to the corresponding program expression
let x = "hi" in not x
The constraint genera2on is done using typing rules. The constraint for our running example is as follows.
5 1 3 1 1
weighted MaxSMT solu2on
Finding Minimum Type Error Sources Zvonimir Pavlinovic (New York University)
OCaml: This expression has type ‘a list but an expression was expected of type unit
Error source: a set of program expressions that, once corrected, yield a well-‐typed program.
(not well-‐typed)
Finding minimum type error sources problem: given an input program and a compiler-‐provided ranking criterion, find a minimum error source subject to the criterion.
Minimum error source: an error source of minimum cumula2ve weight.
let x = "hi" in not x
?
Tlet
=) ( ↵let
= ↵o
^
Tnot
=) ↵not
= ↵app
^
Tx
=) ↵x
= string ^Tapp
=) ( ↵app
= fun(↵i
,↵o
) ^
Ti
=) ↵i
= ↵x
)) ^
hard clause encoding the structure of the program
1
A generated constraint is unsa2sfiable iff there is a type error in the input program. For instance, the above constraint is unsa2sfiable.
Generated typing constraint is passed to the weighted MaxSMT solver.
ST ^ Tlet
^ Tx
^ Tapp
^ Tnot
^ Ti
^ Tnot impl
5 1 3 1 1 1 h
ST ^ Tlet
^ Tx
^ Tapp
^ Tnot
^ Ti
^ Tnot impl
complement represents a minimum error source
ST ^ Tlet
^ Tx
^ Tapp
^ Tnot
^ Ti
^ Tnot impl
let x = "hi" in not x?
• Framework instan2ated for a subset of OCaml (Hindley-‐Milner type system) • Typing constraint generated using the EasyOCaml system • Weighted MaxSMT solver implemented using CVC4 and Sat4j • Implementa2on evaluated on ~350 OCaml scripts from [Lerner et al., ‘07]
sehng a proposi2onal variable to false has the effect of replacing the corresponding expression with a hole
0
50
100
150
200
250
300
350
0-‐50 (47)
50-‐100 (102)
100-‐150 (65)
150-‐200 (57)
200-‐250 (53)
250-‐300 (28)
300-‐350 (3)
350-‐400 (1)
max
min
median
seconds
program size in loc
(2) (2) (3) (1)
let f(lst:move list): (float*float) list =
...
let rec loop lst x y dir acc =
if lst = [] then
acc
else
print_string "foo"
in
List.rev
(loop lst 0.0 0.0 0.0 [(0.0 ,0.0)])
other poten2al error sources
Let S and H be two sets of clauses over some fixed first-‐order theory where each clause from S is assigned a weight. The weighted MaxSMT problem is to find a subset N of S with maximum cumula2ve weight such that N∧H is sa2sfiable. The clauses in S are referred to as so9 clauses, and the clauses in H hard clauses.
ST ⌘
ST ^ Tlet
^ Tx
^ Tapp
^ Tnot
^ Ti
^ Tnot impl
Tnot impl
=) ↵not
= fun(bool, bool)
h