Efficient Runtimes for Gradual Typing
Total Page:16
File Type:pdf, Size:1020Kb
EFFICIENTRUNTIMESFORGRADUALTYPING A Dissertation Presented to the Faculty of the Graduate School of Cornell University in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy by fabian muehlboeck (mühlböck) December 2019 ©2019 Fabian Muehlboeck Some parts of this dissertation (in particular, Chapters 2, 4, 5, and 7) are based on published work where publishing rights have been transferred to the Association for Computing Machinery. For those parts, the following copyright notices are required: For Chapter 2: 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 the author(s) 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]. Copyright is held by the owner/author(s). Publication rights licensed to ACM. For the other chapters: 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 the author(s) 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]. ©2017 Copyright held by the owner/author(s). Publication rights licensed to Association for Computing Machinery. EFFICIENTRUNTIMESFORGRADUALTYPING fabian muehlboeck Cornell University, 2019 This dissertation concerns the design and implementation of programming languages featuring gradual typing—which is the idea that some parts of a program may be type-checked dynamically while others are type-checked statically. This lets programmers trade off between the costs and benefits of using static type-checking for each individual part of their program as needed, and even eventually change their decisions about those trade-offs. Designing gradually typed languages has its own trade-offs: existing gradually typed languages had to essentially decide between being efficient versus behaving in expected and safe ways. Since many of those languages were just gradually typed variants of existing languages, those trade-offs were largely forced by the original language design. Here, we look at the design questions around gradual typing in an unconstrained scenario—what if we design a new language featuring gradual typing from the ground up? In particular, we explore these questions for nominal object-oriented programming languages. Designing a new language from the ground up lets us co-design the features of the language and its implementation. Accordingly, in this dissertation, we tackle a variety of design questions of particular importance to gradual typing, such as decidable subtyping, as well as questions of iii implementation, most importantly efficient casting techniques, which we evaluate using benchmarks from the literature on efficiency in gradual typing. The results presented here show that when gradual typing is co-designed with the rest of the type system and with an eye towards efficiency, it is possible to obtain both the desired formal properties proposed so far for gradual type systems and very low overheads due to gradual typing. This points the way towards a new generation of programming languages that can be used to seamlessly transition between personal scripting or rapid prototyping and large-scale software engineering. iv BIOGRAPHICALSKETCH Fabian Muehlboeck was born in Wels, Austria. He obtained a BSc in Soft- ware & Information Engineering from TU Wien (Vienna, Austria) and an MS in Computer Science from Northeastern University (Boston, MA, United States), where he was a Fulbright Exchange Student. After obtain- ing his Ph.D. in Computer Science from Cornell, he will be a postdoctoral researcher at IST Austria. v ACKNOWLEDGMENTS This dissertation is the culmination of six years in Cornell’s PhD program and all the things that happened before then in order to get there. There are so many people to thank for providing all kinds of help and support on the way. I owe a lot of gratitude to so many friends, colleagues, and mentors—at Cornell, at Google, at Northeastern, at PBS Logitek, and at TU Wien. There are far too many of them to name them all here, but a few people and institutions stand out even more than others: First and foremost, thanks to my advisor, Ross Tate, who not only shared my vision of programming language design research that is mindful of and accessible to programming language designers in industry, but also had the expertise and patience to guide me along this path. Thanks to my other committee members, Dexter Kozen and Richard Miller, who greatly supported me and helped me learn a ton of interesting things that would have otherwise not been immediately on my path. Thanks to other co-authors, Ben Greenman and Cosmo Viola, whose skill and dedication was inspiring and who were a pleasure to work with. Thanks to Kevin Bierhoff, who gave me a great opportunity to learn about work in programming languages in industry and in particular to get lots of practical experience with intermediate code. Thanks to Matthew Milano, who was not just an amazing roommate and friend, but also an excellent rubber duck for discussing research, and who answered an insanely high amount of C++ questions. vi Thanks to Becky Stewart, who is an amazing Assistant Director of the PhD program and has skillfully shepherded many cohorts of PhD students through the program, including me. Thanks to the Cornell CS department as a whole, its faculty, staff, and students; I’ll be forever grateful that I could spend some time with you. There were many people that helped me get there; thanks in particular to my Master’s advisor Mitchell Wand and second Master’s Thesis reader Amal Ahmed at Northeastern University, and to the PhD students in the Programming Research Lab at Northeastern, in particular Paul Stansifer and Dionna Amalie Glaze, who helped tremendously with my Master’s Thesis. In turn, I only got to study at Northeastern because of the Fulbright Program—lots of thanks to the citizens of Austria and the United States, and to the Austrian Fulbright commission, for giving me this opportunity. Thanks to Franz Puntigam at TU Wien, who showed me how interesting the field of programming languages is. Thanks to the National Science Foundation, whose CAREER grant to my advisor1 funded me for most of my PhD. Lastly, thanks to my parents, Manuela and Wolfram, and the rest of my amazing family, whose love and support I have been able to count on since even before I could count. 1 This material is based upon work supported by the NSF under grant CCF-1350182. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author and do not necessarily reflect the views of the NSF. The same holds for the Fulbright program and any other people and institutions mentioned in here except for sometimes my collaborators. vii The work in this dissertation itself would be a lot worse or non-existent were it not for the helpful feedback of my thesis committee, numerous reviewers at various instances of OOPSLA, POPL, and PLDI, various mem- bers of the gradual typing research community, and the programming language research groups at Cornell, Northeastern, TU Wien, and IST Austria. Thanks in particular to Julia Belyakova, Avik Chaudhuri, Ben- jamin Chung, Jonathan DiLorenzo, Molly Feldman, Matthias Felleisen, Ronald Garcia, Ben Greenman, Tom Henzinger, Andrew Hirsch, Basil Hosmer, Andrew Kent, Dexter Kozen, Stephen Longfield, Tom Magrino, Richard Miller, Greg Morrisett, Andrew Myers, Francesco Zappa Nardelli, Max New, Artem Pelenitsyn, Benjamin Pierce, Franz Puntigam, Gregor Richards, Adrian Sampson, Isaac Sheff, Jeremy Siek, Éric Tanter, Ross Tate, Ewan Tempero, Laure Thompson, Sam Tobin-Hochstadt, Jan Vitek, Michael Vitousek, IFIP WG 2.16, the Ceylon Team, and the Kotlin Team. viii CONTENTS 0 introduction1 0.1 Gradual Typing . 1 0.2 Gradual Typing in Industry . 3 0.3 Sound Gradual Typing . 5 0.4 Use Cases for Gradual Typing . 7 0.5 A Roadmap for Practical, Sound, and Efficient Gradual Typing 10 0.5.1 Nominality and Typed Libraries . 11 0.5.2 Milestones . 11 0.6 Contributions in this Dissertation . 14 I decidable subtyping 1 overview 19 2 decidable subtyping with variant generics 23 2.1 Introduction . 23 2.2 Background . 26 2.3 Materials and Shapes . 29 2.3.1 Materials . 30 2.3.2 Shapes . 32 2.3.3 Separating Materials and Shapes . 35 2.4 Industry Compatibility . 36 2.4.1 Methodology . 36 2.4.2 Findings . 37 2.4.3 Ceylon . 39 ix x contents 2.5 Applications . 40 2.5.1 Decidability of Subtyping . 41 2.5.2 Equivalences . 46 2.5.3 Joins . 50 2.5.4 Type Variables and Constraints . 54 2.5.5 Higher Kinds . 56 2.6 Future Work . 60 2.6.1 Conditional Inheritance . 61 2.6.2 Decidable Intraprocedural Type Inference . 62 2.6.3 Virtual Types . 63 2.7 Related Work . 64 2.8 Summary . 66 3 integrated subtyping 67 3.1 Introduction . 67 3.2 Motivation . 71 3.3 Formalizing Traditional Union and Intersection Subtyping . 77 3.3.1 Declarative Subtyping . 78 3.3.2 Reductive Subtyping .