Finding Minimum Type Error Sources Zvonimir Pavlinovic - - PowerPoint PPT Presentation

finding minimum type error sources
SMART_READER_LITE
LIVE PREVIEW

Finding Minimum Type Error Sources Zvonimir Pavlinovic - - PowerPoint PPT Presentation

Finding Minimum Type Error Sources Zvonimir Pavlinovic Tim King Thomas Wies New York University


slide-1
SLIDE 1

Finding ¡Minimum ¡Type ¡ Error ¡Sources ¡

¡Zvonimir ¡Pavlinovic ¡ ¡ ¡ ¡ ¡Tim ¡King ¡ ¡ ¡ ¡ ¡Thomas ¡Wies ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡New ¡York ¡University ¡

slide-2
SLIDE 2

Motivating ¡example ¡

¡

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)])

[Zhang ¡& ¡Myers, ¡POPL ¡‘14] ¡

Error: ¡This ¡expression ¡has ¡type ¡‘a ¡list ¡but ¡an ¡expression ¡was ¡ expected ¡of ¡type ¡unit ¡ print_string: ¡string ¡-­‑> ¡unit ¡

slide-3
SLIDE 3

Problem? ¡

  • Type ¡error ¡reports ¡oPen ¡not ¡helpful ¡
  • increased ¡debugging ¡Qme ¡
  • difficult ¡to ¡learn ¡a ¡language ¡by ¡novice ¡programmers ¡
  • How ¡to ¡improve? ¡
  • consider ¡all ¡error ¡sources ¡
  • rank ¡them ¡by ¡some ¡useful ¡criterion ¡
  • report ¡top ¡ranked ¡sources ¡to ¡the ¡programmer ¡
slide-4
SLIDE 4

Solutions? ¡

  • Previous ¡research ¡aUempts: ¡
  • slice ¡of ¡type ¡inference ¡deducQon ¡ ¡[Wand ¡`86, ¡Duggan ¡& ¡

Bent ¡`95] ¡

  • program ¡slice ¡involved ¡in ¡error ¡ ¡[Tip ¡& ¡Dinesh ¡`01, ¡Gast ¡`05] ¡
  • specially ¡craPed ¡type ¡systems ¡ ¡[ChiQl ¡`01, ¡Neubauer ¡& ¡ ¡ ¡ ¡

Thiemann ¡`03, ¡Chen ¡& ¡Erwig ¡`14] ¡

  • Drawbacks: ¡
  • focus ¡on ¡a ¡single ¡ranking ¡criterion ¡
  • focus ¡on ¡a ¡specific ¡type ¡system ¡
  • substanQal ¡compiler ¡modificaQons ¡
slide-5
SLIDE 5

Challenge ¡

  • Can ¡we ¡enable ¡compilers ¡localize ¡type ¡errors ¡
  • abstracQng ¡from ¡a ¡specific ¡ranking ¡criterion ¡
  • for ¡various ¡type ¡systems ¡
  • with ¡modest ¡compiler ¡modificaQons? ¡
  • In ¡this ¡work: ¡general ¡framework ¡for ¡type ¡error ¡

localiza3on ¡using ¡constraint ¡solving ¡

slide-6
SLIDE 6

De?initions ¡

let x = "hi" in not x

? ¡ Error ¡Source ¡

¡

An ¡error ¡source ¡is ¡a ¡set ¡of ¡program ¡expressions ¡that, ¡

  • nce ¡corrected, ¡yield ¡a ¡well-­‑typed ¡program ¡
slide-7
SLIDE 7

De?initions ¡

  • Rank ¡sources ¡by ¡some ¡useful ¡criterion ¡
  • by ¡ ¡assigning ¡weights ¡to ¡expressions ¡

let x = "hi" in not x

? ¡ Minimum ¡Error ¡Source ¡

¡

An ¡error ¡source ¡with ¡minimum ¡cumula3ve ¡weight ¡

slide-8
SLIDE 8

Ranking ¡criteria ¡-­‑ ¡example ¡

  • Prefer ¡error ¡sources ¡requiring ¡fewer ¡correcQons? ¡
  • assign ¡weights ¡equal ¡to ¡expression’s ¡AST ¡size ¡

let x = "hi" in not x

? ¡(1) ¡ ? ¡(1) ¡ ? ¡(3) ¡ ? ¡(1) ¡ ? ¡(5) ¡

slide-9
SLIDE 9

Problem ¡de?inition ¡

  • How? ¡
  • search ¡through ¡all ¡hole ¡versions ¡of ¡an ¡input ¡program ¡
  • reducQon ¡to ¡constraint ¡solving: ¡weighted ¡maximum ¡

sa3sfiability ¡modulo ¡theories ¡ Compu/ng ¡Minimum ¡Error ¡Sources ¡

¡

Given ¡a ¡program ¡and ¡a ¡compiler-­‑provided ¡ranking ¡ criterion, ¡find ¡a ¡minimum ¡error ¡source ¡subject ¡to ¡ the ¡criterion ¡

slide-10
SLIDE 10

Framework ¡

  • Support ¡for ¡various ¡type ¡systems ¡due ¡to ¡SMT ¡
  • Modest ¡compiler ¡modificaQons ¡
  • Abstracts ¡from ¡specific ¡ranking ¡criteria ¡

Compiler ¡ Typing ¡Constraint ¡ GeneraQon ¡ Weighted ¡MaxSMT ¡ Solver ¡

input ¡program ¡and ¡ ranking ¡criterion ¡ constraint ¡ minimum ¡error ¡ ¡ sources ¡

slide-11
SLIDE 11

Weighted ¡MaxSMT ¡

Input: ¡ ¡

  • hard ¡clauses ¡ ¡
  • must ¡hold ¡
  • soP ¡clauses ¡
  • each ¡clause ¡assigned ¡a ¡weight ¡
  • each ¡clause ¡belongs ¡to ¡a ¡fixed ¡first-­‑order ¡theory ¡
  • algebraic ¡data ¡types, ¡linear ¡integer ¡arithmeQc, ¡… ¡

¡ Output: ¡

  • A ¡saQsfiable ¡subset ¡of ¡soP ¡clauses ¡with ¡maximum ¡

cumulaQve ¡weight ¡(hard ¡clauses ¡must ¡hold) ¡

slide-12
SLIDE 12

Reduction ¡to ¡MaxSMT ¡

let x = "hi" in not x

? ¡

Tlet = ⇒ ( αlet = αo ∧ Tnot = ⇒ αnot = αapp ∧

Tx = ⇒ αx = string ∧ Tapp = ⇒ ( αapp = fun(αi, αo) ∧ Ti = ⇒ αi = αx )) ∧ Tnot impl = ⇒ αnot = fun(bool, bool) ∧

Tlet ∧ Tx ∧ Tapp ∧ Tnot ∧ Ti ∧ Tnot impl

wlet wx wapp wnot wi wnot impl

hard ¡

slide-13
SLIDE 13

Implementation ¡

  • Subset ¡of ¡OCaml ¡(Caml) ¡
  • Hindley-­‑Milner ¡type ¡system ¡
  • Constraint ¡generaQon ¡using ¡EasyOCaml ¡
  • constraint ¡encoded ¡in ¡the ¡theory ¡of ¡inducQve ¡data ¡types ¡
  • Weighted ¡MaxSMT ¡procedures ¡using ¡Sat4j ¡and ¡

CVC4 ¡

  • circa ¡500 ¡lines ¡of ¡Java ¡code ¡
  • EvaluaQon ¡on ¡~350 ¡programs ¡from ¡[Lerner ¡et ¡al., ¡`07] ¡
