
DESIGNING FLEXIBLE, MODULAR LINGUISTIC ABSTRACTIONS 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 Yizhou Zhang August 2019 © 2019 Yizhou Zhang ALL RIGHTS RESERVED DESIGNING FLEXIBLE, MODULAR LINGUISTIC ABSTRACTIONS Yizhou Zhang, Ph.D. Cornell University 2019 Programming-language design is more active than ever: existing languages are evolving continually and rapidly, and new languages keep springing up. While this constant iteration of language design aims to help programmers manage a growing software complexity, programmers are still frequently frustrated by poor design decisions in even the most essential aspects of modern program- ming languages. Less than satisfactory solutions to generic programming and exception handling typify this situation: the inadequacy of current solutions has even forced language designers to abandon these problematic language features. This is an unfortunate state of affairs. Language design does not have to be about abandoning old features or piling on new ones. This dissertation proposes novel linguistic abstractions for the aforementioned design problems, offering ease of use, expressive power, strong guarantees, and good performance all at the same time. It introduces a new mechanism for generic programming, embodied in the Genus programming language. Genus adds expressive power and strengthens static checking, while handling common usage patterns simply. The power of Genus is then integrated into a second language design, Familia, that unifies several polymorphism mechanisms in a lightweight package. Evaluation sug- gests the design of Genus and Familia addresses the need for genericity and extensibility in developing large, complex software. This dissertation also introduces a new mechanism for exception handling. By allowing exceptions to tunnel through handlers, the design offers both the static assurance of checked exceptions and the flexibility of unchecked exceptions. This tunneling semantics is then generalized to a broader class of control effects to address a fundamental modularity problem: it prevents effect-polymorphic abstractions from handling effects by accident. This claim about abstraction safety is formally accounted for. We hope that the language-design ideas presented here will make their way into mainstream programming languages and help make it easier to write and reason about software. BIOGRAPHICAL SKETCH Yizhou Zhang (Chinese: y2) grew up in Changzhou, where he attended Changzhou High Schoool. He obtained a Bacholor of Science in Software En- gineering from Shanghai Jiao Tong University. Intrigued by research on pro- gramming languages, Yizhou applied to and entered the Computer Science Ph.D. program at Cornell University. Yizhou obtained a Masters of Science in Computer Science in 2016, and was awarded his Ph.D. in 2019. iii For my family iv ACKNOWLEDGMENTS I am deeply indebted to my advisor, Andrew Myers, by whom my intellectual growth and academic character were heavily influenced. I thank Andrew for his unfailing support and incisive guidance, and also for the latitude in working on things that most interest me. His intellectual depth and breadth, his scientific creativity and curiosity, his taste for research problems, and his enthusiasm for research and teaching have been a constant source of inspiration. I am grateful to my other special-committee members, Dexter Kozen, Ross Tate, and Bart Selman, for their encouragement and for their useful critiques on the dissertation work. Barbara Liskov and Guido Salvaneschi have been role models and great collaborators. I benefited immensely from working on the Genus project with Andrew, Barbara, and Guido in my earlier years as a Ph.D. student. I learned how to do research by watching them doing it. Over the years, I had the great pleasure to work alongside many incredible researchers and students at Cornell. Jed Liu, K. Vikram, Danfeng Zhang, Owen Arden, Chinawat Isradisaikul, Tom Magrino, Isaac Sheff, Matthew Milano, Ethan Cecchetti, Rolph Recto, Drew Zagieboylo, Josh Acay, and Siqiu Yao made the Ap- plied Programming Languages Group a truly enjoyable environment to discuss research and provide feedback. Matthew Loring, Quinn Beightol, Jonathan Chan, Matthew Gharrity, Daniel Weber, and Jacopo Banfi were a delight to work with. Heartfelt thanks to Yang Yuan, Chen Wang, and many others for their friendship. I thank my parents for providing me with a good education and for being loving and supportive throughout the journey. v vi TABLE OF CONTENTS Biographical Sketch.............................. iii Dedication................................... iv Acknowledgments..............................v Table of Contents............................... vii List of Tables..................................x List of Figures................................. xi 1 Introduction1 1.1 Fixing the Tragedy of Exceptions...................2 1.2 Protecting Abstraction against Accidental Handling........3 1.3 Redesigning Generics for Object-Oriented Languages.......4 1.4 A Deep Unification of Polymorphism Mechanisms.........5 1.5 Roadmap and Published Work....................6 2 Accepting Blame for Tunneled Exceptions7 2.1 Design Principles for Exceptions...................9 2.1.1 Higher-Order Functions and Exceptions........... 11 2.1.2 Our Approach.......................... 12 2.2 The Exception Mechanism....................... 13 2.2.1 Failures............................. 14 2.2.2 Avoiding Exception Capture................. 15 2.2.3 Fail-by-Default Exceptions.................. 16 2.3 Higher-Order Abstractions and Tunneling.............. 16 2.3.1 Exception Tunneling is Safe and Lightweight........ 18 2.3.2 Tunneling Checked Exceptions................ 21 2.3.3 Tunneling, Exception Capture, and Blame.......... 22 2.3.4 Weak Types........................... 24 2.4 Generics and Exceptions........................ 26 2.5 Exactness Analysis........................... 28 2.5.1 Exactness Annotations and Exactness Defaults....... 29 2.5.2 Solving Exactness Constraints................ 32 2.5.3 Exactness-Dependent Types.................. 34 2.6 Formalization.............................. 35 2.6.1 Syntax and Notations..................... 35 2.6.2 Semantics............................ 36 2.6.3 Type Safety........................... 39 2.7 Implementation............................. 41 2.7.1 Representing Exceptions in Non-Checked Modes..... 42 2.7.2 Translating Exception-Oblivious Code............ 42 2.7.3 Translating Exception-Aware Code.............. 43 2.7.4 Translating Failure Exceptions................ 45 2.8 Evaluation................................ 46 vii 2.8.1 Porting Java Code to Use Genus Exceptions........ 46 2.8.2 Performance........................... 47 2.9 Related Work.............................. 50 3 Abstraction-Safe Effect Handlers 53 3.1 Algebraic Effects and Accidental Handling............. 56 3.1.1 Algebraic Effects and Handlers................ 56 3.1.2 Accidentally Handled Effects Violate Abstraction..... 59 3.2 Tunneled Algebraic Effects....................... 63 3.2.1 Tunneling Restores Modularity................ 64 3.2.2 Tunneling Preserves the Expressivity of Dynamic Scoping 65 3.2.3 Accomplishing Tunneling by Statically Choosing Handlers 67 3.2.4 Region Capabilities as Computational Effects........ 71 3.2.5 Implementation......................... 74 3.3 A Core Language............................ 75 3.3.1 Syntax.............................. 75 3.3.2 Operational Semantics..................... 79 3.3.3 Static Semantics......................... 81 3.3.4 Contextual Refinement and Equivalence.......... 85 3.4 A Sound Logical-Relations Model................... 88 3.4.1 Step Indexing.......................... 88 3.4.2 World Indexing......................... 89 3.4.3 A Biorthogonal Term Relation................ 90 3.4.4 Semantic Types, Semantic Effect Signatures, and Semantic Effects.............................. 92 3.4.5 Properties of the Logical Relations.............. 95 3.5 Proving Example Equivalence..................... 101 3.6 Related Work.............................. 104 4 Genus: Lightweight, Flexible Object-Oriented Generics 109 4.1 The Need for Better Genericity.................... 111 4.2 Type Constraints in Genus....................... 114 4.2.1 Type Constraints as Predicates................ 114 4.2.2 Prescribing Constraints Using Where Clauses....... 118 4.2.3 Witnessing Constraints Using Models............ 119 4.3 Models.................................. 121 4.3.1 Models as Expanders...................... 122 4.3.2 Parameterized Models..................... 122 4.3.3 Non-Uniquely Witnessing Constraints............ 123 4.3.4 Resolving Default Models................... 124 4.3.5 Models in Types........................ 126 4.3.6 Models at Run Time...................... 127 4.3.7 Default Model Resolution: Algorithmic Issues....... 128 4.3.8 Constraints/Models vs. Interfaces/Objects......... 129 viii 4.4 Making Models Object-Oriented................... 130 4.4.1 Dynamic Dispatching and Enrichment........... 130 4.4.2 Constraint Entailment..................... 132 4.4.3 Model Inheritance....................... 133 4.5 Use-Site Genericity........................... 133 4.5.1 Existential Types........................ 134 4.5.2 Explicit Local Binding..................... 136 4.6 Implementation............................. 137 4.6.1 Implementing Constraints and Models........... 137 4.6.2 Implementing Generics...................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages243 Page
-
File Size-