S EMINAL : Searching for ML Type-Error Messages Benjamin Lerner, Dan Grossman, Craig Chambers University of Washington.

Slides:



Advertisements
Similar presentations
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Advertisements

CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
Using the Optimizer to Generate an Effective Regression Suite: A First Step Murali M. Krishna Presented by Harumi Kuno HP.
Dynamic Typing COS 441 Princeton University Fall 2004.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
Searching for Type-Error Messages Benjamin Lerner, Matthew Flower, Dan Grossman, Craig Chambers University of Washington.
Type Checking.
Michael Armbrust A Functional Query Optimization Framework.
Debugging Introduction to Computing Science and Programming I.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Fall 2011.
Visualizing Type Error Messages Allison Thompson CSCI 5535 Spring 2010.
NaLIX: A Generic Natural Language Search Environment for XML Data Presented by: Erik Mathisen 02/12/2008.
Automatically Proving the Correctness of Compiler Optimizations Sorin Lerner Todd Millstein Craig Chambers University of Washington.
SEMINAL: Efficiently Searching for Type-Error Messages Benjamin Lerner Dan Grossman, Craig Chambers University of Washington.
© 2010 John Dalbey Ch 9: Reviews Humphrey proposes that personal reviews will result in improved quality. Now that we have a defined process and some real.
Debugging CPSC 315 – Programming Studio Fall 2008.
 Monday, 9/30/02, Slide #1 CS106 Introduction to CS1 Monday, 9/30/02  QUESTIONS (on HW02, etc.)??  Today: Libraries, program design  More on Functions!
Range Analysis. Intraprocedural Points-to Analysis Want to compute may-points-to information Lattice:
Semantics for MinML COS 441 Princeton University Fall 2004.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
Design patterns Observer,Strategi, Composite,Template (Chap 5, 6)
SE 555 Software Requirements & Specification 1 SE 555 Software Requirements & Specification Prototyping.
Type Inference: CIS Seminar, 11/3/2009 Type inference: Inside the Type Checker. A presentation by: Daniel Tuck.
Optimality Study of Logic Synthesis for LUT-Based FPGAs Jason Cong and Kirill Minkovich VLSI CAD Lab Computer Science Department University of California,
Pointer analysis. Pointer Analysis Outline: –What is pointer analysis –Intraprocedural pointer analysis –Interprocedural pointer analysis Andersen and.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
Overview Coding Practices Balancing standards Configuration Management Providing Change Control Software Estimation Reasons why Programmers and Managers.
Visioning ITM 734 Fall 2006 Corritore. 2 Visioning Goal – to create a vision of how your system will support your users’ work. * says what the new work.
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
Usability Evaluation/LP Usability: how to judge it.
1 Project Information and Acceptance Testing Integrating Your Code Final Code Submission Acceptance Testing Other Advice and Reminders.
The First in GPON Verification Classic Mistakes Verification Leadership Seminar Racheli Ganot FlexLight Networks.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Unit Testing Maintaining Quality. How do you test? Testing to date…
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.
CS 4850: Senior Project Fall 2014 Object-Oriented Design.
Requirements Engineering Southern Methodist University CSE 7316 – Chapter 3.
Before Preview Set goals Activate Schema During Predict Picture Relate Monitor correct After Recall React  Three THINKING Stages.
Software Quality Assurance and Testing Fazal Rehman Shamil.
SAFE KERNEL EXTENSIONS WITHOUT RUN-TIME CHECKING George C. Necula Peter Lee Carnegie Mellon U.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Today’s Agenda ML Development Workflow –Emacs –Using use –The REPL More ML –Shadowing Variables –Debugging Tips –Boolean Operations –Comparison Operations.
CSE 341 : Programming Languages Lecture 9 Lexical Scope, Closures Zach Tatlock Spring 2014.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
Data Mining CH6 Implementation: Real machine learning schemes(2) Reporter: H.C. Tsai.
Certifying and Synthesizing Membership Equational Proofs Patrick Lincoln (SRI) joint work with Steven Eker (SRI), Jose Meseguer (Urbana) and Grigore Rosu.
CSE341: Programming Languages Lecture 11 Type Inference
R-GMA as an example of a generic framework for information exchange
Lesson Objectives Aims Understand the following “standard algorithms”:
CSE 341: Programming Languages Section 1
Object-Oriented Design
The key to your first draft [Outlines.pptx]
Higher-Order Procedures
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Winter 2013.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2013.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2016.
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2018.
CSE341: Programming Languages Lecture 11 Type Inference
CSE 303 Concepts and Tools for Software Development
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Zach Tatlock Winter 2018.
CSE341: Programming Languages Lecture 11 Type Inference
slides created by Marty Stepp
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 11 Type Inference
CSE341: Programming Languages Lecture 8 Lexical Scope and Function Closures Dan Grossman Spring 2019.
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 11 Type Inference
Presentation transcript:

