Solver-based gradual type migration

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.

[1]  Jim Baker,et al.  Design and evaluation of gradual typing for python , 2014, DLS.

[2]  Laurence Tratt,et al.  Don't Panic! Better, Fewer, Syntax Errors for LR Parsers , 2018, ECOOP.

[3]  Nikolaj Bjørner,et al.  νZ - An Optimizing SMT Solver , 2015, TACAS.

[4]  What is decidable about gradual types? , 2019, Proc. ACM Program. Lang..

[5]  Robert Cartwright,et al.  A practical soft type system for scheme , 1997, TOPL.

[6]  Brian W. Kernighan,et al.  Timing trials, or the trials of timing: experiments with scripting and user-interface languages , 1998 .

[7]  Robert Bruce Findler,et al.  Operational semantics for multi-language programs , 2007, POPL '07.

[8]  Matteo Cimini,et al.  Principal Type Schemes for Gradual Programs , 2015, POPL.

[9]  Cormac Flanagan,et al.  Space-efficient gradual typing , 2010, High. Order Symb. Comput..

[10]  Cormac Flanagan,et al.  Effective Static Debugging via Compential Set-Based Analysis , 1997 .

[11]  Sam Tobin-Hochstadt,et al.  Interlanguage migration: from scripts to programs , 2006, OOPSLA '06.

[12]  S FosterJeffrey,et al.  Profile-guided static typing for dynamic scripting languages , 2009 .

[13]  Sam Tobin-Hochstadt,et al.  The design and implementation of typed scheme , 2008, POPL '08.

[14]  Ranjit Jhala,et al.  Trust, but Verify: Two-Phase Typing for Dynamic Languages , 2015, ECOOP.

[15]  Sam Tobin-Hochstadt,et al.  Monotonic References for Efficient Gradual Typing , 2015, ESOP.

[16]  Jeremy G. Siek Gradual Typing for Functional Languages , 2006 .

[17]  Ben Greenman,et al.  On the cost of type-tag soundness , 2017, PEPM.

[18]  Ravi Chugh,et al.  Nested Refinements for Dynamic Languages , 2011 .

[19]  Jan Vitek,et al.  Thorn: robust, concurrent, extensible scripting on the JVM , 2009, OOPSLA '09.

[20]  Jeremy G. Siek,et al.  Big types in little runtime: open-world soundness and collaborative blame for gradual type systems , 2017, POPL.

[21]  Shriram Krishnamurthi,et al.  Typing Local Control and State Using Flow Analysis , 2011, ESOP.

[22]  Jeffrey S. Foster,et al.  Just-in-time static type checking for dynamic languages , 2016, PLDI 2016.

[23]  Philip Wadler,et al.  Blame and coercion: together again for the first time , 2015, Journal of Functional Programming.

[24]  Manish Vachharajani,et al.  Gradual typing with unification-based inference , 2008, DLS '08.

[25]  Jeremy G. Siek,et al.  Toward efficient gradual typing for structural types via coercions , 2019, PLDI.

[26]  P. K. Dubey,et al.  Recognition, Mining and Synthesis Moves Comp uters to the Era of Tera , 2005 .

[27]  Georgios Gousios,et al.  TypeWriter: neural type prediction with search-based validation , 2020, ESEC/SIGSOFT FSE.

[28]  Jeffrey S. Foster,et al.  Sound, heuristic type annotation inference for Ruby , 2020, DLS.

[29]  Fritz Henglein,et al.  Dynamic Typing: Syntax and Proof Theory , 1994, Sci. Comput. Program..

[30]  Zvonimir Pavlinovic,et al.  Finding minimum type error sources , 2014, Software Engineering & Management.

[31]  Claudiu Saftoiu JSTrace: Run-time Type Discovery for JavaScript , 2010 .

[32]  John Tang Boyland,et al.  Refined Criteria for Gradual Typing , 2015, SNAPL.

[33]  Paul Graham ANSI Common Lisp , 1995 .

[34]  Atsushi Igarashi,et al.  Dynamic type inference for gradual Hindley–Milner typing , 2018, Proc. ACM Program. Lang..

[35]  Giuseppe Castagna,et al.  Gradual typing: a new perspective , 2019, Proc. ACM Program. Lang..

[36]  Martin Erwig,et al.  Migrating gradual types , 2018, Proc. ACM Program. Lang..

[37]  Isil Dillig,et al.  LambdaNet: Probabilistic Type Inference using Graph Neural Networks , 2020, ICLR.

[38]  Michael Pradel,et al.  NL2Type: Inferring JavaScript Function Types from Natural Language Information , 2019, 2019 IEEE/ACM 41st International Conference on Software Engineering (ICSE).

[39]  Jean-Baptiste Jeannin,et al.  Type inference for static compilation of JavaScript , 2016, OOPSLA.

[40]  Christian Bird,et al.  Deep learning type inference , 2018, ESEC/SIGSOFT FSE.

[41]  Cesare Tinelli,et al.  An Abstract Decision Procedure for a Theory of Inductive Data Types , 2007, J. Satisf. Boolean Model. Comput..

[42]  Sophia Drossopoulou,et al.  Towards Type Inference for JavaScript , 2005, ECOOP.

[43]  Fritz Henglein,et al.  Safe polymorphic type inference for a dynamically typed language: translating Scheme to ML , 1995, FPCA '95.

[44]  Eric Walkingshaw,et al.  Casts and costs: harmonizing safety and performance in gradual typing , 2018, Proc. ACM Program. Lang..

[45]  Avik Chaudhuri,et al.  The ins and outs of gradual type inference , 2012, POPL '12.

[46]  Matthias Felleisen,et al.  Catching bugs in the web of program invariants , 1996, PLDI '96.

[47]  Matthias Felleisen,et al.  A spectrum of type soundness and performance , 2018, Proc. ACM Program. Lang..

[48]  Martin Erwig,et al.  Extending Type Inference to Variational Programs , 2014, ACM Trans. Program. Lang. Syst..

[49]  Richard P. Gabriel,et al.  Performance and evaluation of Lisp systems , 1985 .

[50]  Avik Chaudhuri,et al.  Dynamic inference of static types for ruby , 2011, POPL '11.