Extensible Transition System Semantics
Total Page:16
File Type:pdf, Size:1020Kb
Extensible Transition System Semantics Casper Bach Poulsen Submitted to Swansea University in fulfilment of the requirements for the Degree of Doctor of Philosophy Department of Computer Science Swansea University 2015 Declaration This work has not been previously accepted in substance for any degree and is not being concurrently submitted in candidature for any degree. Signed ............................................................ (candidate) Date ............................................................ Statement 1 This thesis is the result of my own investigations, except where otherwise stated. Other sources are acknowledged by footnotes giving explicit references. A bibliography is appended. Signed ............................................................ (candidate) Date ............................................................ Statement 2 I hereby give my consent for my thesis, if accepted, to be available for photocopying and for inter-library loan, and for the title and summary to be made available to outside organisations. Signed ............................................................ (candidate) Date ............................................................ Abstract Structural operational semantics (SOS) come in two main styles: big-step and small- step. Each style has its merits and drawbacks, and it is sometimes useful to maintain specifications in both styles. But it is both tedious and error-prone to maintain multiple specifications of the same language. Additionally, big-step SOS has poor support for language evolution, requires reformulation or introduction of new rules for existing constructs as a language is extended, and is sometimes regarded as inferior for type soundness proofs. This thesis addresses pragmatic shortcomings with giving and relat- ing extensible small-step and big-step specifications, and with big-step type soundness proofs. The thesis makes a number of contributions. First, we present Extensible SOS (XSOS), a simple but novel extension of Mosses’ Modular SOS that supports concise and extensible specification of language features for both big-step and small-step se- mantics. Second, we internalise the well-known refocusing transformation in XSOS to provide a systematic transformation between extensible small-step and big-step spec- ifications. Third, we consider types as abstract interpretations as a novel approach to big-step type soundness. Finally, we propose a novel type system for Hindley-Milner- Damas polymorphic type inference for a language with ML style references. v Acknowledgements I sincerely thank Peter Mosses for his support, encouragement, and all that he has taught me during my years in Swansea. I would also like to thank Ulrich Berger for being my second supervisor, and my examiners, Graham Hutton and Anton Setzer, for interesting discussions during my viva, and for their valuable suggestions for improving this thesis. I am grateful to Fredrik Nordvall Forsberg, Neil Sculthorpe, Peter Mosses, Paolo Torrini, and Ulrich Berger for patient proofreading and feedback on earlier ver- sions of this thesis. My thesis and I have also benefited from discussions with Martin Churchill, Ferdinand Vesely, Olivier Danvy, Jacob Johannsen, Jan Midtgaard, Andrew Tolmach, and Eelco Visser; thank you. I further thank Olivier Danvy for his inspiring lecture courses at Aarhus University, as well as his support in connection with applying for a Ph.D. in Swansea; and Eelco Visser for employing me after my Ph.D., and for his topical words about deadlines [Vis97, Acknowledgements, final paragraph]. Thanks are also due to all the people whose moral support and company I have enjoyed throughout my Ph.D. Thank you for your friendship, Phil and Emma James, Fredrik Nordvall Forsberg, Liam O’Reilly, Ferdinand Vesely and Olga Vesela, Dean Thomas, and Shannon Morrison. Thank you, Erling Midtgaard Hanssen and Dorete Bøving Larsen, for opening up your hearts and home whenever Margit and I visit home. Thank you to my family for always being there for me. A special thanks goes to my beloved Margit: thank you for agreeing to join me in moving to Swansea for our Welsh adventure, and for always being there for me, not least on the (sometimes strenuous) journey of my Ph.D. This work was supported by an EPSRC grant (EP/I032495/1) to Swansea University in connection with the PLanCompS project (www.plancomps.org). vii Table of Contents 1 Introduction 1 1.1 Motivation: promises and problems with formal specification . 2 1.2 Background: operational semantics . 3 1.3 Thesis . 9 1.4 Relationship with previous publications . 10 2 Operational Semantics in Theory and Practice 13 2.1 Prerequisites and conventions . 13 2.2 Structural operational semantics . 14 2.3 Modular SOS . 28 2.4 Natural semantics . 36 2.5 Pretty-big-step semantics . 43 2.6 Big-step Modular SOS . 51 2.7 Modularity in Denotational Semantics . 54 2.8 Reduction semantics . 59 2.9 Type soundness using operational semantics . 64 2.10 Summary . 77 3 Extensible Transition System Semantics 79 3.1 The problem with modular abrupt termination . 79 3.2 Towards a solution: abruptly terminated configurations . 80 3.3 Extensible transition systems . 80 3.4 Extensible SOS . 82 3.5 Extensible specifications for abrupt termination . 86 3.6 Correspondence with other transition system variants . 93 3.7 Assessment and related work . 94 4 Refocusing in Extensible SOS 97 4.1 Danvy and Nielsen’s refocusing transformation . 98 4.2 Refocusing in XSOS . 102 4.3 Correctness of refocusing without abrupt termination . 105 4.4 Refocusing lcbv ................................110 ix 4.5 Refocusing with abrupt termination . 112 4.6 Deriving pretty-big-step rules for delimited control . 116 4.7 Assessment and related work . 121 5 Modular Divergence in Extensible SOS 123 5.1 Divergence as modular abrupt termination . 123 5.2 Correspondence between converging and diverging computations in re- focused XSOS rules . 126 5.3 Assessment and related work . 131 6 Big-Step Type Soundness using Types as Abstract Interpretations 135 6.1 Monotype abstraction of big-step lcbv . 135 6.2 Well-foundedness and proof mechanisation in Coq . 139 6.3 Polytype abstraction . 141 6.4 Assessment and related work . 144 7 Type Inference for References using Types as Abstract Interpretations 147 7.1 Abstracting extensible specifications . 148 7.2 Extensible type soundness for lcbv+ref . 153 7.3 Assessment and related work . 162 8 Type and Effect Inference using Types as Abstract Interpretation 167 8.1 The problem with let-polymorphic generalisation with references . 168 8.2 A store-based type system . 169 8.3 Types as abstract interpretations for store-based types . 173 8.4 Assessment and related work . 179 9 Discussion and Future Directions 183 9.1 Extensible transition system semantics . 183 9.2 Refocusing in XSOS . 185 9.3 Types as abstract interpretations . 186 9.4 Modular big-step type soundness . 187 9.5 Type and effect soundness . 187 9.6 Conclusion . 187 A Proofs for Chapter 2 189 A.1 Expression sorts . 189 A.2 Correspondence between converging computations . 192 A.3 Correspondence between diverging computations . 195 B Proofs for Refocusing in XSOS 203 B.1 Proofs for Chapter 4 . 203 B.2 Proofs for Chapter 5 . 210 x C Specifications 217 C.1 Pretty-big-step semantics for lcbv• +ref . 217 C.2 Plotkin-style propagation of abrupt termination in SOS . 219 C.3 From reduction-based to reduction-free normalisation for simple arith- metic expressions . 221 xi List of Figures 2.1 Abstract syntax for simple arithmetic expressions . 17 2.2 SOS for simple arithmetic expressions . 17 2.3 SOS for simple arithmetic expressions with interleaving . 18 2.4 Reflexive-transitive closure of G L G . 19 ! ⊆ × × 2.5 Abstract syntax for lcbv (extends Figure2.1) . 20 2.6 SOS for lcbv .................................... 21 2.7 Interleaving SOS for lcbv ............................. 22 2.8 Coinductive infinite closure of ........................ 22 ! 2.9 Abstract syntax for lcbv• (extends Figure2.5) . 24 2.10 SOS for exception handling (extends Figure2.6) . 24 2.11 SOS rules for propagating exceptions in lcbv• . 25 2.12 Abstract syntax for lcbv• +ref (extends Figure2.9) . 25 2.13 Updated SOS for lcbv• fragment of lcbv• +ref ................... 26 2.14 SOS rules for ref fragment of lcbv• +ref ..................... 27 2.15 SOS rules for propagating exceptions in lcbv• +ref . 27 2.16 MSOS for simple arithmetic expressions . 31 2.17 MSOS for lcbv (extends Figure2.16) . 32 2.18 Reflexive-transitive and infinite closure of an MSOS transition relation . 32 2.19 Abstract syntax for lcbv• (extends Figure2.5) . 33 2.20 MSOS for lcbv• (extends Figure2.17) . 34 2.21 MSOS for lcbv• +ref (extends Figure2.20) . 35 2.22 Abstract syntax for printing (extends Figure2.12) . 35 2.23 MSOS for printing (extends Figure2.21) . 36 2.24 Abstract syntax and semantic values for simple arithmetic expressions . 37 2.25 Natural semantics for simple arithmetic expressions . 37 2.26 Abstract syntax and semantic values for lcbv (extends Figure2.24) . 39 2.27 Natural semantics for lcbv ............................ 40 2.28 Natural semantics divergence predicate for lcbv . 40 2.29 Abstract syntax and semantic values for lcbv• (extends Figure2.26) . 43 2.30 Natural semantics for lcbv• (extends Figure2.27) . 43 2.31 Natural semantic abrupt termination rules for lcbv• (extends Figure2.27) . 44 2.32 Natural semantic divergence predicate for lcbv• (extends Figure2.28) . 44 xii 2.33 Abstract syntax, values, and outcomes for simple arithmetic expressions . 45 2.34 Pretty-big-step