S EMINAL : Searching for ML Type-Error Messages Benjamin Lerner, Dan Grossman, Craig Chambers University of Washington

2 Example: Curried functions # let map2 f aList bList = List.map (fun (a, b) -> f a b) (List.combine aList bList);; val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list = # map2 (fun (x, y) -> x + y) [1;2;3] [4;5;6];; This expression has type int but is here used with type 'a -> 'b Try replacing fun (x, y) -> x + y with fun x y -> x + y

3 Example: Nested matches # type a = A1 | A2 | A3;; # type b = B1 | B2;; # let x : a =...;; # let y : b =...;; # match x with A1 -> 1 | A2 -> match y with B1 -> 11 | B2 -> 21 | A3 -> 5;; This pattern matches values of type a but is here used to match values of type b Try replacing match x with A1 -> 1 | A2 -> match y with B1 -> 11 | B2 -> 21 | A3 -> 5;; with match x with A1 -> 1 | A2 -> (match y with B1 -> 11 | B2 -> 21) | A3 -> 5;;

4 What went wrong? Sometimes, existing type-error messages… …are not local Symptoms <> Problems …are not intuitive Very lengthy types are hard to read …are not descriptive Location + types <> Solution …have a steep learning curve

5 Related work Instrument the type-checker Change the order of unification Explanation systems Program slicing Interactive systems Reparation systems But that leads to… See paper for citations

6 Tight coupling with type-checker Implementing a Hindley-Milner TC is easy Implementing a production TC is hard Adding good error messages makes it even harder Interferes with easy revision or extension of TC Error messages in TC adds to compiler’s trusted computing base

7 Our Approach, in one slide Treats type checker as oracle Makes no assumptions about the type system Note: no dependence on unification Tries many variations on program, see which ones work Must do this carefully – there are too many! Note: “Variant works” <> “Variant is right” Ranks successful suggestions, presents results to programmer

8 Outline Examples of confusing messages Related work Our approach Running example Architecture overview Preliminary results Ongoing work Conclusions

9 Example: Curried functions # let map2 f xs ys = List.map (fun (x, y) -> f x y) (List.combine xs ys);; val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list = # map2 (fun (x, y) -> x + y) [1;2;3] [4;5;6];; This expression has type int but is here used with type 'a -> 'b Suggestions: Try replacing fun (x, y) -> x + y with fun x y -> x + y of type int -> int -> int within context (map2 (fun x y -> x + y) [1; 2; 3] [4; 5; 6])

10 Finding the changes, part 0 Change let map2 f aList bList = … ;; map2 (fun (x, y) -> x+y) [1;2;3] [4;5;6] Into…   map2 (fun(x,y)->x+y) [1;2;3] [4;5;6] let map2 f aList bList = … ;; 

11 What’s that  ? Seminal examines the given AST “Replace with  ” = “Replace in AST” Any particular  means Expressions: raise Foo...

