Tech Report : A Practical Framework for Type Inference Error Explanation

Many languages have support for automatic type inference. But when inference fails, the reported error messages can be unhelpful, highlighting a code location far from the source of the problem. Several lines of work have emerged proposing error reports derived from correcting sets: a set of program points that, when fixed, produce a well-typed program. Unfortunately, these approaches are tightly tied to specific languages; targeting a new language requires encoding a type inference algorithm for the language in a custom constraint system specific to the error reporting tool. We show how to produce correcting set-based error reports by leveraging existing type inference implementations, easing the burden of adoption and, as type inference algorithms tend to be efficient in practice, producing error reports of comparable quality to similar error reporting tools orders of magnitude faster. Many type inference algorithms are already formulated as dual phases of type constraint generation and solving; rather than (re)implementing type inference in an error explanation tool, we isolate the solving phase and treat it as an oracle for solving typing constraints. Given any set of typing constraints, error explanation proceeds by iteratively removing conflicting constraints from the initial constraint set until discovering a subset on which the solver succeeds; the constraints removed form a correcting set. Our approach is agnostic to the semantics of any particular language or type system, instead leveraging the existing type inference engine to give meaning to constraints.

[1]  Simon L. Peyton Jones,et al.  Diagnosing type errors with class , 2015, PLDI.

[2]  Sharad Malik,et al.  On Solving the Partial MAX-SAT Problem , 2006, SAT.

[3]  Martin Erwig,et al.  Counter-factual typing for debugging type errors , 2014, POPL.

[4]  Zvonimir Pavlinovic,et al.  Practical SMT-based type error localization , 2015, ICFP.

[5]  Dan Grossman,et al.  Searching for type-error messages , 2007, PLDI '07.

[6]  Alexander Aiken,et al.  Type inclusion constraints and type inference , 1993, FPCA '93.

[7]  Jean-Baptiste Jeannin,et al.  Type inference for static compilation of JavaScript , 2016, OOPSLA.

[8]  Ulrich Junker,et al.  QUICKXPLAIN: Preferred Explanations and Relaxations for Over-Constrained Problems , 2004, AAAI.

[9]  Ronald L. Rivest,et al.  Introduction to Algorithms, third edition , 2009 .

[10]  Martin Odersky,et al.  Type Inference with Constrained Types , 1999, Theory Pract. Object Syst..

[11]  Christian Haack,et al.  Type error slicing in implicitly typed higher-order languages , 2003, Sci. Comput. Program..

[12]  Danfeng Zhang,et al.  Toward general diagnosis of static errors , 2014, POPL.

[13]  George C. Necula,et al.  SJS: A Type System for JavaScript with Fixed Object Layout , 2015, SAS.

[14]  Jakob Rehof,et al.  Scalable context-sensitive flow analysis using instantiation constraints , 2000, PLDI '00.

[15]  Zvonimir Pavlinovic,et al.  Finding minimum type error sources , 2014, Software Engineering & Management.

[16]  Roberto Bruttomesso,et al.  A flexible schema for generating explanations in lazy theory propagation , 2010, Eighth ACM/IEEE International Conference on Formal Methods and Models for Codesign (MEMOCODE 2010).

[17]  Jerzy Tiuryn,et al.  An analysis of ML typability , 1994, JACM.

[18]  Martin Sulzmann,et al.  Hindley/Milner style type systems in constraint form , 1999 .

[19]  Fritz Henglein,et al.  Type inference with polymorphic recursion , 1993, TOPL.

[20]  Robin Milner,et al.  Principal type-schemes for functional programs , 1982, POPL '82.

[21]  Westley Weimer,et al.  Dynamic witnesses for static type errors (or, ill-typed programs usually go wrong) , 2016, Journal of Functional Programming.