skip to main content

Solver-based gradual type migration

Published:15 October 2021Publication History
Related Artifact: TypeWhich software https://doi.org/10.5281/zenodo.5141479
Skip Abstract Section

Abstract

Gradually typed languages allow programmers to mix statically and dynamically typed code, enabling them to incrementally reap the benefits of static typing as they add type annotations to their code. However, this type migration process is typically a manual effort with limited tool support. This paper examines the problem of automated type migration: given a dynamic program, infer additional or improved type annotations. Existing type migration algorithms prioritize different goals, such as maximizing type precision, maintaining compatibility with unmigrated code, and preserving the semantics of the original program. We argue that the type migration problem involves fundamental compromises: optimizing for a single goal often comes at the expense of others. Ideally, a type migration tool would flexibly accommodate a range of user priorities. We present TypeWhich, a new approach to automated type migration for the gradually-typed lambda calculus with some extensions. Unlike prior work, which relies on custom solvers, TypeWhich produces constraints for an off-the-shelf MaxSMT solver. This allows us to easily express objectives, such as minimizing the number of necessary syntactic coercions, and constraining the type of the migration to be compatible with unmigrated code. We present the first comprehensive evaluation of GTLC type migration algorithms, and compare TypeWhich to four other tools from the literature. Our evaluation uses prior benchmarks, and a new set of "challenge problems." Moreover, we design a new evaluation methodology that highlights the subtleties of gradual type migration. In addition, we apply TypeWhich to a suite of benchmarks for Grift, a programming language based on the GTLC. TypeWhich is able to reconstruct all human-written annotations on all but one program.

Skip Supplemental Material Section

Supplemental Material

Auxiliary Presentation Video

This is the video that accompanies the paper Solver-Based Gradual Type Migration.