12 Finding the changes, part 1 Change map2 (fun (x, y) -> x+y) [1;2;3] [4;5;6] Into…  map2 ((fun(x,y)->x+y), [1;2;3], [4;5;6])  map2 ((fun(x,y)->x+y) [1;2;3] [4;5;6]) …  (fun (x,y)->x+y) [1;2;3] [4;5;6] map2  [1;2;3] [4;5;6]  map2 (fun (x,y)->x+y)  [4;5;6]  map2 (fun (x,y)->x+y) [1;2;3] 

13 Finding the changes, part 2 Change (fun (x, y) -> x + y) Into…  fun (x, y)  -> x + y  fun  (x, y) -> x + y  fun (y, x) -> x + y … fun x y -> x + y

14 Ranking the suggestions Replace map2 (fun (x,y)->x+y) [1;2;3] [4;5;6] with  Replace map2 with  Replace (fun (x,y)->x+y) with  Replace (fun (x,y)->x+y) with (fun x y -> x+y) Prefer smaller changes over larger ones Prefer non-deleting changes over others

15 Tidying up Find type of replacement Get this for free from TC Maintain surrounding context Help user locate the replacement Suggestions: Try replacing fun (x, y) -> x + y with fun x y -> x + y of type int -> int -> int within context (map2 (fun x y -> x + y) [1; 2; 3] [4; 5; 6])

16 Behind the scenes

17 Searcher Defines the strategy for looking for fixes: Look for single AST subtree to remove that will make problem “go away” Replace subtree with “wildcards”  Interesting subtrees guide the search If removing a subtree worked, try its children … Often improves on existing messages’ locations Rely on Enumerator’s suggestions for more detail

18 Enumerator Defines the fixes to be tried: Try custom attempts for each type of AST node E.g. Function applications break differently than if-then expressions Enumeration is term-directed A function of AST nodes only More enumerated attempts  better messages Called by Searcher when needed

19 Ranker Defines the relative merit of successful fixes: Search can produce too many results Not all results are helpful to user E.g. “Replace whole program with  ”! Use heuristics to filter and sort messages “Smallest fixes are best” “Currying a function is better than deleting it” Simple heuristics seem sufficient

20 Preliminary results Prototype built on ocaml Reasonable performance Can fully examine most files in under ~2sec Compare with human speed… Bottleneck is time spent in TC Many calls + repetitive data > 90% of time TC can be improved independently from S EMINAL

21 Current analysis Ongoing analysis of ~2K files collected from students Methods: Group messages as “good”, “misleading”, “bad” Check if message precisely locates problem Check if message approximates student’s actual fix Results: Very good precision on small test cases Good precision on real, large problems Most poor results stem from common cause

22 Ongoing work Dealing with multiple errors: Errors may be widely separated Least common parent is too big Idea: ignore most code, focus on one error Triage : Trade “complete” for “small” Not in workshop paper!

23 Example: Multiple errors # val x : int;; # val y : 'a list;; # match (x, y) with 0, [] -> [] | _, [] -> x | _, 5 -> 5 + "hi" This pattern matches values of type int * int but is here used to match values of type int * 'a list Problems: The last two patterns don’t match the same types The first two cases don’t match The last case doesn’t type-check Try replacing match (x, y) with 0, [] -> [] | _, [] -> x | _, 5 -> 5 + "hi" with  Not an effective suggestion! 1) Try replacing _, 5 with _,  2) Try replacing x with  3) Try replacing 5 + "hi" with 5 + 

24 Example: Multiple errors # val x : int;; # val y : 'a list;; # match (x, y) with 0, [] -> [] | _, [] -> x | _, 5 -> 5 + "hi" First try just the scrutinee match (x, y) with  ->  Then try the patterns match (x, y) with 0, [] ->  | _, [] ->  | _, 5 ->  Finally try the whole expression match (x, y) with 0, [] -> [] | _, [] -> x | _, 5 -> 5 + "hi"

25 Conclusions Searching for repairs yields intuitively helpful messages S EMINAL decouples type-checker from error- message generator Simpler TC architecture Smaller trusted computing base It’s a win-win scenario! Version available soon – happy hacking!