Nothing Special   »   [go: up one dir, main page]

skip to main content
research-article
Open access

Total Type Error Localization and Recovery with Holes

Published: 05 January 2024 Publication History

Abstract

Type systems typically only define the conditions under which an expression is well-typed, leaving ill-typed expressions formally meaningless. This approach is insufficient as the basis for language servers driving modern programming environments, which are expected to recover from simultaneously localized errors and continue to provide a variety of downstream semantic services. This paper addresses this problem, contributing the first comprehensive formal account of total type error localization and recovery: the marked lambda calculus. In particular, we define a gradual type system for expressions with marked errors, which operate as non-empty holes, together with a total procedure for marking arbitrary unmarked expressions. We mechanize the metatheory of the marked lambda calculus in Agda and implement it, scaled up, as the new basis for Hazel, a full-scale live functional programming environment with, uniquely, no meaningless editor states.
The marked lambda calculus is bidirectionally typed, so localization decisions are systematically predictable based on a local flow of typing information. Constraint-based type inference can bring more distant information to bear in discovering inconsistencies but this notoriously complicates error localization. We approach this problem by deploying constraint solving as a type-hole-filling layer atop this gradual bidirectionally typed core. Errors arising from inconsistent unification constraints are localized exclusively to type and expression holes, i.e. the system identifies unfillable holes using a system of traced provenances, rather than localized in an ad hoc manner to particular expressions. The user can then interactively shift these errors to particular downstream expressions by selecting from suggested partially consistent type hole fillings, which returns control back to the bidirectional system. We implement this type hole inference system in Hazel.

References