slide-14
SLIDE 14

Evaluation ¡

15% ¡increase ¡in ¡accuracy ¡over ¡OCaml ¡

  • ranking ¡criterion: ¡size ¡of ¡expression ¡

seconds ¡ program ¡size ¡in ¡LOC ¡

0 ¡ 20 ¡ 40 ¡ 60 ¡ 80 ¡ 100 ¡ 120 ¡ 140 ¡ 160 ¡ 180 ¡ 0-­‑50 ¡ (47) ¡ 50-­‑100 ¡ (102) ¡ 100-­‑150 ¡ (65) ¡ 150-­‑200 ¡ (57) ¡ 200-­‑250 ¡ (53) ¡ 250-­‑300 ¡ (28) ¡ 300-­‑350 ¡ (3) ¡ 350-­‑400 ¡ (1) ¡

min ¡ median ¡ max ¡

slide-15
SLIDE 15

Constraint ¡size ¡

10 100 1000 10000 100000 50 100 150 200 250

Number of assertions Program size (lines of code)

Constraint size

slide-16
SLIDE 16

Performance ¡improvements ¡

  • Type ¡checking ¡EXPTIME-­‑complete ¡[Mairson ¡`90, ¡

Kfoury ¡et ¡al. ¡`90] ¡

  • SoluQon? ¡
  • Lazy ¡quanQfier-­‑based ¡instanQaQon ¡
  • Lazy ¡unificaQon-­‑based ¡instanQaQon ¡
  • Further ¡opQmizaQons ¡
  • Constraint ¡slicing ¡
  • PreempQve ¡cuvng ¡
slide-17
SLIDE 17

Contributions ¡

  • Clean ¡problem ¡formulaQon ¡
  • type ¡error ¡localizaQon ¡as ¡an ¡opQmizaQon ¡problem ¡
  • abstracts ¡from ¡ranking ¡criteria ¡
  • General ¡algorithm ¡
  • reducQon ¡to ¡weighted ¡MaxSMT ¡constraint ¡solving ¡
  • supports ¡various ¡type ¡systems ¡due ¡to ¡SMT ¡
  • modest ¡compiler ¡modificaQons ¡

¡

Thank ¡you! ¡