skip to main content
10.1145/2784731.2784765acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Practical SMT-based type error localization

Published:29 August 2015Publication History

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.

References

  1. A. Aiken and E. L. Wimmers. Type inclusion constraints and type inference. In FPCA, pages 31–41. ACM, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle Scholar
  3. 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 ScholarGoogle ScholarCross RefCross Ref
  4. C. Barrett, A. Stump, and C. Tinelli. The SMT-LIB standard – version 2.0. In SMT, 2010.Google ScholarGoogle Scholar
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. N. Bjørner and A. Phan. νZ: Maximal Satisfaction with Z3. In SCSS, 2014.Google ScholarGoogle Scholar
  7. N. Bjørner, A. Phan, and L. Fleckenstein. νZ: An Optimizing SMT Solver. In TACAS, 2015.Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. S. Chen and M. Erwig. Counter-factual typing for debugging type errors. In POPL, pages 583–594. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. O. Chitil. Compositional explanation of types and algorithmic debugging of type errors. In ICFP, ICFP ’01, pages 193–204. ACM, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. L. Damas and R. Milner. Principal type-schemes for functional programs. In POPL, pages 207–212. ACM, 1982. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. L. De Moura and N. Bjørner. Z3: An Efficient SMT Solver. In TACAS, pages 337–340. Springer-Verlag, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. D. Duggan and F. Bent. Explaining type inference. In Science of Computer Programming, pages 37–83, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. EasyOCaml. http://easyocaml.forge.ocamlcore.org. {Online; accessed 16-April-2015}.Google ScholarGoogle Scholar
  14. H. Gast. Explaining ML type errors by data flows. In Implementation and Application of Functional Languages, pages 72–89. Springer, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. C. Haack and J. B. Wells. Type error slicing in implicitly typed higherorder languages. Sci. Comput. Program., pages 189–224, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. ML Typability is DEXTIMEComplete. In CAAP, pages 206–220, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. B. Lerner, M. Flower, D. Grossman, and C. Chambers. Searching for type-error messages. In PLDI. ACM Press, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. 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 ScholarGoogle Scholar
  19. H. G. Mairson. Deciding ML Typability is Complete for Deterministic Exponential Time. In POPL, pages 382–401, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. N. Narodytska and F. Bacchus. Maximum satisfiability using coreguided maxsat resolution. In Twenty-Eighth AAAI Conference on Artificial Intelligence, 2014.Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. M. Neubauer and P. Thiemann. Discriminative sum types locate the source of type errors. In ICFP, pages 15–26. ACM Press, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. OCaml. http://ocaml.org. {Online; accessed 15-April-2015}.Google ScholarGoogle Scholar
  23. M. Odersky, M. Sulzmann, and M. Wehr. Type inference with constrained types. TAPOS, 5(1):35–55, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Z. Pavlinovic, T. King, and T. Wies. Finding minimum type error sources. In OOPSLA, pages 525–542, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Z. Pavlinovic, T. King, and T. Wies. On practical smt-based type error localization. Technical Report TR2015-972, New York University, 2015.Google ScholarGoogle Scholar
  26. B. C. Pierce. Types and programming languages. MIT press, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. 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 ScholarGoogle Scholar
  28. J. A. Robinson. Computational logic: The unification computation. Machine intelligence, 6(63-72):10–1, 1971.Google ScholarGoogle Scholar
  29. SHErrLoc. http://www.cs.cornell.edu/projects/ sherrloc/. {Online; accessed 22-April-2015}.Google ScholarGoogle Scholar
  30. 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 ScholarGoogle Scholar
  31. F. Tip and T. B. Dinesh. A slicing-based approach for locating type errors. ACM Trans. Softw. Eng. Methodol., pages 5–55, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. M. Wand. Finding the source of type errors. In POPL, pages 38–43. ACM, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. D. Zhang and A. C. Myers. Toward general diagnosis of static errors. In POPL, pages 569–581. ACM, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. D. Zhang, A. C. Myers, D. Vytiniotis, and S. L. P. Jones. Diagnosing type errors with class. In PLDI, pages 12–21, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Practical SMT-based type error localization

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in
      • Published in

        cover image ACM Conferences
        ICFP 2015: Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming
        August 2015
        436 pages
        ISBN:9781450336697
        DOI:10.1145/2784731
        • cover image ACM SIGPLAN Notices
          ACM SIGPLAN Notices  Volume 50, Issue 9
          ICFP '15
          September 2015
          436 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2858949
          • Editor:
          • Andy Gill
          Issue’s Table of Contents

        Copyright © 2015 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 29 August 2015

        Permissions

        Request permissions about this article.

        Request Permissions

        Check for updates

        Qualifiers

        • research-article

        Acceptance Rates

        Overall Acceptance Rate333of1,064submissions,31%

        Upcoming Conference

        ICFP '24

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader