skip to main content
research-article

Practical SMT-based type error localization

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

Cited By

View all
  • (2022)Improving Type Error Reporting for Type ClassesFunctional and Logic Programming10.1007/978-3-030-99461-7_2(19-38)Online publication date: 3-May-2022
  • (2018)Automatic diagnosis and correction of logical errors for functional programming assignmentsProceedings of the ACM on Programming Languages10.1145/32765282:OOPSLA(1-30)Online publication date: 24-Oct-2018
  • (2017)Learning user friendly type-error messagesProceedings of the ACM on Programming Languages10.1145/31339301:OOPSLA(1-29)Online publication date: 12-Oct-2017
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

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
  • 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
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
Published in SIGPLAN Volume 50, Issue 9

Check for updates

Author Tags

  1. Polymorphic Types
  2. Satisfiability Modulo Theories
  3. Type Error Localization

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)5
  • Downloads (Last 6 weeks)1
Reflects downloads up to 13 Dec 2024

Other Metrics

Citations

Cited By

View all
  • (2022)Improving Type Error Reporting for Type ClassesFunctional and Logic Programming10.1007/978-3-030-99461-7_2(19-38)Online publication date: 3-May-2022
  • (2018)Automatic diagnosis and correction of logical errors for functional programming assignmentsProceedings of the ACM on Programming Languages10.1145/32765282:OOPSLA(1-30)Online publication date: 24-Oct-2018
  • (2017)Learning user friendly type-error messagesProceedings of the ACM on Programming Languages10.1145/31339301:OOPSLA(1-29)Online publication date: 12-Oct-2017
  • (2017)How type errors were fixed and what students did?Proceedings of the ACM on Programming Languages10.1145/31339291:OOPSLA(1-27)Online publication date: 12-Oct-2017
  • (2023)ChameleonIDE: Untangling Type Errors Through Interactive Visualization and Exploration2023 IEEE/ACM 31st International Conference on Program Comprehension (ICPC)10.1109/ICPC58990.2023.00029(146-156)Online publication date: May-2023
  • (2023)Error Localization for Sequential Effect SystemsStatic Analysis10.1007/978-3-031-44245-2_16(343-370)Online publication date: 24-Oct-2023
  • (2020)Heuristics-based Type Error Diagnosis for HaskellProceedings of the 32nd Symposium on Implementation and Application of Functional Languages10.1145/3462172.3462189(33-43)Online publication date: 2-Sep-2020
  • (2020)The history of Standard MLProceedings of the ACM on Programming Languages10.1145/33863364:HOPL(1-100)Online publication date: 12-Jun-2020
  • (2019)A compiler architecture for domain-specific type error diagnosisOpen Computer Science10.1515/comp-2019-00029:1(33-51)Online publication date: 14-Feb-2019
  • (2019)A framework for improving error messages in dependently-typed languagesOpen Computer Science10.1515/comp-2019-00019:1(1-32)Online publication date: 24-Jan-2019
  • Show More Cited By

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