
Decidable Subtyping for Path Dependent Types by Julian Mackay A thesis submitted to the Victoria University of Wellington in fulfilment of the requirements for the degree of Doctor of Philosophy in Computer Science. Victoria University of Wellington 2020 Abstract Path dependent types form a central component of the Scala programming language. Coupled with other expressive type forms, path dependent types provide for a diverse set of concepts and patterns, from nominality to F- bounded polymorphism. Recent years have seen much work aimed at for- malising the foundations of path dependent types, most notably a hard won proof of type safety. Unfortunately subtyping remains undecidable, present- ing problems for programmers who rely on the results of their tools. One such tool is Dotty, the basis for the upcoming Scala 3. Another is Wyvern, a new programming language that leverages path dependent types to sup- port both first class modules and parametric polymorphism. In this thesis I investigate the issues with deciding subtyping in Wyvern. I define three decidable variants that retain several key instances of expressiveness includ- ing the ability to encode nominality and parametric polymorphism. Wyvfix fixes types to the contexts they are defined in, thereby eliminating expansive environments. Wyvnon-µ removes recursive subtyping, thus removing the key source of expansive environments during subtyping. Wyvµ places a syntactic restriction on the usage of recursive types. I discuss the formal properties of these variants, and the implications each has for expressing the common programming patterns of path dependent types. I have also mechanized the proofs of decidability for both Wyvfix and Wyvµ in Coq Chapter 0 ii Acknowledgments I would most especially like to acknowledge the tremendous support given by my supervisors, Alex Potanin, Lindsay Groves and Jonathan Aldrich. My supervisors have guided and advised me, and are owed much of the credit for the work within this thesis. I would like to thank the input to this work from Ross Tate, who’s in- valuable insight and advice changed the entire trajectory of the research in this thesis. I would also like to thank the examiners for their work in evaluating this thesis. I am also grateful to the friendship I have received from the many office mates I have had over the years, in the many offices I have occupied. While I appreciate the support and friendship of many of my colleagues, I should in particular acknowledge Michael Homer, Tim Jones, Alex Sawcuk da Silva, Chen Wong and Erin Greenwood-Thessman. I would also like to thank the wider School of Engineering and Computer Science for providing me a community over the past few years. Finally, I would like to thank my family for their support, and perhaps most importantly I recognise that I owe my partner Fiona McNamara an immense amount of emotional support. iii Chapter 0 iv Contents 1 Introduction 1 2 Background 5 2.1 Type Systems ........................... 6 2.1.1 λ-Calculus ......................... 6 2.1.2 The Simply Typed λ-Calculus: λ ! .......... 8 2.1.3 Polymorphism: System F ................ 12 2.1.4 Bounded Quantification: System< F : .......... 14 2.1.5 Properties of Type Systems ............... 18 2.1.6 Calculus of Constructions ................ 25 2.2 Object Oriented Languages ................... 26 2.2.1 Dependent Object Types ................. 27 2.2.2 Structural vs Nominal Subtyping ............ 38 2.2.3 Java ............................ 40 2.2.4 Decidability of Subtyping in Java ............ 42 2.3 Wyvern .............................. 48 2.3.1 Modules for Wyvern ................... 49 3 Issues with Subtype Decidability 51 3.1 A Core Wyvern Type System .................. 52 3.1.1 Starting with a Basic Wyvern Type System ...... 52 3.1.2 Properties of Basic Wyvern ............... 56 3.1.3 Wyvcore .......................... 62 v Chapter 0 CONTENTS 3.2 Subtype Undecidability in Wyvcore ............... 68 3.2.1 Encoding System F<:: Dependent Function Types ... 69 3.2.2 Encoding System F<:: Recursive Types ......... 74 3.2.3 Encoding Java Generics ................. 78 4 Material/Shape Separated Wyvcore 87 4.1 Designing a Material/Shape Separation for Wyvcore ...... 87 4.1.1 Relaxing The Material/Shape Separation ........ 89 4.1.2 Nominality in Wyvcore vs Java .............. 90 4.2 Formalizing The Material/Shape Separation in Wyvcore .... 98 4.2.1 Type Graphs in Wyvcore ................. 98 4.2.2 An Extended Syntax for Material/Shape Separated Wyvcore .......................... 102 5 A General Decidability Argument 105 5.1 Wyvexpand: Recursive Expansion of Wyvcore Types ....... 106 5.2 A Subtyping Algorithm for Wyvexpand .............. 108 5.3 Shape Depth ........................... 112 5.4 Termination of Subtyping Algorithm .............. 114 5.5 Fixed Environments ....................... 116 5.5.1 Wyvfix ........................... 117 5.5.2 Subtype Decidability ................... 119 5.5.3 Transitivity in Wyvfix ................... 126 6 Non-Recursive Subtyping 129 6.1 Wyvnon-µ .............................. 129 6.2 Subtype Decidability ....................... 130 6.3 Type Safety ............................ 140 6.3.1 Term Typing and Reduction ............... 140 6.3.2 Encoding Wyvnon-µ in Wadlerfest DOT ......... 144 6.4 Expressiveness .......................... 152 vi Chapter 0 CONTENTS 7 Recursive Types 155 7.1 Examples of Expressiveness with Recursive Types ....... 155 7.2 Wyvµ ............................... 159 7.2.1 Preservation of the Material/Shape Separation .... 159 7.2.2 Wyvcore −! Wyvµ .................... 160 7.2.3 Subtype Decidability ................... 161 7.3 Expressiveness of Wyvµ ..................... 170 7.4 Type Safety ............................ 172 7.4.1 Term Typing and Operational Semantics ........ 174 7.4.2 Encoding Wyvcore in DOT 2016 ............. 176 8 Conclusion 187 8.1 Contributions of this Thesis ................... 187 8.1.1 Nominality in Wyvern .................. 187 8.1.2 Decidable Variants of Wyvcore .............. 188 8.2 Future Work ........................... 190 8.2.1 Type Safety for Wyvfix .................. 190 8.2.2 Transitivity ........................ 190 8.2.3 Intersection and Union Types .............. 192 vii Chapter 0 CONTENTS viii List of Figures 2.1 λ-Calculus Syntax ........................ 7 2.2 λ-Calculus Operational Semantics ................ 7 2.3 Types in the Simply Typed λ-Calculus ............. 9 2.4 Simply Typed λ-Calculus with Booleans ............ 10 2.5 Reduction of Boolean Conditionals ............... 10 2.6 Simply Typed λ-Calculus Type Rules .............. 11 2.7 System F with Booleans ..................... 13 2.8 System F Type Rule Extension ................. 14 2.9 System F Evaluation Rule Extension .............. 14 2.10 Subtyping for System F ..................... 15 2.11 System F<: Syntax extension over System F .......... 17 2.12 System F<: Typing Rules ..................... 17 2.13 System F<: Subtyping Rules ................... 17 2.14 Non-termination of subtyping in System F<: .......... 22 2.15 Kernel F<: Subtyping Rules ................... 23 2.16 Kernel F<: Depth Measure .................... 23 > 2.17 F<: Subtyping for Universally Quantified Types ........ 24 2.18 System F<: with Objects ..................... 26 2.19 Isomorphism on Iso-Recursive Types [70] ............ 30 2.20 Wadlerfest DOT Syntax ..................... 35 2.21 Mutual Dependency between Properties of µDOT ....... 36 2.22 Structural Subtyping ....................... 38 2.23 Type Usage Graph of List .................... 44 ix Chapter 0 LIST OF FIGURES 2.24 Featherweight Wyvern Syntax of Nistor et al. ......... 49 3.1 Basic Wyvern Syntax ....................... 54 3.2 Basic Wyvern Typing ....................... 54 3.3 Basic Wyvern Subtyping ..................... 54 3.4 Syntax Directed modification to System< F : .......... 57 3.5 Syntax Directed modification to Basic Wyvern Subtyping ... 58 3.6 Syntax Directed modification to Basic Wyvern Typing .... 59 3.7 Replacing Recursive and Structure types with Recursive Type Refinement ............................ 60 3.8 Double Bounded Type Declarations with Single Bounded Type Declarations ............................ 61 3.9 Wyvcore Syntax .......................... 63 3.10 Wyvcore Typing .......................... 63 3.11 Wyvcore Type Extension ..................... 63 3.12 Wyvcore Type Extendability ................... 63 3.13 Refinement Flattening ...................... 63 3.14 Wyvcore Subtyping ........................ 64 3.15 Encoding System F<: in Wyvcore ................. 70 N 3.16 F<: Subtyping ........................... 71 N ) 3.17 F<: NAll Wyvcore S-All .................. 72 3.18 Encoding System F<: in Wyvcore without functions ...... 74 3.19 Fragment of Java Subtyping (Grigore 2017) .......... 79 3.20 Encoding Java (Grigore 2017) in Wyvcore ............ 81 3.21 Alternative form of Java Subtyping (Grigore 2017) with Ex- plicit Substitutions ........................ 82 4.1 Material/Shape Separated Wyvcore Type Extension ...... 95 4.2 Concrete Nominal Type Definitions ............... 97 4.3 Syntax for Wyvcore Type Definition Graphs ........... 99 4.4 Type Graph (Definition) of List in Wyvcore .......... 101 4.5 Separation on Material/Shape Type Names .......... 103 x Chapter 0 LIST OF FIGURES 4.6 Material/Shape Separated Wyvcore Syntax ........... 103 5.1 Type Syntax for Wyvexpand .................... 107 5.2 Unfolding Types in Wyvcore to Types in Wyvexpand ....... 108 5.3 Shape Depth Measure on Type Graphs ............
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages225 Page
-
File Size-