Dissertation Presented to the Faculty of the Graduate School of Cornell University

Total Page:16

File Type:pdf, Size:1020Kb

Dissertation Presented to the Faculty of the Graduate School of Cornell University 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...................
Recommended publications
  • Why Do Developers Neglect Exception Handling?
    Why Do Developers Neglect Exception Handling? Hina Shah, Carsten Görg, Mary Jean Harrold College of Computing, Georgia Institute of Technology, Atlanta, Georgia, U.S.A. {hinashah,goerg,harrold}@cc.gatech.edu ABSTRACT code. However, in these proposed approaches both types of code In this paper, we explore the problems associated with exception (main functionality code and exception handling code) would still handling from a new dimension: the human. We designed a study be implemented by the same developer. Filho and colleagues [2, that evaluates (1) different perspectives of software developers to 3] suggest lexically separating error-handling code from normal understand how they perceive exception handling and what meth- code so that both code types can be independently modified. In ods they adopt to deal with exception handling constructs, and (2) addition they propose leveraging aspect-oriented programming to the usefulness of a visualization tool that we developed in previ- enhance the separation between error-handling code and normal ous work for exception handling. We describe the design of our code. Zhang and colleagues [10] propose a different approach that study, present details about the study’s participants, describe the provides programmers with more intuitive exception-handling be- interviews we conducted with the participants, present the results havior and control. of the study, and discuss what we learned from the study. Based All these approaches concentrate on enhancing the separation on our analysis, we suggest several
    [Show full text]
  • SWI-Prolog 5.8.1 Reference Manual In
    University of Amsterdam Kruislaan 419, 1098 VA Amsterdam VU University Amsterdam De Boelelaan 1081a, 1081 HV Amsterdam The Netherlands SWI-Prolog 5.8 Reference Manual Updated for version 5.8.1, November 2009 Jan Wielemaker [email protected] http://www.swi-prolog.org SWI-Prolog is a Prolog implementation based on a subset of the WAM (Warren Ab- stract Machine). SWI-Prolog was developed as an open Prolog environment, providing a powerful and bi-directional interface to C in an era this was unknown to other Prolog implementations. This environment is required to deal with XPCE, an object-oriented GUI system developed at SWI. XPCE is used at SWI for the development of knowledge- intensive graphical applications. As SWI-Prolog became more popular, a large user-community provided requirements that guided its development. Compatibility, portability, scalability, stability and provid- ing a powerful development environment have been the most important requirements. Edinburgh, Quintus, SICStus and the ISO-standard guide the development of the SWI- Prolog primitives. This document gives an overview of the features, system limits and built-in predicates. Copyright c 1990–2009, University of Amsterdam Contents 1 Introduction 10 1.1 SWI-Prolog....................................... 10 1.1.1 Books about Prolog............................... 10 1.2 Status.......................................... 11 1.3 Compliance to the ISO standard............................ 11 1.4 Should you be using SWI-Prolog?........................... 11 1.5 The XPCE GUI system for Prolog........................... 12 1.6 Release Notes...................................... 13 1.7 Donate to the SWI-Prolog project........................... 19 1.8 Acknowledgements................................... 19 2 Overview 21 2.1 Getting started quickly................................
    [Show full text]
  • Accepting Blame for Safe Tunneled Exceptions
    Accepting Blame for Safe Tunneled Exceptions Yizhou Zhang∗ Guido Salvaneschiy Quinn Beightol∗ Barbara Liskovz Andrew C. Myers∗ ∗Cornell University, USA yTU Darmstadt, Germany zMIT, USA [email protected] [email protected] [email protected] [email protected] [email protected] Abstract 1. Introduction Unhandled exceptions crash programs, so a compile-time Exceptions make code more reliable by helping programmers check that exceptions are handled should in principle make handle abnormal or unusual run-time conditions. The core software more reliable. But designers of some recent lan- idea is to transfer control in a nonlocal way to handler code guages have argued that the benefits of statically checked ex- that can be factored out from common-case code. This sepa- ceptions are not worth the costs. We introduce a new stati- ration of concerns simplifies code and prompts programmers cally checked exception mechanism that addresses the prob- not to forget about exceptional conditions. lems with existing checked-exception mechanisms. In partic- There has been disagreement since the 1970’s about how ular, it interacts well with higher-order functions and other or whether exceptions should be subject to static check- design patterns. The key insight is that whether an excep- ing [19, 28]. This disagreement continues to the present tion should be treated as a “checked” exception is not a prop- day [17]. Some currently popular languages—Java [20] and erty of its type but rather of the context in which the excep- Swift [46]—offer checked exceptions that the compiler stati- tion propagates. Statically checked exceptions can “tunnel” cally ensures are handled.
    [Show full text]
  • NAHS Technology and Business Department Introduction to Programming Curriculum Map
    NAHS Technology and Business Department Introduction to Programming Curriculum Map NAHS Technology and Business Department Introduction to Programming Curriculum Map Overview In this course, students are introduced to the fundamentals of computer programming. Students will explore programming concepts such as input/output, variables, methods, control logic, looping, arrays, classes, encapsulation, inheritance, and exception handling using both a graphical and text-based interface. Students will become proficient in code design, development, and testing process by applying these concepts to create various puzzles, forms, and games Curriculum Components • History of computers o Original needs that led to computer development o Historical figures related to the development of computers o The role of government in the development of computers o Computer generations & their characteristics • History of programming languages o The role of a computer program o Differences between computers and humans o Programming language generations and their characteristics o Characteristics of structured programming • Number Systems o Understanding number systems used by computers, understanding why they are used, and physical conversion among them • Programming concepts o Object oriented programming o Information hiding/encapsulation o Concepts related to classes, objects, and instances • Programming Lifecycle o Designing o Building the interface o Adding code o Testing o Concepts involved with building the final application (stand-alone) and understanding the difference between source code and object (executable) code Revised 10/31/10 1 NAHS Technology and Business Department Introduction to Programming Curriculum Map • Objects and Event Handlers o Understand what causes events to be “fired” o Using the appropriate event handler o Using the appropriate object for the intended job • Programming concepts o Assigning values to properties o The concept of datatypes o New dataype: strings o Handling basic syntax errors.
    [Show full text]
  • Expressive Checked Exceptions
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by eCommons@Cornell Accepting Blame: Expressive Checked Exceptions Yizhou Zhang∗ Guido Salvaneschiy Quinn Beightol∗ Barbara Liskovz Andrew C. Myers∗ ∗Cornell University yTU Darmstadt zMIT [email protected] [email protected] [email protected] [email protected] [email protected] April, 2016 Abstract Unhandled exceptions crash programs, so a compile-time check that exceptions are handled should in principle make software more reliable. But designers of some recent languages have argued that the benefits of statically checked exceptions are not worth the costs. We introduce a new statically checked exception mechanism that addresses the problems with existing checked-exception mechanisms. In par- ticular, it interacts well with higher-order functions and other design patterns. The key insight is that whether an exception should be treated as a “checked” exception is not a property of its type but rather of the context in which the exception propagates. Statically checked exceptions can “tunnel” through code that is oblivious to their presence, but the type system nevertheless checks that these exceptions are handled. Further, exceptions can be tunneled without being accidentally caught, by expanding the space of exception identifiers to identify the exception-handling context. The resulting mechanism is ex- pressive and syntactically light, and can be implemented efficiently. We demonstrate the expressiveness of the mechanism using significant codebases and evaluate its performance. We have implemented this new exception mechanism as part of the new Genus programming language, but the mechanism could equally well be applied to other programming languages.
    [Show full text]
  • Technical Report on C++ Performance
    ISO/IEC TR 18015:2004(E) 2005-06-15 Information Technology — Programming languages, their environments and system software interfaces Technical Report on C++ Performance Technical Report on C++ Performance ISO/IEC TR 18015:2004(E) Contents Contents ......................................................................................2 Foreword ......................................................................................4 Introduction ......................................................................................5 1 Scope ......................................................................................7 2 Normative References .....................................................................8 3 Terms and definitions .....................................................................9 4 Typical Application Areas ............................................................. 18 4.1 Embedded Systems.......................................................................................................18 4.2 Servers.............................................................................................................................20 5 Language Features: Overheads and Strategies .......................... 21 5.1 Namespaces ...................................................................................................................21 5.2 Type Conversion Operators........................................................................................22 5.3 Classes and Inheritance................................................................................................23
    [Show full text]