References

  1. Jong-hoon David An, Avik Chauduri, Jeffrey S. Foster, and Michael Hicks. 2011. Dynamic Inference of Static Types for Ruby. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  2. Christopher Anderson, Paola Giannini, and Sophia Drossopoulou. 2005. Towards Type Inference for JavaScript. In European Conference on Object-Oriented Programming (ECOOP).Google ScholarGoogle Scholar
  3. Clark Barrett, Iger Shikanian, and Cesare Tinelli. 2007. An Abstract Decision Procedure for a Theory of Inductive Data Types. Journal on Satisfiability, Boolean Modeling and Computation, 3, 1–2 (2007), 21–46.Google ScholarGoogle ScholarCross RefCross Ref
  4. Nikolaj Bjørner, Anh-Dung Phan, and Lars Fleckenstein. 2015. ν Z: An Optimizing SMT Solver. In Tools and Algorithms for the Construction and Analysis of Systems (TACAS).Google ScholarGoogle Scholar
  5. Bard Bloom, John Field, Nathaniel Nystrom, Johan Östlund, Gregor Richards, Rok Strniša, Jan Vitek, and Tobias Wrigstad. 2009. Thorn: Robust, Concurrent, Extensible Scripting on the JVM. In ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages and Applications (OOPSLA).Google ScholarGoogle Scholar
  6. John Peter Campora, Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2018. Migrating Gradual Types. Proceedings of the ACM on Programming Languages (PACMPL), 2, POPL (2018).Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. John Peter Campora, Sheng Chen, and Eric Walkingshaw. 2018. Casts and Costs: Harmonizing Safety and Performance in Gradual Typing. Proceedings of the ACM on Programming Languages (PACMPL), 2, ICFP (2018).Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Giuseppe Castagna, Victor Lanvin, Tommaso Petrucciani, and Jeremy G. Siek. 2019. Gradual Typing: A New Perspective. Proceedings of the ACM on Programming Languages (PACMPL), 3, POPL (2019).Google ScholarGoogle Scholar
  9. Satish Chandra, Colin S. Gordon, Jean-Baptiste Jeannin, Cole Schlesinger, Manu Sridharan, Frank Tip, and Young-Il Choi. 2016. Type inference for static compilation of JavaScript. In ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages and Applications (OOPSLA).Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Sheng Chen, Martin Erwig, and Eric Walkingshaw. 2014. Extending Type Inference to Variational Programs. ACM Transactions on Programming Languages and Systems (TOPLAS), 36, 1 (2014).Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Ravi Chugh, Patrick M. Rondon, and Ranjit Jhala. 2012. Nested Refinements for Dynamic Languages. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  12. Lukas Diekmann and Laurence Tratt. 2020. Don’t Panic! Better, Fewer, Syntax Errors for LR Parsers. In European Conference on Object-Oriented Programming (ECOOP).Google ScholarGoogle Scholar
  13. Cormac Flanagan. 1997. Effective Static Debugging via Componential Set-based Analysis. Ph.D. Dissertation. Rice University.Google ScholarGoogle Scholar
  14. Cormac Flanagan, Matthew Flatt, Shriram Krishnamurthi, Stephanie Weirich, and Matthias Felleisen. 1996. Catching Bugs in the Web of Program Invariants. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI).Google ScholarGoogle Scholar
  15. Michael Furr, Jong-hoon David An, and Jeffrey S. Foster. 2009. Profile-Guilding Static Typing for Dynamic Scripting Languages. In ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages and Applications (OOPSLA).Google ScholarGoogle Scholar
  16. Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  17. Michael Greenberg. 2013. Manifest Contracts. Ph.D. Dissertation. University of Pennsylvania.Google ScholarGoogle Scholar
  18. Ben Greenman and Matthias Felleisen. 2018. A Spectrum of Type Soundness and Performance. 2, ICFP (2018).Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Ben Greenman and Zeina Migeed. 2018. On the Cost of Type-Tag Soundness. In ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation (PEPM).Google ScholarGoogle Scholar
  20. Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. 2011. Typing Local Control and State Using Flow Analysis. In European Symposium on Programming (ESOP).Google ScholarGoogle Scholar
  21. Vincent J. Hellendoorn, Christian Bird, Earl T. Barr, and Miltiadis Allamanis. 2018. Deep Learning Type Inference. In ACM SIGSOFT Symposium on the Foundations of Software Engineering (FSE).Google ScholarGoogle Scholar
  22. Fritz Henglein. 1994. Dynamic typing: syntax and proof theory. Science of Computer Programming, 22, 3 (1994), 197–230.Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Fritz Henglein and Jakob Rehof. 1995. Safe polymorphic type inference for a dynamically typed language: Translating Scheme to ML. In International Conference on Functional Programming Languages and Computer Architecture (FPCA).Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. David Herman, Aaron Tomb, and Cormac Flanagan. 2011. Space-efficient gradual typing. Higher-Order and Symbolic Computation (HOSC), 23, 2 (2011), 167–189.Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Milod Kazerounian, Brianna M. Ren, and Jeffrey S. Foster. 2020. Sound, Heuristic Type Annotation Inference for Ruby. In Dynamic Languages Symposium (DLS).Google ScholarGoogle Scholar
  26. Andre Kuhlenschmidt, Deyaaeldeen Almahallawi, and Jeremy G. Siek. 2019. Toward Efficient Gradual Typing for Structural Types via Coercions. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI).Google ScholarGoogle Scholar
  27. Rabee Sohail Malik, Jibesh Patra, and Michael Pradel. 2019. NL2Type: Inferring JavaScript Function Types from Natural Language Information. In International Conference on Software Engineering (ICSE).Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Zeina Migeed and Jens Palsberg. 2020. What is Decidable about Gradual Types? Proceedings of the ACM on Programming Languages (PACMPL), 4, POPL (2020).Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Yusuke Miyazaki, Taro Sekiyama, and Atsushi Igarashi. 2019. Dynamic Type Inference for Gradual Hindley–Milner Typing. Proceedings of the ACM on Programming Languages (PACMPL), 3, POPL (2019).Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Zvonimir Pavlinovic, Tim King, and Thomas Wies. 2014. Finding Minimum Type Error Sources. In ACM SIGPLAN Conference on Object Oriented Programming, Systems, Languages and Applications (OOPSLA).Google ScholarGoogle Scholar
  31. Luna Phipps-Costin, Carolyn Jane Anderson, Michael Greenberg, and Arjun Guha. 2021. Solver-based Gradual Type Migration. arxiv:2109.05049.Google ScholarGoogle Scholar
  32. Michael Pradel, Georgios Gousios, Jason Liu, and Satish Chandra. 2020. TypeWriter: Neural Type Prediction with Search-Based Validation. In Joint Meeting of the European Software Engineering Conference (ESEC) and the ACM SIGSOFT Symposium on the Foundations of Software Engineering (FSE).Google ScholarGoogle Scholar
  33. Aseem Rastogi, Avik Chaudhuri, and Basil Hosmer. 2012. The Ins and Outs of Gradual Type Inference. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  34. Brianna M. Ren and Jeffrey S. Foster. 2016. Just-in-Time Static Type Checking for Dynamic Languages. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI).Google ScholarGoogle Scholar
  35. Claudiu Saftoiu. 2010. JSTrace: Run-time type discovery for JavaScript. Master’s thesis. Brown University.Google ScholarGoogle Scholar
  36. Jeremy Siek, Peter Thiemann, and Philip Wadler. 2015. Blame and Coercion: Together Again for the First Time. In ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI).Google ScholarGoogle Scholar
  37. Jeremy Siek, Michael Vitousek, Matteo Cimini, and John Boyland. 2015. Refined Criteria for Gradual Typing. In Summit oN Advances in Programming Languages (SNAPL).Google ScholarGoogle Scholar
  38. Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop (SW).Google ScholarGoogle Scholar
  39. Jeremy G. Siek and Manish Vachharajani. 2008. Gradual Typing with Unification-based Inference. In Dynamic Languages Symposium (DLS).Google ScholarGoogle Scholar
  40. Jeremy G. Siek, Michael M. Vitousek, Matteo Cimini, Sam Tobin-Hochstadt, and Ronald Garcia. 2015. Monotonic References for Efficient Gradual Typing. In European Symposium on Programming (ESOP).Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage Migration: From Scripts to Programs. In Dynamic Languages Symposium (DLS).Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Sam Tobin Hochstadt and Matthias Felleisen. 2008. The Design and Implementation of Typed Scheme. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  43. Panagiotis Vekris, Benjamin Cosman, and Ranjit Jhala. 2015. Trust, but Verify: Two-Phase Typing for Dynamic Languages. In European Conference on Object-Oriented Programming (ECOOP).Google ScholarGoogle Scholar
  44. Michael M. Vitousek, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. In Dynamic Languages Symposium (DLS).Google ScholarGoogle Scholar
  45. Michael M. Vitousek, Cameron Swords, and Jeremy G. Siek. 2017. Big Types in Little Runtime: Open-World Soundness and Collaborative Blame for Gradual Type Systems. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google ScholarGoogle Scholar
  46. Jiayi Wei, Maruth Goyal, Greg Durrett, and Isil Dillig. 2020. LambdaNet: Probabilistic Type Inference using Graph Neural Networks. In International Conference on Learning Representations (ICLR).Google ScholarGoogle Scholar
  47. Andrew K. Wright and Robert Cartwright. 1997. A Practical Soft Type System for Scheme. ACM Transactions on Programming Languages and Systems (TOPLAS), 19, 1 (1997), 87–152.Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Solver-based gradual type migration

    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

    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!