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.
Supplemental Material
- 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 Scholar
- Christopher Anderson, Paola Giannini, and Sophia Drossopoulou. 2005. Towards Type Inference for JavaScript. In European Conference on Object-Oriented Programming (ECOOP).Google Scholar
- 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 Scholar
Cross Ref
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Cormac Flanagan. 1997. Effective Static Debugging via Componential Set-based Analysis. Ph.D. Dissertation. Rice University.Google Scholar
- 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 Scholar
- 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 Scholar
- Ronald Garcia and Matteo Cimini. 2015. Principal Type Schemes for Gradual Programs. In ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL).Google Scholar
- Michael Greenberg. 2013. Manifest Contracts. Ph.D. Dissertation. University of Pennsylvania.Google Scholar
- Ben Greenman and Matthias Felleisen. 2018. A Spectrum of Type Soundness and Performance. 2, ICFP (2018).Google Scholar
Digital Library
- 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 Scholar
- Arjun Guha, Claudiu Saftoiu, and Shriram Krishnamurthi. 2011. Typing Local Control and State Using Flow Analysis. In European Symposium on Programming (ESOP).Google Scholar
- 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 Scholar
- Fritz Henglein. 1994. Dynamic typing: syntax and proof theory. Science of Computer Programming, 22, 3 (1994), 197–230.Google Scholar
Digital Library
- 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 Scholar
Digital Library
- David Herman, Aaron Tomb, and Cormac Flanagan. 2011. Space-efficient gradual typing. Higher-Order and Symbolic Computation (HOSC), 23, 2 (2011), 167–189.Google Scholar
Digital Library
- Milod Kazerounian, Brianna M. Ren, and Jeffrey S. Foster. 2020. Sound, Heuristic Type Annotation Inference for Ruby. In Dynamic Languages Symposium (DLS).Google Scholar
- 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 Scholar
- 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 Scholar
Digital Library
- Zeina Migeed and Jens Palsberg. 2020. What is Decidable about Gradual Types? Proceedings of the ACM on Programming Languages (PACMPL), 4, POPL (2020).Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- Luna Phipps-Costin, Carolyn Jane Anderson, Michael Greenberg, and Arjun Guha. 2021. Solver-based Gradual Type Migration. arxiv:2109.05049.Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
- Claudiu Saftoiu. 2010. JSTrace: Run-time type discovery for JavaScript. Master’s thesis. Brown University.Google Scholar
- 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 Scholar
- Jeremy Siek, Michael Vitousek, Matteo Cimini, and John Boyland. 2015. Refined Criteria for Gradual Typing. In Summit oN Advances in Programming Languages (SNAPL).Google Scholar
- Jeremy G. Siek and Walid Taha. 2006. Gradual Typing for Functional Languages. In Scheme and Functional Programming Workshop (SW).Google Scholar
- Jeremy G. Siek and Manish Vachharajani. 2008. Gradual Typing with Unification-based Inference. In Dynamic Languages Symposium (DLS).Google Scholar
- 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 Scholar
Digital Library
- Sam Tobin-Hochstadt and Matthias Felleisen. 2006. Interlanguage Migration: From Scripts to Programs. In Dynamic Languages Symposium (DLS).Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
- Michael M. Vitousek, Jeremy G. Siek, and Jim Baker. 2014. Design and Evaluation of Gradual Typing for Python. In Dynamic Languages Symposium (DLS).Google Scholar
- 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 Scholar
- 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 Scholar
- 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 Scholar
Digital Library
Index Terms
Solver-based gradual type migration
Recommendations
Principal Type Schemes for Gradual Programs
POPL '15: Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesGradual typing is a discipline for integrating dynamic checking into a static type system. Since its introduction in functional languages, it has been adapted to a variety of type systems, including object-oriented, security, and substructural. This ...
Gradual typing with unification-based inference
DLS '08: Proceedings of the 2008 symposium on Dynamic languagesStatic and dynamic type systems have well-known strengths and weaknesses. Gradual typing provides the benefits of both in a single language by giving the programmer control over which portions of the program are statically checked based on the presence ...
Putting Gradual Types to Work
Practical Aspects of Declarative LanguagesAbstractIn this paper, we describe our experience incorporating gradual types in a statically typed functional language with Hindley-Milner style type inference. Where most gradually typed systems aim to improve static checking in a dynamically typed ...






Comments