Progress in Theoretical Computer Science Editor Ronald V. Book, University of California Editorial Board Erwin Engeler, ETH Zentrum, Zurich, Switzerland Jean-Pierre Jouannaud, Universite de Paris-Sud, Orsay, France Robin Milner, Cambridge University, England Martin Wirsing, Universität Passau, Passau, Germany ALGOL-like Languages Volume2 Peter W. O'Hearn Robert D. Tennent Editors Springer Science+B usiness Media, LLC Peter O'Hearn Robert D. Tennent Dept. of Computer Science Dept. of Computing and Information Science Queen Mary&Westfield College Queen's University London E1 4NS Kingston, Ontario England Canada K7L 3N6 Library of Congress Cataloging-in-Publication Data ALGOL-like languages I Peter W. O'Hearn, Robert D. Tennent, editors. p. cm. -- (Progress in theoretical computer science) Includes bibliographical references and index. ISBN 978-1-4757-3853-7 ISBN 978-1-4757-3851-3 (eBook) DOI 10.1007/978-1-4757-3851-3 1. ALGOL (Computer program language) I. O'Hearn, Peter W. (Peter William), 1963- . II. Tennent, R. D., 1944- III. Series. QA76.73.A24A413 1997 005.13'1--dc21 96-46972 CIP Printedon acid-free paper © 1997 Springer Science+ Business Media N ew Yo rk Originally published by Birkhäuser Boston in 1997 Softcoverreprint of the bardeover 1st edition 1997 Copyright is not claimed for works ofU.S. Govemment employees. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior permission of the copyright owner. Permission to photocopy for internal or personal use of specific clients is granted by Springer Science+ Business Media, LLC for libraries and other users registered with the Copyright Clearance Center (CCC), provided that the base fee of$6.00 per copy, plus $0.20 per page is paid directly to CCC, 222 Rosewood Drive, Danvers, MA 01923, U.S.A. Special requests should be addressed directly to Springer Science+ Business Media, LLC. Cover design by R. D. Tennent and Typesmith, with apologies to Guy Steele, designer of the cover for The Little Lisper, by Daniel Friedman, Science Research Associates (1974). ISBN 978-1-4757-3853-7 Typeset by the Authors in 1EX. 9 R 7 6 5 4 3 2 1 Table of Contents Contributors vü Part IV FUNCTOR-cATEGORY SEMANTICS 1 11 Functor Categories and Store Shapes 3 Frank]. Oles 12 Using Functor Categories to Generate Intermediate Code 13 ]ohn C. Reynolds Part V SPECIFICAT ION LOGIC 39 13 Semantical Analysis of Specification Logic 41 Robert D. Tennent 14 Semantical Analysis of Specification Logic, 2 65 Peter W. O'Hearn and Robert D. Tennent Part VI PROCEDURES AND LOCAL VARIABLES 95 15 Full Abstraction for the Second-Order Subset 97 Kurt Sieber 16 Parametridty and Local Variables 109 Peter W. O'Hearn and Robert D. Tennent 17 Operationally-Based Reasoning About Local Variables 165 Andrew M. Pitts Part VII INTERFERENCE, IRREVERSffiiLITY, AND CONCURRENCY 187 18 Syntactic Control of Interference Revisited 189 Peter W. O'Hearn, A. ]ohn Power, Makoto Takeyama and Robert D. Tennent 19 Global State Considered Unnecessary 227 Uday S. Reddy 20 Linearity, Sharing and State 297 Samson Abramsky and Guy McCusker 21 The Essence of PARALLEL ALGOL 331 Stephen Brookes Contents of Volume 1 349 Contributors Samson Abramsky A. John Power Department of Computer Science Laboratory for the Foundations of University of Edinburgh Computer Science Edinburgh, U.K. EH9 3JZ Department of Computer Science [email protected] University of Edinburgh Edinburgh, U.K. EH9 3JZ Stephen Brookes [email protected] School of Computer Science Carnegie-Mellon University Uday S. Reddy Pittsburgh, PA 15213-3890 Computer Science Department [email protected] University of lllinois Mattbias Felleisen Urbana, IL 61801 [email protected] Department of Computer Science Rice University John C. Reynolds Houston, TX 77251 School of Computer Science [email protected] Carnegie Mellon University Evan Ireland Pittsburgh, PA 15213 School of Information Science [email protected] Massey University Kurt Sieher Palmerston North, New Zealand [email protected] Informatik Universität des Saarlandes Guy McCusker Saarbrücken, Germany 66041 Department of Computing [email protected] Imperial College London, U.K. SW7 2BZ Vipin Swarup [email protected] The MITRE Corporation Hurlington Road Albert R. Meyer Bedford, MA 01730 Laboratory for Computer Science [email protected] MIT Cambridge, MA 02139 Makoto Takeyama [email protected] Department of Computing Science Chalmers University of Technology and Peter W. O'Hearn Göteborg University Department of Computer Science Göteborg, Sweden S 41296 Queen Mary and Westfield College [email protected] London, U.K. E1 4NS [email protected] Robert D. Tennent Frank J. Oles Department of Computing and Mathematical Seiences Department Information Science ffiM T. J. Watson Research Center Queen's University Yorktown Heights, NY 10598 Kingston, Canada K7L 3N6 [email protected] [email protected] Andrew M. Pitts Stephen Weeks Computer Laboratory School of Computer Science University of Cambridge Carnegie Mellon University Cambridge, U.K. CB2 3QG Pittsburgh, PA 15213 [email protected] [email protected] Part IV FUNCTOR-CATEGORY SEMANTICS Chapter 11 Functor Categories and Store Shapes Frank]. Oles Contents 1 Introduction 3 2 The Utility of Functor Categories 3 3 A Category of Store Shapes 8 4 Concluding Remarks 11 References 12 1 Introduction An intuitive grasp of the nature of variable declarations and of what is hap pening as one enters and exits from blocks is essential to programming in an ALGOL-like language. However, a precise semantic description of the con structs involved is difficult, and it is particularly difficult if one wants seman tics for block structure that mesh elegantly with semantics for procedures. Our goal is to outline in general terms how functor categories can be used to explain the semantics of ALGOL-like languages which possess a rich type structure, higher-order procedures whose types may be arbitrarily complex, imperative capabilities, and block structure. It is our aim to draw a sharp dis tinction between change of state and change of underlying structure. Block entrances and block exits in connection with variable declarations change the shape of the store (underlying structure), whereas commands alter the store (state). It is our feeling that, far from being abstract nonsense, functor cate gories are a natural vehicle for giving mathematical substance to these intu itions about stack discipline. 2 The Utility of Functor Categories We think of a language as beginning with the specification of a set of data types; let's say int (for integer) and bool (for boolean). Each data type ö gives rise to three primitive phrase types ö-exp (for ö-expression), ö-var (for ö-variable), and ö-acc (for ö-acceptor). Another primitive phrase type is comm (for command). The reader probably has an excellent intuitive feeling for the nature of phrases that are assigned the phrase types ö-exp, ö-var, and comm. A phrase has type ö-acc if it gobbles up values of type ö and produces com mands. Thus, if x and y are ö-variables, then, in the assignment command x := y, the ö-variable x is used as a ö-acceptor. Even if a language turnsout Adapted by the author and the editors from material in Section 1 of F. J. Oles: "Type algebras, functor categories, and block structure," in M. Nivat and J. C. Reynolds (editors): Algebraic Methods in Semantics, © Cambridge University Press 1985 (reprinted with the permission of Cambridge University Press), andin Chapters I and V1 of F. J. Oles: A Category·Theoretic Approach to the Semantics of Programming Languages, Ph.D. thesis, Syracuse University, Syracuse, N.Y., August 1982. P. W. O’Hearn et al. (eds.), Algol -like Languages © Springer Science+Business Media New York 1997 4 Chapter 11. Functor Categories and Store Shapes not actually to have any phrases of type 8-acc, it is still useful to introduce that phrase type in order to explain 8-var. Also, for any phrase types T and (}, there is a phrase type T => (} that is assigned to procedures accepting arguments (i.e., having formal parameters) of type T and producing results (i.e., having calls) of type 0. The symbol => will intentionally be used also to denote exponentiation in Cartesian closed categories. An integral part of the semantics of a typed language is the assignment to each phrase type T of a meaning, denoted Mng T. One might suppose Mng T is a set; however, the possible existence of nonterminating programs, which lead to an "undefined" state, provides an inducement to partially order Mng T, where the relation x ~ y means x is more undefined than y; for instance, see [Sco71, Rey77]. The need to give meanings to recursively defined expressions of type T causes us to require that directed subsets of Mng T have least upper bounds, i.e., that Mng T be a predomain. Also, we generally want Mng T to have a minimal element, but we must tread cautiously at this point to avoid becom ing overcommitted to the use of Vom (the category of domains) rather than Paom (the category of predomains). As we shall see later, Vom is technically inadequate. Suppose we try to give the semantics of programs which do not contain block entrances and exits. We start by positing the existence of a set S of possible stores. Regard sets as discretely ordered predomains (i.e., x ~ y iff x = y). Since a command is a transformation of S that possibly may not terminate, and a function from S to Sj_ (i.e., toS with a new least element .L) is the same as a continuous function from S to Sj_, we expect Mngcomm = S= S.c. where => is the intemal hom functor (exponentiation) for Paom. Also, for each data type 8, Mng8-exp = S=> (Val8)j_, Mng8-acc = Val8=> Mngcomm, Mng8-var = Mng8-acc x Mng8-exp, where Val8 is the set of values of data-type 8. In other words, a 8-expression attempts to compute a value of type 8 from the current store, a 8-acceptor uses a value of type 8 to update the current store, and a 8-variable may be used as either a 8-expression or a 8-acceptor. Finally, for all phrase types T and (}, we expect Mng(T => {}) = MngT => Mng (}; i.e., the predomain of meanings for the procedural phrase type T => (} is the predomain of continuous functions from Mng T to Mng (}. Although the approach of the preceding paragraph is attractively compre hensible, it is inadequate for the semantics of block structure because the set S is fixed throughout the exposition. The whole point of block structure is to permit S to vary during program execution. For instance, if we view stores as being functions from finite sets of locations in memory to the set of data-type values, then the domains of those functions may be regarded as store shapes. Frank]. Oles 5 Variable declarations at the start of a block alter the shape of the store by adding locations to it, whereas block exit restores the shape of the store to its condition at block entrance. The semantics of a language obeying a stack discipline should reflect this dynamic behaviour. Therefore, let ~ be the collection of all store shapes. To each X E ~. there is a set StX of storesofthat shape. Since the meaning of phrasetypeT varies with the store shape, Mng T is not a predomain, but is rather a ~-indexed collection of predomains. For instance we might arrange matters so that MngcommX = StX=> (StX).l Mngö-exp X = StX=> (Valöh Mngö-accX = Valö=>MngcommX Mng ö-var X = Mng ö-acc X x Mng ö-exp X, where X e ~ and ö is a data type. It is important to realize that, for any phrase type T and store shapes X and Y, the predomains Mng T X and Mng T Y cannot be arbitrarily different. After all, we want the notion of command to have a uniform meaning for all store shapes, or else the definition of operations like ; (concatenation of commands) will be bizarrely complicated. For instance, consider the program skeleton begin int-var x; X:= 3; begin bool-var y; x:= 3; end; end Suppose X is the store shape corresponding to the outer block and Y is the store shape corresponding to the inner block. Then Mng comm X is relevant to the first occurrence of the assignment command x := 3, while Mngcomm Y is relevant to the second occurrence. However, both occurrences are meant to alter the contents of the same location. Roughly speaking, the fact that X can be "expanded" to give Y induces a function from Mngcomm X to Mngcomm Y. So it becomes important to contemplate the notion of an ex pansion from a store shape X to a store shape Y. Certainly expansions should be composable. The composition should be associative. For each store shape X there ought to be an identity expansion which involves "doing nothing" to X. In short, we assert that we erred in letting ~ be the collection of store