skip to main content
10.1145/2983990.2983994acmconferencesArticle/Chapter ViewAbstractPublication PagessplashConference Proceedingsconference-collections
research-article

A practical framework for type inference error explanation

Published: 19 October 2016 Publication History

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.
[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.
[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.
[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.
[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.
[6]
Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Third Edition. The MIT Press, 3rd edition, 2009.
[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.
[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.
[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.
[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.
[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.
[12]
Fritz Henglein. Type inference with polymorphic recursion. ACM Trans. Program. Lang. Syst., 15(2):253–289, April 1993.
[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.
[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.
[15]
A. J. Kfoury, J. Tiuryn, and P. Urzyczyn. An analysis of ML typability. J. ACM, 41(2):368–398, March 1994.
[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.
[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.
[18]
Martin Odersky, Martin Sulzmann, and Martin Wehr. Type inference with constrained types. Theor. Pract. Object Syst., 5(1):35–55, January 1999.
[19]
Yutaka Oiwa and Eijiro Sumii. min-rt. https://github. com/esumii/min-caml/blob/master/min-rt.
[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.
[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.
[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.
[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.
[24]
Eric L. Seidel, Ranjit Jhala, and Westley Weimer. Dynamic witnesses for static type errors. CoRR, abs/1606.07557, 2016.
[25]
Martin Sulzmann, Martin Müller, and Christoph Zenger. Hindley/Milner style type systems in constraint form. Technical report, 1999.
[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.
[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.

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

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
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 the author(s) 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].

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 19 October 2016

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Type Error Diagnosis
  2. Type Inference

Qualifiers

  • Research-article

Conference

SPLASH '16
Sponsor:

Acceptance Rates

Overall Acceptance Rate 268 of 1,244 submissions, 22%

Upcoming Conference

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)26
  • Downloads (Last 6 weeks)1
Reflects downloads up to 20 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media