ABSTRACT
Compilers 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 of the error. Since other error sources are not even considered, the actual root cause is often missed. A more adequate approach is to consider all possible error sources and report the most useful one subject to some usefulness criterion. In our previous work, we showed that this approach can be formulated as an optimization problem related to satisfiability modulo theories (SMT). This formulation cleanly separates the heuristic nature of usefulness criteria from the underlying search problem. Unfortunately, algorithms that search for an optimal error source cannot directly use principal types which are crucial for dealing with the exponential-time complexity of the decision problem of polymorphic type checking. In this paper, we present a new algorithm that efficiently finds an optimal error source in a given ill-typed program. Our algorithm uses an improved SMT encoding to cope with the high complexity of polymorphic typing by iteratively expanding the typing constraints from which principal types are derived. The algorithm preserves the clean separation between the heuristics and the actual search. We have implemented our algorithm for OCaml. In our experimental evaluation, we found that the algorithm reduces the running times for optimal type error localization from minutes to seconds and scales better than previous localization algorithms.
- A. Aiken and E. L. Wimmers. Type inclusion constraints and type inference. In FPCA, pages 31–41. ACM, 1993. Google ScholarDigital 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. {5}, 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 ScholarCross 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 ScholarDigital Library
- N. Bjørner and A. Phan. νZ: Maximal Satisfaction with Z3. In SCSS, 2014.Google Scholar
- N. Bjørner, A. Phan, and L. Fleckenstein. νZ: An Optimizing SMT Solver. In TACAS, 2015.Google ScholarDigital Library
- S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In POPL, pages 583–594. ACM, 2014. Google ScholarDigital Library
- O. Chitil. Compositional explanation of types and algorithmic debugging of type errors. In ICFP, ICFP ’01, pages 193–204. ACM, 2001. Google ScholarDigital Library
- L. Damas and R. Milner. Principal type-schemes for functional programs. In POPL, pages 207–212. ACM, 1982. Google ScholarDigital Library
- L. De Moura and N. Bjørner. Z3: An Efficient SMT Solver. In TACAS, pages 337–340. Springer-Verlag, 2008. Google ScholarDigital Library
- D. Duggan and F. Bent. Explaining type inference. In Science of Computer Programming, pages 37–83, 1995. Google ScholarDigital Library
- EasyOCaml. http://easyocaml.forge.ocamlcore.org. {Online; accessed 16-April-2015}.Google Scholar
- H. Gast. Explaining ML type errors by data flows. In Implementation and Application of Functional Languages, pages 72–89. Springer, 2005. Google ScholarDigital Library
- C. Haack and J. B. Wells. Type error slicing in implicitly typed higherorder languages. Sci. Comput. Program., pages 189–224, 2004. Google ScholarDigital Library
- A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. ML Typability is DEXTIMEComplete. In CAAP, pages 206–220, 1990. Google ScholarDigital Library
- B. Lerner, M. Flower, D. Grossman, and C. Chambers. Searching for type-error messages. In PLDI. ACM Press, 2007. Google ScholarDigital Library
- C. M. Li and F. Manyà. MaxSAT, Hard and Soft Constraints, chapter 19, pages 613–631. Volume 185 of Biere et al. {5}, February 2009.Google Scholar
- H. G. Mairson. Deciding ML Typability is Complete for Deterministic Exponential Time. In POPL, pages 382–401, 1990. Google ScholarDigital Library
- N. Narodytska and F. Bacchus. Maximum satisfiability using coreguided maxsat resolution. In Twenty-Eighth AAAI Conference on Artificial Intelligence, 2014.Google ScholarDigital Library
- M. Neubauer and P. Thiemann. Discriminative sum types locate the source of type errors. In ICFP, pages 15–26. ACM Press, 2003. Google ScholarDigital Library
- OCaml. http://ocaml.org. {Online; accessed 15-April-2015}.Google Scholar
- M. Odersky, M. Sulzmann, and M. Wehr. Type inference with constrained types. TAPOS, 5(1):35–55, 1999. Google ScholarDigital Library
- Z. Pavlinovic, T. King, and T. Wies. Finding minimum type error sources. In OOPSLA, pages 525–542, 2014. Google ScholarDigital Library
- Z. Pavlinovic, T. King, and T. Wies. On practical smt-based type error localization. Technical Report TR2015-972, New York University, 2015.Google Scholar
- B. C. Pierce. Types and programming languages. MIT press, 2002. Google ScholarDigital Library
- R. Piskac, T. Wies, and D. Zufferey. Grasshopper. In Tools and Algorithms for the Construction and Analysis of Systems, pages 124– 139. Springer, 2014.Google Scholar
- J. A. Robinson. Computational logic: The unification computation. Machine intelligence, 6(63-72):10–1, 1971.Google Scholar
- SHErrLoc. http://www.cs.cornell.edu/projects/ sherrloc/. {Online; accessed 22-April-2015}.Google Scholar
- 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 ScholarDigital Library
- M. Wand. Finding the source of type errors. In POPL, pages 38–43. ACM, 1986. Google ScholarDigital Library
- D. Zhang and A. C. Myers. Toward general diagnosis of static errors. In POPL, pages 569–581. ACM, 2014. Google ScholarDigital Library
- D. Zhang, A. C. Myers, D. Vytiniotis, and S. L. P. Jones. Diagnosing type errors with class. In PLDI, pages 12–21, 2015. Google ScholarDigital Library
Index Terms
- Practical SMT-based type error localization
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 '14Automatic 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, ...
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, ...
Comments