[1]
Djonathan Barros, Sven Peldszus, Wesley K. G. Assunç ao, and Thorsten Berger. 2022. Editing support for software languages: implementation practices in language server protocols. In Proceedings of the 25th International Conference on Model Driven Engineering Languages and Systems, MODELS 2022, Montreal, Quebec, Canada, October 23-28, 2022, Eugene Syriani, Houari A. Sahraoui, Nelly Bencomo, and Manuel Wimmer (Eds.). ACM, 232–243. https://doi.org/10.1145/3550355.3552452
[2]
Ishan Bhanuka, Lionel Parreaux, David Binder, and Jonathan Immanuel Brachthäuser. 2023. Getting into the flow: Towards better type error messages for constraint-based type inference. Proceedings of the ACM on Programming Languages, 7, OOPSLA2 (2023), 431–459. https://doi.org/10.1145/3622812
[3]
Andrew Blinn, David Moon, Eric Griffis, and Cyrus Omar. 2022. An Integrative Human-Centered Architecture for Interactive Programming Assistants. In 2022 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC). 1–5. https://doi.org/10.1109/VL/HCC53370.2022.9833110
[4]
Frédéric Bour, Thomas Refis, and Gabriel Scherer. 2018. Merlin: a language server for OCaml (experience report). Proc. ACM Program. Lang., 2, ICFP (2018), 103:1–103:15. https://doi.org/10.1145/3236798
[5]
Edwin C. Brady. 2013. Idris, a general-purpose dependently typed programming language: Design and implementation. J. Funct. Program., 23, 5 (2013), 552–593. https://doi.org/10.1017/S095679681300018X
[6]
Yair Chuchem and Eyal Lotem. 2019. Steady Typing.
[7]
Matteo Cimini and Jeremy G. Siek. 2016. The gradualizer: a methodology and algorithm for generating gradual type systems. In Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2016, St. Petersburg, FL, USA, January 20 - 22, 2016, Rupak Majumdar Rastislav Bodík (Ed.). ACM, 443–455. https://doi.org/10.1145/2837614.2837632
[8]
Evan Czaplicki and Stephen Chong. 2013. Asynchronous functional reactive programming for GUIs. In ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI ’13, Seattle, WA, USA, June 16-19, 2013, Hans-Juergen Boehm and Cormac Flanagan (Eds.). ACM, 411–422. https://doi.org/10.1145/2491956.2462161
[9]
Sérgio Queiroz de Medeiros, Gilney de Azevedo Alvez Junior, and Fabio Mascarenhas. 2020. Automatic syntax error reporting and recovery in parsing expression grammars. Sci. Comput. Program., 187 (2020), 102373. https://doi.org/10.1016/J.SCICO.2019.102373
[10]
Jana Dunfield and Neel Krishnaswami. 2019. Bidirectional Typing. CoRR, abs/1908.05839 (2019), arXiv:1908.05839. arxiv:1908.05839
[11]
Jana Dunfield and Neelakantan R. Krishnaswami. 2013. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ACM SIGPLAN International Conference on Functional Programming, ICFP’13, Boston, MA, USA - September 25 - 27, 2013, Greg Morrisett and Tarmo Uustalu (Eds.). ACM, 429–442. https://doi.org/10.1145/2500365.2500582
[12]
Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015, Sriram K. Rajamani and David Walker (Eds.). ACM, 303–315. https://doi.org/10.1145/2676726.2676992
[13]
Christian Haack and Joe B. Wells. 2003. Type Error Slicing in Implicitly Typed Higher-Order Languages. In Programming Languages and Systems, 12th European Symposium on Programming, ESOP 2003, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2003, Warsaw, Poland, April 7-11, 2003, Proceedings, Pierpaolo Degano (Ed.) (Lecture Notes in Computer Science, Vol. 2618). Springer, 284–301. https://doi.org/10.1007/3-540-36575-3_20
[14]
HaskellWiki. 2014. GHC/Typed holes — HaskellWiki. https://wiki.haskell.org/index.php?title=GHC/Typed_holes&oldid=58717 [Online; accessed 2-March-2023]
[15]
Hazel Development Team. 2023. Hazel. http://hazel.org/
[16]
Bastiaan Heeren, Daan Leijen, and Arjan van IJzendoorn. 2003. Helium, for learning Haskell. In Proceedings of the ACM SIGPLAN Workshop on Haskell, Haskell 2003, Uppsala, Sweden, August 28, 2003, Johan Jeuring (Ed.). ACM, 62–71. https://doi.org/10.1145/871895.871902
[17]
Gérard P. Huet. 1976. Resolution d’Equations dans les langages d’ordre 1, 2, ..., omega. Ph. D. Dissertation. Université de Paris VII.
[18]
Stef Joosten, Klaas van den Berg, and Gerrit van Der Hoeven. 1993. Teaching Functional Programming to First-Year Students. J. Funct. Program., 3, 1 (1993), 49–65. https://doi.org/10.1017/S0956796800000599
[19]
Oukseh Lee and Kwangkeun Yi. 1998. Proofs about a Folklore Let-Polymorphic Type Inference Algorithm. ACM Trans. Program. Lang. Syst., 20, 4 (1998), 707–723. https://doi.org/10.1145/291891.291892
[20]
Meven Lennon-Bertrand. 2022. Bidirectional Typing for the Calculus of Inductive Constructions. (Typage Bidirectionnel pour le Calcul des Constructions Inductives). Ph. D. Dissertation. University of Nantes, France. https://tel.archives-ouvertes.fr/tel-03848595
[21]
Bruce J. McAdam. 1999. On the Unification of Substitutions in Type Inference. In Implementation of Functional Languages, Kevin Hammond, Tony Davie, and Chris Clack (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 137–152. isbn:978-3-540-48515-5
[22]
David Moon, Andrew Blinn, and Cyrus Omar. 2022. tylr: a tiny tile-based structure editor. In TyDe ’22: 7th ACM SIGPLAN International Workshop on Type-Driven Development, Ljubljana, Slovenia, 11 September 2022. ACM, 28–37. https://doi.org/10.1145/3546196.3550164
[23]
David Moon, Andrew Blinn, and Cyrus Omar. 2023. Gradual Structure Editing with Obligations. In 2023 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC). 71–81. https://doi.org/10.1109/VL-HCC57772.2023.00016
[24]
Ulf Norell. 2007. Towards a practical programming language based on dependent type theory. Ph. D. Dissertation. Department of Computer Science and Engineering, Chalmers University of Technology. SE-412 96 Göteborg, Sweden.
[25]
Martin Odersky, Martin Sulzmann, and Martin Wehr. 1999. Type Inference with Constrained Types. Theory Pract. Object Syst., 5, 1 (1999), 35–55.
[26]
Cyrus Omar, Ian Voysey, Ravi Chugh, and Matthew A. Hammer. 2019. Live functional programming with typed holes. Proc. ACM Program. Lang., 3, POPL (2019), 14:1–14:32. https://doi.org/10.1145/3290327
[27]
Cyrus Omar, Ian Voysey, Michael Hilton, Jonathan Aldrich, and Matthew A. Hammer. 2017. Hazelnut: a bidirectionally typed structure editor calculus. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages, POPL 2017, Paris, France, January 18-20, 2017, Giuseppe Castagna and Andrew D. Gordon (Eds.). ACM, 86–99. https://doi.org/10.1145/3009837.3009900
[28]
Cyrus Omar, Ian Voysey, Michael Hilton, Joshua Sunshine, Claire Le Goues, Jonathan Aldrich, and Matthew A. Hammer. 2017. Toward Semantic Foundations for Program Editors. In 2nd Summit on Advances in Programming Languages, SNAPL 2017, May 7-10, 2017, Asilomar, CA, USA, Benjamin S. Lerner and Shriram Krishnamurthi Rastislav Bodík (Eds.) (LIPIcs, Vol. 71). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 11:1–11:12. https://doi.org/10.4230/LIPICS.SNAPL.2017.11
[29]
Zvonimir Pavlinovic, Tim King, and Thomas Wies. 2014. Finding minimum type error sources. In Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & Applications, OOPSLA 2014, part of SPLASH 2014, Portland, OR, USA, October 20-24, 2014, Andrew P. Black and Todd D. Millstein (Eds.). ACM, 525–542. https://doi.org/10.1145/2660193.2660230
[30]
Benjamin C. Pierce. 2002. Types and programming languages. MIT Press. isbn:978-0-262-16209-8
[31]
Benjamin C. Pierce and David N. Turner. 2000. Local type inference. ACM Trans. Program. Lang. Syst., 22, 1 (2000), 1–44. https://doi.org/10.1145/345099.345100
[32]
Hannah Potter, Ardi Madadi, René Just, and Cyrus Omar. 2022. Contextualized Programming Language Documentation. In Proceedings of the 2022 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software, Onward! 2022, Auckland, New Zealand, December 8-10, 2022, Christophe Scholliers and Jeremy Singer (Eds.). ACM, 1–15. https://doi.org/10.1145/3563835.3567654
[33]
Hannah Potter and Cyrus Omar. 2020. Hazel Tutor: Guiding Novices Through Type-Driven Development Strategies. Human Aspects of Types and Reasoning Assistants (HATRA).
[34]
François Pottier. 2014. Hindley-milner elaboration in applicative style: functional pearl. In Proceedings of the 19th ACM SIGPLAN international conference on Functional programming, Gothenburg, Sweden, September 1-3, 2014, Johan Jeuring and Manuel M. T. Chakravarty (Eds.). ACM, 203–212. https://doi.org/10.1145/2628136.2628145
[35]
Thomas Schilling. 2011. Constraint-Free Type Error Slicing. In Trends in Functional Programming, 12th International Symposium, TFP 2011, Madrid, Spain, May 16-18, 2011, Revised Selected Papers, Ricardo Peña and Rex L. Page (Eds.) (Lecture Notes in Computer Science, Vol. 7193). Springer, 1–16. https://doi.org/10.1007/978-3-642-32037-8_1
[36]
Eric L. Seidel, Ranjit Jhala, and Westley Weimer. 2016. Dynamic witnesses for static type errors (or, ill-typed programs usually go wrong). In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, Nara, Japan, September 18-22, 2016, Jacques Garrigue, Gabriele Keller, and Eijiro Sumii (Eds.). ACM, 228–242. https://doi.org/10.1145/2951913.2951915
[37]
Eric L. Seidel, Huma Sibghat, Kamalika Chaudhuri, Westley Weimer, and Ranjit Jhala. 2017. Learning to blame: localizing novice type errors with data-driven diagnosis. Proc. ACM Program. Lang., 1, OOPSLA (2017), 60:1–60:27. https://doi.org/10.1145/3138818
[38]
Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop.
[39]
Jeremy G. Siek and Manish Vachharajani. 2008. Gradual typing with unification-based inference. In Proceedings of the 2008 Symposium on Dynamic Languages, DLS 2008, July 8, 2008, Paphos, Cyprus, Johan Brichau (Ed.). ACM, 7. https://doi.org/10.1145/1408681.1408688
[40]
Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, and John Tang Boyland. 2015. Refined Criteria for Gradual Typing. In 1st Summit on Advances in Programming Languages, SNAPL 2015, May 3-6, 2015, Asilomar, California, USA, Thomas Ball, Rastislav Bodik, Shriram Krishnamurthi, Benjamin S. Lerner, and Greg Morrisett (Eds.) (LIPIcs, Vol. 32). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 274–293. https://doi.org/10.4230/LIPICS.SNAPL.2015.274
[41]
Armando Solar-Lezama. 2013. Program sketching. Int. J. Softw. Tools Technol. Transf., 15, 5-6 (2013), 475–495. https://doi.org/10.1007/S10009-012-0249-7
[42]
Arthur Sorkin and Peter Donovan. 2011. LR(1) parser generation system: LR(1) error recovery, oracles, and generic tokens. ACM SIGSOFT Softw. Eng. Notes, 36, 2 (2011), 1–5. https://doi.org/10.1145/1943371.1943391
[43]
Tim Teitelbaum and Thomas W. Reps. 1981. The Cornell Program Synthesizer: A Syntax-Directed Programming Environment. Commun. ACM, 24, 9 (1981), 563–573. https://doi.org/10.1145/358746.358755
[44]
Frank Tip and T. B. Dinesh. 2001. A slicing-based approach for locating type errors. ACM Trans. Softw. Eng. Methodol., 10, 1 (2001), 5–55. https://doi.org/10.1145/366378.366379
[45]
Niki Vazou, Éric Tanter, and David Van Horn. 2018. Gradual liquid type inference. Proc. ACM Program. Lang., 2, OOPSLA (2018), 132:1–132:25. https://doi.org/10.1145/3276502
[46]
Jérôme Vouillon and Vincent Balat. 2014. From bytecode to JavaScript: the Js_of_ocaml compiler. Softw. Pract. Exp., 44, 8 (2014), 951–972. https://doi.org/10.1002/SPE.2187
[47]
Philip Wadler and Stephen Blott. 1989. How to Make ad-hoc Polymorphism Less ad-hoc. In Conference Record of the Sixteenth Annual ACM Symposium on Principles of Programming Languages, Austin, Texas, USA, January 11-13, 1989. ACM Press, 60–76. https://doi.org/10.1145/75277.75283
[48]
Mitchell Wand. 1986. Finding the Source of Type Errors. In Conference Record of the Thirteenth Annual ACM Symposium on Principles of Programming Languages, St. Petersburg Beach, Florida, USA, January 1986. ACM Press, 38–43. https://doi.org/10.1145/512644.512648
[49]
Yongwei Yuan, Scott Guest, Eric Griffis, Hannah Potter, David Moon, and Cyrus Omar. 2023. Live Pattern Matching with Typed Holes. Proc. ACM Program. Lang., 7, OOPSLA1 (2023), 609–635. https://doi.org/10.1145/3586048
[50]
Danfeng Zhang and Andrew C. Myers. 2014. Toward general diagnosis of static errors. In The 41st Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’14, San Diego, CA, USA, January 20-21, 2014, Suresh Jagannathan and Peter Sewell (Eds.). ACM, 569–582. https://doi.org/10.1145/2535838.2535870
[51]
Eric Zhao, Raef Maroof, Anand Dukkipati, Andrew Blinn, Zhiyi Pan, and Cyrus Omar. 2023. Artifact for Total Type Error Localization and Recovery with Holes. https://doi.org/10.5281/zenodo.10129703

Cited By

View all
  • (2024)Statically Contextualizing Large Language Models with Typed HolesProceedings of the ACM on Programming Languages10.1145/36897288:OOPSLA2(468-498)Online publication date: 8-Oct-2024

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 8, Issue POPL
January 2024
2820 pages
EISSN:2475-1421
DOI:10.1145/3554315
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 05 January 2024
Published in PACMPL Volume 8, Issue POPL

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. bidirectional typing
  2. gradual typing
  3. type errors
  4. type inference

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)579
  • Downloads (Last 6 weeks)94
Reflects downloads up to 18 Nov 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Statically Contextualizing Large Language Models with Typed HolesProceedings of the ACM on Programming Languages10.1145/36897288:OOPSLA2(468-498)Online publication date: 8-Oct-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media