skip to main content
research-article

A practical framework for type inference error explanation

Published:19 October 2016Publication History
Skip Abstract Section

Abstract

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.

References

  1. Alexander Aiken and Edward L. Wimmers. Type inclusion constraints and type inference. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture, FPCA ’93, pages 31–41, New York, NY, USA, 1993. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. R. Bruttomesso, E. Pek, and N. Sharygina. A flexible schema for generating explanations in lazy theory propagation. In Formal Methods and Models for Codesign (MEMOCODE), 2010 8th IEEE/ACM International Conference on, pages 41– 48, July 2010.Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Satish Chandra, Colin S. Gordon, Jean-Baptiste Jeannin, Cole Schlesinger, Manu Sridharan, Frank Tip, and Young-il Choi. Type inference for static compilation of JavaScript. In Proceedings of the 2016 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’16, New York, NY, USA, 2016. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Sheng Chen and Martin Erwig. Counter-factual typing for debugging type errors. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, pages 583–594, New York, NY, USA, 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Wontae Choi, Satish Chandra, George C. Necula, and Koushik Sen. SJS: A type system for JavaScript with fixed object layout. In Sandrine Blazy and Thomas Jensen, editors, Static Analysis - 22nd International Symposium, SAS 2015, Saint-Malo, France, September 9-11, 2015, Proceedings, volume 9291 of Lecture Notes in Computer Science, pages 181–198. Springer, 2015.Google ScholarGoogle Scholar
  6. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Third Edition. The MIT Press, 3rd edition, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Luis Damas and Robin Milner. Principal type-schemes for functional programs. In Proceedings of the 9th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’82, pages 207–212, New York, NY, USA, 1982. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Manuel Fähndrich, Jakob Rehof, and Manuvir Das. Scalable context-sensitive flow analysis using instantiation constraints. In Proceedings of the ACM SIGPLAN 2000 Conference on Programming Language Design and Implementation, PLDI ’00, pages 253–263, New York, NY, USA, 2000. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Zhaohui Fu and Sharad Malik. On solving the Partial MAXSAT problem. In Armin Biere and Carla P. Gomes, editors, Theory and Applications of Satisfiability Testing - SAT 2006, volume 4121 of Lecture Notes in Computer Science, pages 252–265. Springer Berlin Heidelberg, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Harald Ganzinger, George Hagen, Robert Nieuwenhuis, Albert Oliveras, and Cesare Tinelli. Computer Aided Verification: 16th International Conference, CAV 2004, Boston, MA, USA, July 13-17, 2004. Proceedings, chapter DPLL(T): Fast Decision Procedures, pages 175–188. Springer Berlin Heidelberg, Berlin, Heidelberg, 2004.Google ScholarGoogle Scholar
  11. Christian Haack and J. B. Wells. Type error slicing in implicitly typed higher-order languages. In Proceedings of the 12th European Conference on Programming, ESOP’03, pages 284– 301, Berlin, Heidelberg, 2003. Springer-Verlag. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Fritz Henglein. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):253–289, April 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Ulrich Junker. QUICKXPLAIN: Preferred explanations and relaxations for over-constrained problems. In Proceedings of the 19th National Conference on Artifical Intelligence, AAAI’04, pages 167–172. AAAI Press, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Richard M. Karp. Complexity of Computer Computations: Proceedings of a symposium on the Complexity of Computer Computations, chapter Reducibility among Combinatorial Problems, pages 85–103. Springer US, Boston, MA, 1972.Google ScholarGoogle Scholar
  15. A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. An analysis of ML typability. J. ACM, 41(2):368–398, March 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Daniel Le Berre and Anne Parrain. The Sat4j library, release 2.2, system description. Journal on Satisfiability, Boolean Modeling and Computation, 7:59–64, 2010.Google ScholarGoogle ScholarCross RefCross Ref
  17. Benjamin S. Lerner, Matthew Flower, Dan Grossman, and Craig Chambers. Searching for type-error messages. In Proceedings of the 28th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’07, pages 425–434, New York, NY, USA, 2007. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Martin Odersky, Martin Sulzmann, and Martin Wehr. Type inference with constrained types. Theor. Pract. Object Syst., 5(1):35–55, January 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Yutaka Oiwa and Eijiro Sumii. min-rt. https://github. com/esumii/min-caml/blob/master/min-rt.Google ScholarGoogle Scholar
  20. Zvonimir Pavlinovic, Tim King, and Thomas Wies. Finding minimum type error sources. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA ’14, pages 525– 542, New York, NY, USA, 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Zvonimir Pavlinovic, Tim King, and Thomas Wies. Practical SMT-based type error localization. In Proceedings of the 20th ACM SIGPLAN International Conference on Functional Programming, ICFP 2015, pages 412–423, New York, NY, USA, 2015. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. François Pottier and Didier Rémy. The essence of ML type inference. In Benjamin Pierce, editor, Advanced Types and Programming Languages. MIT Press, 2005.Google ScholarGoogle Scholar
  23. Didier Rémy. Extending ML type system with a sorted equational theory. Technical report, Research Report 1766, Institut National de Recherche en Informatique et Automatisme, Rocquencourt, BP 105, 78 153 Le Chesnay Cedex, France, 1992.Google ScholarGoogle Scholar
  24. Eric L. Seidel, Ranjit Jhala, and Westley Weimer. Dynamic witnesses for static type errors. CoRR, abs/1606.07557, 2016. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Martin Sulzmann, Martin Müller, and Christoph Zenger. Hindley/Milner style type systems in constraint form. Technical report, 1999.Google ScholarGoogle Scholar
  26. Danfeng Zhang and Andrew C. Myers. Toward general diagnosis of static errors. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, pages 569–581, New York, NY, USA, 2014. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Danfeng Zhang, Andrew C. Myers, Dimitrios Vytiniotis, and Simon Peyton-Jones. Diagnosing type errors with class. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2015, pages 12–21, New York, NY, USA, 2015. ACM. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A practical framework for type inference error explanation

      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

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 51, Issue 10
        OOPSLA '16
        October 2016
        915 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/3022671
        Issue’s Table of Contents
        • cover image ACM Conferences
          OOPSLA 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Object-Oriented Programming, Systems, Languages, and Applications
          October 2016
          915 pages
          ISBN:9781450344449
          DOI:10.1145/2983990

        Copyright © 2016 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 19 October 2016

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!