Concurrency Semantics in Continuation-Passing Style — The

Total Page:16

File Type:pdf, Size:1020Kb

Concurrency Semantics in Continuation-Passing Style — The Concurrency Semantics in Continuation-Passing Style∗ — The Companion Technical Report — Eneia Nicolae Todoran Technical University of Cluj-Napoca Department of Computer Science Baritiu Str. 28, 400027, Cluj-Napoca, Romania. [email protected] Nikolaos S. Papaspyrou National Technical University of Athens School of Electrical and Computer Engineering Software Engineering Laboratory Polytechnioupoli, 15780 Zografou, Greece. [email protected] Abstract By using the mathematical framework of metric semantics we develop a denotational semantics designed in continuation-passing style for an abstract concurrent language providing a general mech- anism of interaction between multisets of distributed actions. The basic laws of concurrent systems are satisfied in this semantics. Next, by customizing the behavior of continuations we obtain denota- tional semantics for a couple of concurrent languages incorporating mechanisms for multiparty and binary interactions. We offer denotational semantics for two imperative concurrent languages based on Hoare’s CSP and a process algebra for DNA computing introduced by Cardelli. Keywords: continuation-passing style, denotational semantics, metric spaces, concurrency semantics 1 Introduction Continuations are a very powerful control-flow mechanism. As abstract representations of control flow, they were introduced in the 1960s and soon came into prominence in the field of denotational semantics for modelling the semantics of programming languages [23, 38, 34]. In a few words, a continuation represents control flow by capturing the notion of “the rest of the program”, after the current point during the program’s execution. Some functional languages, such as Scheme [22] and SML/NJ [37], provide direct support for capturing and invoking continuations, which are treated as first-class values. In such languages, continuations can be used to implement a variety of advanced control flow constructs. They roughly correspond to “jumps” to different places; programmers can use them as a low-level mechanism to implement disciplined (or undisciplined) “goto”, resumable exceptions, or even coroutines. Continuation-passing style (CPS) is the style of programming in which control is passed explicitly in the form of continuations, in contrast to direct style, which is the usual style of programming. In direct style, a function is called with a number of arguments, it evaluates its result, and returns it to the caller. In CPS, on the other hand, functions never return to the caller. They receive as an additional argument a continuation (or more than one, if necessary), which they invoke with the value of their result, as soon as that is computed. Programs in direct style can be automatically translated to CPS [13]. Indeed CPS ∗Printed: August 2016, Revised April 2017 1 is commonly employed in the development of optimizing compilers for languages with higher-order functions [3]. In recent years, CPS has found a significant practical use for synchronous or asynchronous web programming [31, 32, 12, 21]. Continuations do not only generalize the notion of a “callback” function that is standard in web programming. They can be used to circumvent the statelessness of the HTTP protocol which, in the traditional model of web programming, typically leads to poorly structured code. Several continuation-aware web servers and web frameworks have been developed [47, 44, 48, 35] and have known varying degrees of popularity. In the semantics of programming languages, continuations can be used to model a variety of advanced control concepts, including nonlocal exits, exceptions, coroutines [18] and even multitasking [46, 14]. Various forms of delimited continuations [15, 16, 36, 33, 13, 19, 25] provide even finer control than traditional continuations; they represent a part of the rest of what remains to be computed and they allow (or impose) a more structured way to the use of continuations. However, it is generally believed that traditional continuations do not work well in the presence of concurrency [19]. In the words of Mosses, from his more recent survey of programming language description languages [27]: “Although continuation-passing style is sometimes regarded as a standard style to use for de- notational semantics, it is inadequate for describing languages that involve non-determinism or concurrent processes.” We argue that the fault lies not with the use of CPS, either as a programming style or as a tool for modeling denotational semantics, but with the standard, traditional notion of continuation, which is inadequate to describe certain aspects of concurrency. To alleviate this problem, in our previous publications we have introduced the continuation semantics for concurrency (CSC) technique and we have used it for defining the semantics of several concurrent languages [40, 9]. CSC provides a general tool for modelling control in concurrent systems and it can be used to design both operational and denotational semantic models. When used for the latter, the dis- tinctive characteristic of the CSC technique is that continuations are modelled as appropriate structures of computations (denotations). The structure of continuations is representative of the control flow con- cepts of the languages under study. Computations are also called processes in [40]. Intuitively, CSC is a semantic formalization of a process scheduler. Processes are grouped in what is called a continuation, and the term process denotes the (partially evaluated) meaning of a statement. The concurrency control concepts themselves are modelled as operations manipulating continuations. The domain of CSC can be defined based on a set Id of (process) identifiers. The set of identifiers Id is endowed with a partial order, which induces the structure of continuations specific of the language under investigation. For ex- ample, in [42, 41] continuations are multisets of computations that are executed in parallel. In [40, 9, 10] continuations are trees of computations with active computations at the leaves. In this paper, we propose a different solution by focusing on a much simpler structure for contin- uations, more reminiscent of traditional continuations. We investigate the denotational semantics of concurrent systems in classic continuation-passing style (CPS) based on the interplay between compu- tations (denotations), interaction multisets, synchronous and asynchronous continuations. Our notion of a synchronous continuation roughly coincides with the traditional one: a function that awaits a value and represents the “rest of the program” by yielding its final result. However, the awaited value encom- passes an asynchronous continuation, which may contain a suspended computation, in a way similar to that used by resumption-based approaches to concurrency [11]. We argue that this enhanced notion of continuation provides the necessary structure that is missing from the traditional approach. When a computation is evaluated with respect to a synchronous continuation, the computation is decomposed into an interaction multiset and an asynchronous continuation, which are transmitted as parameters to the synchronous continuation. We offer denotational semantics designed in CPS for various binary and multiparty interaction mechanisms. We hope to collect sufficient evidence that CPS can be used as a general tool for designing denotational semantics for concurrent languages. 2 Note that CSC (continuation semantics for concurrency [40, 9]) and CPS (continuation-passing style) are different techniques, relying on different (classes of) domains and different evaluation strategies for continuations. CSC captures the flow of control by explicit manipulations of process identifiers and requires silent steps to handle synchronous interactions [40, 42, 10], that are not needed in the CPS- based approach that we introduce in this paper. Also, using classic CPS, in this work we establish laws of synchronous interactions that have not been investigated for CSC. Unlike other semantic models of concurrency [30, 5], in the CPS approach that we introduce in this paper the final yield of the semantic functions is a simple collection of observations assembled in a linear time domain. No branching structure is needed. All communication and concurrency control concepts are modelled as operations manipulating continuations. The terms linear time and branching time are often used in temporal logic and semantics [5]. Intuitively, an element of a linear time domain is a collection of (execution) traces. An element of a branching time domain is a tree like structure. Following de Bakker and de Vink [5] in this paper we use the mathematical methodology of metric semantics. The main mathematical tool in this approach to semantics is Banach’s theorem which states that contracting functions on complete metric spaces have unique fixed points. The metric domains that we use to express computation are complete metric spaces. We use the general method for solving reflexive domain equations (in a category of complete metric spaces) developed by America and Rutten [2] as our domain of computations is defined as the solution of an equation where the domain variable occurs in the left hand side of a function space construction. The rest of this paper is organized as follows. In sections 3 and 4 we introduce an abstract con- current language L providing a general mechanism of of interaction between multisets of distributed actions. In section 4 we define a denotational semantics for L. The denotational semantics
Recommended publications
  • Denotational Semantics
    Denotational Semantics CS 6520, Spring 2006 1 Denotations So far in class, we have studied operational semantics in depth. In operational semantics, we define a language by describing the way that it behaves. In a sense, no attempt is made to attach a “meaning” to terms, outside the way that they are evaluated. For example, the symbol ’elephant doesn’t mean anything in particular within the language; it’s up to a programmer to mentally associate meaning to the symbol while defining a program useful for zookeeppers. Similarly, the definition of a sort function has no inherent meaning in the operational view outside of a particular program. Nevertheless, the programmer knows that sort manipulates lists in a useful way: it makes animals in a list easier for a zookeeper to find. In denotational semantics, we define a language by assigning a mathematical meaning to functions; i.e., we say that each expression denotes a particular mathematical object. We might say, for example, that a sort implementation denotes the mathematical sort function, which has certain properties independent of the programming language used to implement it. In other words, operational semantics defines evaluation by sourceExpression1 −→ sourceExpression2 whereas denotational semantics defines evaluation by means means sourceExpression1 → mathematicalEntity1 = mathematicalEntity2 ← sourceExpression2 One advantage of the denotational approach is that we can exploit existing theories by mapping source expressions to mathematical objects in the theory. The denotation of expressions in a language is typically defined using a structurally-recursive definition over expressions. By convention, if e is a source expression, then [[e]] means “the denotation of e”, or “the mathematical object represented by e”.
    [Show full text]
  • Operational Semantics with Hierarchical Abstract Syntax Graphs*
    Operational Semantics with Hierarchical Abstract Syntax Graphs* Dan R. Ghica Huawei Research, Edinburgh University of Birmingham, UK This is a motivating tutorial introduction to a semantic analysis of programming languages using a graphical language as the representation of terms, and graph rewriting as a representation of reduc- tion rules. We show how the graphical language automatically incorporates desirable features, such as a-equivalence and how it can describe pure computation, imperative store, and control features in a uniform framework. The graph semantics combines some of the best features of structural oper- ational semantics and abstract machines, while offering powerful new methods for reasoning about contextual equivalence. All technical details are available in an extended technical report by Muroya and the author [11] and in Muroya’s doctoral dissertation [21]. 1 Hierarchical abstract syntax graphs Before proceeding with the business of analysing and transforming the source code of a program, a com- piler first parses the input text into a sequence of atoms, the lexemes, and then assembles them into a tree, the Abstract Syntax Tree (AST), which corresponds to its grammatical structure. The reason for preferring the AST to raw text or a sequence of lexemes is quite obvious. The structure of the AST incor- porates most of the information needed for the following stage of compilation, in particular identifying operations as nodes in the tree and operands as their branches. This makes the AST algorithmically well suited for its purpose. Conversely, the AST excludes irrelevant lexemes, such as separators (white-space, commas, semicolons) and aggregators (brackets, braces), by making them implicit in the tree-like struc- ture.
    [Show full text]
  • A Denotational Semantics Approach to Functional and Logic Programming
    A Denotational Semantics Approach to Functional and Logic Programming TR89-030 August, 1989 Frank S.K. Silbermann The University of North Carolina at Chapel Hill Department of Computer Science CB#3175, Sitterson Hall Chapel Hill, NC 27599-3175 UNC is an Equal OpportunityjAfflrmative Action Institution. A Denotational Semantics Approach to Functional and Logic Programming by FrankS. K. Silbermann A dissertation submitted to the faculty of the University of North Carolina at Chapel Hill in par­ tial fulfillment of the requirements for the degree of Doctor of Philosophy in Computer Science. Chapel Hill 1989 @1989 Frank S. K. Silbermann ALL RIGHTS RESERVED 11 FRANK STEVEN KENT SILBERMANN. A Denotational Semantics Approach to Functional and Logic Programming (Under the direction of Bharat Jayaraman.) ABSTRACT This dissertation addresses the problem of incorporating into lazy higher-order functional programming the relational programming capability of Horn logic. The language design is based on set abstraction, a feature whose denotational semantics has until now not been rigorously defined. A novel approach is taken in constructing an operational semantics directly from the denotational description. The main results of this dissertation are: (i) Relative set abstraction can combine lazy higher-order functional program­ ming with not only first-order Horn logic, but also with a useful subset of higher­ order Horn logic. Sets, as well as functions, can be treated as first-class objects. (ii) Angelic powerdomains provide the semantic foundation for relative set ab­ straction. (iii) The computation rule appropriate for this language is a modified parallel­ outermost, rather than the more familiar left-most rule. (iv) Optimizations incorporating ideas from narrowing and resolution greatly improve the efficiency of the interpreter, while maintaining correctness.
    [Show full text]
  • Denotational Semantics
    Denotational Semantics 8–12 lectures for Part II CST 2010/11 Marcelo Fiore Course web page: http://www.cl.cam.ac.uk/teaching/1011/DenotSem/ 1 Lecture 1 Introduction 2 What is this course about? • General area. Formal methods: Mathematical techniques for the specification, development, and verification of software and hardware systems. • Specific area. Formal semantics: Mathematical theories for ascribing meanings to computer languages. 3 Why do we care? • Rigour. specification of programming languages . justification of program transformations • Insight. generalisations of notions computability . higher-order functions ... data structures 4 • Feedback into language design. continuations . monads • Reasoning principles. Scott induction . Logical relations . Co-induction 5 Styles of formal semantics Operational. Meanings for program phrases defined in terms of the steps of computation they can take during program execution. Axiomatic. Meanings for program phrases defined indirectly via the ax- ioms and rules of some logic of program properties. Denotational. Concerned with giving mathematical models of programming languages. Meanings for program phrases defined abstractly as elements of some suitable mathematical structure. 6 Basic idea of denotational semantics [[−]] Syntax −→ Semantics Recursive program → Partial recursive function Boolean circuit → Boolean function P → [[P ]] Concerns: • Abstract models (i.e. implementation/machine independent). Lectures 2, 3 and 4. • Compositionality. Lectures 5 and 6. • Relationship to computation (e.g. operational semantics). Lectures 7 and 8. 7 Characteristic features of a denotational semantics • Each phrase (= part of a program), P , is given a denotation, [[P ]] — a mathematical object representing the contribution of P to the meaning of any complete program in which it occurs. • The denotation of a phrase is determined just by the denotations of its subphrases (one says that the semantics is compositional).
    [Show full text]
  • Mechanized Semantics of Simple Imperative Programming Constructs*
    App eared as technical rep ort UIB Universitat Ulm Fakultat fur Informatik Dec Mechanized Semantics of Simple Imp erative Programming Constructs H Pfeifer A Dold F W von Henke H Rue Abt Kunstliche Intelligenz Fakultat fur Informatik Universitat Ulm D Ulm verifixkiinformatikuniulmde Abstract In this pap er a uniform formalization in PVS of various kinds of semantics of imp er ative programming language constructs is presented Based on a comprehensivede velopment of xed p oint theory the denotational semantics of elementary constructs of imp erative programming languages are dened as state transformers These state transformers induce corresp onding predicate transformers providing a means to for mally derivebothaweakest lib eral precondition semantics and an axiomatic semantics in the style of Hoare Moreover algebraic laws as used in renement calculus pro ofs are validated at the level of predicate transformers Simple reformulations of the state transformer semantics yield b oth a continuationstyle semantics and rules similar to those used in Structural Op erational Semantics This formalization provides the foundations on which formal sp ecication of program ming languages and mechanical verication of compilation steps are carried out within the Verix pro ject This research has b een funded in part by the Deutsche Forschungsgemeinschaft DFG under pro ject Verix Contents Intro duction Related Work Overview A brief description of PVS Mechanizing Domain
    [Show full text]
  • Chapter 3 – Describing Syntax and Semantics CS-4337 Organization of Programming Languages
    !" # Chapter 3 – Describing Syntax and Semantics CS-4337 Organization of Programming Languages Dr. Chris Irwin Davis Email: [email protected] Phone: (972) 883-3574 Office: ECSS 4.705 Chapter 3 Topics • Introduction • The General Problem of Describing Syntax • Formal Methods of Describing Syntax • Attribute Grammars • Describing the Meanings of Programs: Dynamic Semantics 1-2 Introduction •Syntax: the form or structure of the expressions, statements, and program units •Semantics: the meaning of the expressions, statements, and program units •Syntax and semantics provide a language’s definition – Users of a language definition •Other language designers •Implementers •Programmers (the users of the language) 1-3 The General Problem of Describing Syntax: Terminology •A sentence is a string of characters over some alphabet •A language is a set of sentences •A lexeme is the lowest level syntactic unit of a language (e.g., *, sum, begin) •A token is a category of lexemes (e.g., identifier) 1-4 Example: Lexemes and Tokens index = 2 * count + 17 Lexemes Tokens index identifier = equal_sign 2 int_literal * mult_op count identifier + plus_op 17 int_literal ; semicolon Formal Definition of Languages • Recognizers – A recognition device reads input strings over the alphabet of the language and decides whether the input strings belong to the language – Example: syntax analysis part of a compiler - Detailed discussion of syntax analysis appears in Chapter 4 • Generators – A device that generates sentences of a language – One can determine if the syntax of a particular sentence is syntactically correct by comparing it to the structure of the generator 1-5 Formal Methods of Describing Syntax •Formal language-generation mechanisms, usually called grammars, are commonly used to describe the syntax of programming languages.
    [Show full text]
  • 1 a Denotational Semantics for IMP
    CS 4110 – Programming Languages and Logics .. Lecture #8: Denotational Semantics . We have now seen two operational models for programming languages: small-step and large-step. In this lecture, we consider a different semantic model, called denotational semantics. The idea in denotational semantics is to express the meaning of a program as the mathematical function that expresses what the program computes. We can think of an IMP program c as a function from stores to stores: given an an initial store, the program produces a nal store. For example, the program foo := bar+1 0 can be thought of as a function that when given an input store σ, produces a nal store σ that is identical 0 to σ except that it maps foo to the integer σ(bar) + 1; that is, σ = σ[foo 7! σ(bar) + 1]. We will model programs as functions from input stores to output stores. As opposed to operational models, which tell us how programs execute, the denotational model shows us what programs compute. 1 A Denotational Semantics for IMP For each program c, we write C[[c]] for the denotation of c, that is, the mathematical function that c represents: C[[c]] : Store * Store: Note that C[[c]] is actually a partial function (as opposed to a total function), both because the store may not be dened on the free variables of the program and because program may not terminate for certain input stores. The function C[[c]] is not dened for non-terminating programs as they have no corresponding output stores. We will write C[[c]]σ for the result of applying the function C[[c]] to the store σ.
    [Show full text]
  • Chapter 1 Introduction
    Chapter Intro duction A language is a systematic means of communicating ideas or feelings among people by the use of conventionalized signs In contrast a programming lan guage can be thought of as a syntactic formalism which provides ameans for the communication of computations among p eople and abstract machines Elements of a programming language are often called programs They are formed according to formal rules which dene the relations between the var ious comp onents of the language Examples of programming languages are conventional languages likePascal or C and also the more the oretical languages such as the calculus or CCS A programming language can b e interpreted on the basis of our intuitive con cept of computation However an informal and vague interpretation of a pro gramming language may cause inconsistency and ambiguity As a consequence dierent implementations maybegiven for the same language p ossibly leading to dierent sets of computations for the same program Had the language in terpretation b een dened in a formal way the implementation could b e proved or disproved correct There are dierent reasons why a formal interpretation of a programming language is desirable to give programmers unambiguous and p erhaps informative answers ab out the language in order to write correct programs to give implementers a precise denition of the language and to develop an abstract but intuitive mo del of the language in order to reason ab out programs and to aid program development from sp ecications Mathematics often emphasizes
    [Show full text]
  • Ten Choices for Lexical Semantics
    1 Ten Choices for Lexical Semantics Sergei Nirenburg and Victor Raskin1 Computing Research Laboratory New Mexico State University Las Cruces, NM 88003 {sergei,raskin}@crl.nmsu.edu Abstract. The modern computational lexical semantics reached a point in its de- velopment when it has become necessary to define the premises and goals of each of its several current trends. This paper proposes ten choices in terms of which these premises and goals can be discussed. It argues that the central questions in- clude the use of lexical rules for generating word senses; the role of syntax, prag- matics, and formal semantics in the specification of lexical meaning; the use of a world model, or ontology, as the organizing principle for lexical-semantic descrip- tions; the use of rules with limited scope; the relation between static and dynamic resources; the commitment to descriptive coverage; the trade-off between general- ization and idiosyncracy; and, finally, the adherence to the “supply-side” (method- oriented) or “demand-side” (task-oriented) ideology of research. The discussion is inspired by, but not limited to, the comparison between the generative lexicon ap- proach and the ontological semantic approach to lexical semantics. It is fair to say that lexical semantics, the study of word meaning and of its representation in the lexicon, experienced a powerful resurgence within the last decade.2 Traditionally, linguistic se- mantics has concerned itself with two areas, word meaning and sentence meaning. After the ascen- dancy of logic in the 1930s and especially after “the Chomskian revolution” of the late 1950s-early 1960s, most semanticists, including those working in the transformational and post-transforma- tional paradigm, focused almost exclusively on sentence meaning.
    [Show full text]
  • Denotational Semantics for 'Natural' Language Question-Answering
    Denotational Semantics for "'Natural'" Language Question-Answering Programs 1 Michael G. Main 2 David B. Benson Department of Computer Science Washington State University Pullman, WA 99164-1210 Scott-Strachey style denotational semantics is proposed as a suitable means of commu- nicating the specification of "natural" language question answerers to computer program- mers and software engineers. The method is exemplified by a simple question answerer communicating with a small data base. This example is partly based on treatment of fragments of English by Montague. Emphasis is placed on the semantic interpretation of questions. The "meaning" of a question is taken as a function from the set of universes to a set of possible answers. 1. Introduction methods do not provide. In short, a formal method of specifying the semantics is needed at the design and We advocate the use of Scott-Strachey denotational implementation stage (see Ashcroft and Wadge 1982). semantics for "natural" language question-answering Once a formal semantics has been given, it can be programs. The majority of this paper demonstrates put to other uses as well. It can provide the basis for the use of denotational semantics for a small question a rigorous proof of correctness of an implementation. answerer. The types of questions possible are similar Furthermore, formal specifications might allow partial to those in Harris (1979), Winograd (1972), and automation of the implementation process in the same Woods (1972). The analysis is not as deep as in Kart- way that automatic compiler-writers produce parts of a tunen (1977) or similar studies, as it is oriented to the compiler from a formal specification of a programming specification of useful, but linguistically modest, capa- language (see Johnson 1975).
    [Show full text]
  • UTP Semantics for Shared-State, Concurrent, Context-Sensitive Process Models
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by University of Limerick Institutional Repository UTP Semantics for Shared-State, Concurrent, Context-Sensitive Process Models Andrew Butterfield Anila Mjeda John Noll Lero @ TCD Lero @ TCD Lero @ UL School of Computer Science and Statistics School of Computer Science and Statistics Tierney Building Trinity College, Dublin 2, Ireland Trinity College, Dublin 2, Ireland University of Limerick Email: Andrew.Butterfi[email protected] Email: [email protected] Email: [email protected] Abstract—Process Modelling Language (PML) is a notation semantics for shared global state concurrency, as a way to for describing software development and business processes. It get a suitable semantics for strict and flexible PML, inspired takes the form of a shared-state concurrent imperative language by the work of Woodcock and Hughes on unifying parallel describing tasks as activities that require resources to start and provide resources when they complete. Its syntax covers programming (UTPP, [13]). We present both a formal seman- sequential composition, parallelism, iteration and choice, but tics for a “weak” interpretation of PML, as well as a unified without explicit iteration and choice conditions. It is intended theory of concurrent programs (UTCP) that will provide a to support a range of context-sensitive interpretations, from a baseline theory for modelling more “flexible” and “strong” rough guide for intended behaviour, to being very prescriptive interpretations of PML. Part of our contribution is extending about the order in which tasks must occur. We are using Unifying Theories of Programming (UTP) to model this range of semantic the UTP methodology to use non-homogenous relations that interpretations, with formal links between them, typically of the mix dynamic state-change (observations with before- and nature of a refinement.
    [Show full text]
  • Domain Theory for Concurrency
    Domain Theory for Concurrency Mikkel Nygaard Glynn Winskel BRICS∗ Computer Laboratory University of Aarhus University of Cambridge Abstract A simple domain theory for concurrency is presented. Based on a categorical model of linear logic and associated comonads, it highlights the role of linear- ity in concurrent computation. Two choices of comonad yield two expressive metalanguages for higher-order processes, both arising from canonical construc- tions in the model. Their denotational semantics are fully abstract with respect to contextual equivalence. One language derives from an exponential of linear logic; it supports a straightforward operational semantics with simple proofs of soundness and adequacy. The other choice of comonad yields a model of affine-linear logic, and a process language with a tensor operation to be under- stood as a parallel composition of independent processes. The domain theory can be generalised to presheaf models, providing a more refined treatment of nondeterministic branching. The article concludes with a discussion of a broader programme of research, towards a fully fledged domain theory for concurrency. 1 Introduction Denotational semantics and domain theory of Scott and Strachey provide a global mathematical setting for sequential computation, and thereby place programming languages in connection with each other; connect with the mathematical worlds of algebra, topology and logic; and inspire programming languages, type disciplines and methods of reasoning. In concurrent/distributed/interactive computation that global mathematical gui- dance is missing, and domain theory has had little direct influence on theories of concurrent computation. One reason is that classical domain theory has not scaled up to the more intricate models used there.
    [Show full text]