Abstract
Automatic type inference is a popular feature of functional programming languages. If a program cannot be typed, the compiler typically reports a single program location in its error message. This location is the point where the type inference failed, but not necessarily the actual source of the error. Other potential error sources are not even considered. Hence, the compiler often misses the true error source, which increases debugging time for the programmer. In this paper, we present a general framework for automatic localization of type errors. Our algorithm finds all minimum error sources, where the exact definition of minimum is given in terms of a compiler-specific ranking criterion. Compilers can use minimum error sources to produce more meaningful error reports, and for automatic error correction. Our approach works by reducing the search for minimum error sources to an optimization problem that we formulate in terms of weighted maximum satisfiability modulo theories (MaxSMT). The reduction to weighted MaxSMT allows us to build on SMT solvers to support rich type systems and at the same time abstract from the concrete criterion that is used for ranking the error sources. We have implemented an instance of our framework targeted at Hindley-Milner type systems and evaluated it on existing OCaml benchmarks for type error localization. Our evaluation shows that our approach has the potential to significantly improve the quality of type error reports produced by state of the art compilers.
- A. Aiken and E. L. Wimmers. Type inclusion constraints and type inference. In FPCA, pages 31--41. ACM, 1993. Google Scholar
Digital Library
- C. Barrett, C. L. Conway, M. Deters, L. Hadarean, D. Jovanović, T. King, A. Reynolds, and C. Tinelli. CVC4. In CAV, pages 171--177. Springer-Verlag, 2011. Google Scholar
Digital Library
- C. Barrett, R. Sebastiani, S. A. Seshia, and C. Tinelli. Satisfiability Modulo Theories, chapter 26, pages 825--885. Volume 185 of Biere et al. {6}, February 2009.Google Scholar
- C. Barrett, I. Shikanian, and C. Tinelli. An abstract decision procedure for a theory of inductive data types. Journal on Satisfiability, Boolean Modeling and Computation, 3:21--46, 2007.Google Scholar
Cross Ref
- C. Barrett, A. Stump, and C. Tinelli. The SMT-LIB standard - version 2.0. In SMT, 2010.Google Scholar
- A. Biere, M. J. H. Heule, H. van Maaren, and T. Walsh, editors. Handbook of Satisfiability, volume 185 of Frontiers in Artificial Intelligence and Applications. IOS Press, February 2009. Google Scholar
Digital Library
- S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In POPL, pages 583--594. ACM, 2014. Google Scholar
Digital Library
- O. Chitil. Compositional explanation of types and algorithmic debugging of type errors. In ICFP, ICFP '01, pages 193--204. ACM, 2001. Google Scholar
Digital Library
- A. Cimatti, A. Griggio, B. J. Schaafsma, and R. Sebastiani. A Modular Approach to MaxSAT Modulo Theories. In SAT, pages 150--165, 2013. Google Scholar
Digital Library
- V. Cremet, F. Garillot, S. Lenglet, and M. Odersky. A Core Calculus for Scala Type Checking. In MFCS, volume 4162 of LNCS, pages 1--23. Springer, 2006. Google Scholar
Digital Library
- L. De Moura and N. Bjørner. Z3: An Efficient SMT Solver. In TACAS, pages 337--340. Springer-Verlag, 2008. Google Scholar
Digital Library
- D. Duggan and F. Bent. Explaining type inference. In Science of Computer Programming, pages 37--83, 1995. Google Scholar
Digital Library
- B. Dutertre and L. de Moura. The Yices SMT solver. Technical report, SRI International, 2006.Google Scholar
- EasyOCaml. http://easyocaml.forge.ocamlcore.org. {Online; accessed 10-March-2014}.Google Scholar
- H. Gast. Explaining ML type errors by data flows. In Implementation and Application of Functional Languages, pages 72--89. Springer, 2005. Google Scholar
Digital Library
- T. Gvero, V. Kuncak, I. Kuraj, and R. Piskac. Complete completion using types and weights. In PLDI, pages 27--38. ACM, 2013. Google Scholar
Digital Library
- C. Haack and J. B. Wells. Type error slicing in implicitly typed higher-order languages. Sci. Comput. Program., pages 189--224, 2004. Google Scholar
Digital Library
- The Haskell Programming Language. http://www.haskell.org/. {Online; accessed 15-March-2014}.Google Scholar
- J. R. Hindley. The principal type-scheme of an object in combinatory logic. Transactions of the American Mathematical Society, 146:2960, 1969.Google Scholar
- M. Jose and R. Majumdar. Bug-Assist: Assisting Fault Localization in ANSI-C Programs. In CAV, pages 504--509. Springer-Verlag, 2011. Google Scholar
Digital Library
- U. Junker. Quickxplain: Preferred explanations and relaxations for over-constrained problems. In AAAI, pages 167--172, 2004. Google Scholar
Digital Library
- A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. ML Typability is DEXTIME-Complete. In CAAP, pages 206--220, 1990. Google Scholar
Digital Library
- D. Le Berre, A. Parrain, et al. The sat4j library, release 2.2, system description. Journal on Satisfiability, Boolean Modeling and Computation, 7:59--64, 2010.Google Scholar
Cross Ref
- B. Lerner, M. Flower, D. Grossman, and C. Chambers. Searching for type-error messages. In PLDI. ACM Press, 2007. Google Scholar
Digital Library
- X. Leroy, D. Doligez, A. Frisch, J. Garrigue, D. Rémy, and J. Vouillon. OCaml Manual: Module Pervasives. http://caml.inria.fr/pub/docs/manual-ocaml/libref/Pervasives.html. {Online; accessed 14-March-2014}.Google Scholar
- C. M. Li and F. Manyà. MaxSAT, Hard and Soft Constraints, chapter 19, pages 613--631. Volume 185 of Biere et al. {6}, February 2009.Google Scholar
- H. G. Mairson. Deciding ML Typability is Complete for Deterministic Exponential Time. In POPL, pages 382--401, 1990. Google Scholar
Digital Library
- J. Marques-Sila and J. Planes. Algorithms for maximum satisfiability using unsatisfiable cores. In K. Gulati, editor, Advanced Techniques in Logic Synthesis, Optimizations and Applications, pages 171--182. Springer New York, 2011.Google Scholar
Cross Ref
- R. Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17(3):348--375, 1978.Google Scholar
Cross Ref
- M. Neubauer and P. Thiemann. Discriminative sum types locate the source of type errors. In ICFP, pages 15--26. ACM Press, 2003. Google Scholar
Digital Library
- OCaml. http://ocaml.org. {Online; accessed 2-February-2014}.Google Scholar
- M. Odersky, M. Sulzmann, and M.Wehr. Type inference with constrained types. TAPOS, 5(1):35--55, 1999. Google Scholar
Digital Library
- J. A. Robinson. Computational logic: The unification computation. Machine intelligence, 6(63--72):10--1, 1971.Google Scholar
- P. M. Rondon, M. Kawaguci, and R. Jhala. Liquid types. In PLDI, pages 159--169. ACM, 2008. Google Scholar
Digital Library
- T. Schrijvers, S. L. P. Jones, M. Sulzmann, and D. Vytiniotis. Complete and decidable type inference for gadts. In ICFP, pages 341--352. ACM, 2009. Google Scholar
Digital Library
- P. J. Stuckey, M. Sulzmann, and J. Wazny. Interactive type debugging in haskell. In Haskell, pages 72--83. ACM, 2003. Google Scholar
Digital Library
- P. J. Stuckey, M. Sulzmann, and J. Wazny. Improving type error diagnosis. In ACM SIGPLAN Workshop on Haskell, pages 80--91. ACM, 2004. Google Scholar
Digital Library
- M. Sulzmann, M. Müller, and C. Zenger. Hindley/Milner style type systems in constraint form. Res. Rep. ACRC-99-009, University of South Australia, School of Computer and Information Science. July, 1999.Google Scholar
- F. Tip and T. B. Dinesh. A slicing-based approach for locating type errors. ACM Trans. Softw. Eng. Methodol., pages 5--55, 2001. Google Scholar
Digital Library
- D. Vytiniotis, S. L. P. Jones, T. Schrijvers, and M. Sulzmann. Outsidein(x) modular type inference with local assumptions. J. Funct. Program., 21(4-5):333--412, 2011. Google Scholar
Digital Library
- M. Wand. Finding the source of type errors. In POPL, pages 38--43. ACM, 1986. Google Scholar
Digital Library
- D. Zhang and A. C. Myers. Toward general diagnosis of static errors. In POPL, pages 569--581. ACM, 2014. Google Scholar
Digital Library
Index Terms
Finding minimum type error sources
Recommendations
Practical SMT-based type error localization
ICFP '15Compilers for statically typed functional programming languages are notorious for generating confusing type error messages. When the compiler detects a type error, it typically reports the program location where the type checking failed as the source ...
Finding minimum type error sources
OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & ApplicationsAutomatic type inference is a popular feature of functional programming languages. If a program cannot be typed, the compiler typically reports a single program location in its error message. This location is the point where the type inference failed, ...
Discriminative sum types locate the source of type errors
We propose a type system for locating the source of type errors in an applied lambda calculus with ML-style polymorphism. The system is based on discriminative sum types---known from work on soft typing---with annotation subtyping and recursive types. ...







Comments