skip to main content
article

Dependence-driven delimited CPS transformation for JavaScript

Published: 20 October 2016 Publication History

Abstract

In today’s web applications asynchronous requests to remote services using callbacks or futures are omnipresent. The continuation of such a non-blocking task is represented as a callback function that will later be called with the result of the request. This style of programming where the remainder of a computation is captured in a continuation function is called continuation-passing style (CPS). This style of programming can quickly lead to a phenomenon called “call- back hell”, which has a negative impact on the maintain- ability of applications that employ this style. Several alter- natives to callbacks are therefore gaining traction within the web domain. For example, there are a number of frameworks that rely on automatically transforming sequential style code into the continuation-passing style. However, these frame- works often employ a conservative approach in which each function call is transformed into CPS. This conservative approach can sequentialise requests that could otherwise be run in parallel. So-called delimited continuations can remedy, but require special marks that have to be manually inserted in the code for marking the beginning and end of the continuation. In this paper we propose an alternative strategy in which we apply a delimited CPS transformation that operates on a Program Dependence Graph instead to find the limits of each continuation.We implement this strategy in JavaScript and demonstrate its applicability to various web programming scenarios.

References

[1]
Andrew W. Appel. Compiling with Continuations. Cambridge University Press, New York, NY, USA, 1992.
[2]
Patrick Cousot and Radhia Cousot. Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints. In Proceedings of the 4th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, pages 238–252. ACM, 1977.
[3]
Olivier Danvy and John Hatcliff. CPS-transformation After Strictness Analysis. ACM Lett. Program. Lang. Syst., 1(3):195–212, September 1992.
[4]
Alex Davies. Async in Csharp 5.0 - Unleash the Power of Async. O’Reilly, 2012.
[5]
Continuation.js documentation. Continuation.js. https:// github.com/BYVoid/continuation, 2013.
[6]
Streamline documentation. Streamline.js. https://github. com/Sage/streamlinejs, 2015.
[7]
Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. The Essence of Compiling with Continuations. In Proceedings of the ACM SIGPLAN 1993 Conference on Programming Language Design and Implementation, PLDI ’93, pages 237–247, New York, NY, USA, 1993. ACM.
[8]
Matthew Flatt, Gang Yu, Robert Bruce Findler, and Matthias Felleisen. Adding Delimited and Composable Control to a Production Programming Environment. SIGPLAN Not., 42(9):165–176, October 2007.
[9]
Keheliya Gallaba, Ali Mesbah, and Ivan Beschastnikh. Don’t Call Us, We’ll Call You: Characterizing Callbacks in JavaScript. In 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement, ESEM 2015, Beijing, China, October 22-23, 2015, pages 247–256, 2015.
[10]
Rich Hickey and contributors. core.async clojure library. https://github.com/clojure/core.async, 2013.
[11]
Robert Hieb, R.Kent Dybvig, and III Anderson, ClaudeW. Subcontinuations. LISP and Symbolic Computation, 7(1):83– 109, 1994.
[12]
Simon Holm Jensen, Anders Møller, and Peter Thiemann. Type analysis for JavaScript. In Proc. 16th International Static Analysis Symposium (SAS), volume 5673 of LNCS. Springer-Verlag, August 2009.
[13]
Yukiyoshi Kameyama and Masahito Hasegawa. A Sound and Complete Axiomatization of Delimited Continuations. In In Proc. of 8th ACM SIGPLAN Int. Conf. on Functional Programming, ICFP’03, pages 177–188. ACM Press, 2003.
[14]
Grzegorz Kossakowski, Nada Amin, Tiark Rompf, and Martin Odersky. Javascript as an Embedded DSL. In James Noble, editor, ECOOP 2012, volume 7313 of Lecture Notes in Computer Science, pages 409–434. Springer Berlin Heidelberg, 2012.
[15]
Jens Krinke. Program slicing. In S K Chang, editor, Handbook of Software Engineering and Knowledge Engineering 3. World Scientific Publishing, 2004.
[16]
Shriram Krishnamurthi, Peter Walton Hopkins, Jay A. Mc-Carthy, Paul T. Graunke, Greg Pettyjohn, and Matthias Felleisen. Implementation and use of the PLT scheme Web server. Higher-Order and Symbolic Computation, 20(4):431– 460, 2007.
[17]
D. J. Kuck, R. H. Kuhn, D. A. Padua, B. Leasure, and M. Wolfe. Dependence Graphs and Compiler Optimizations. In Proceedings of the 8th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL ’81, pages 207–218, New York, NY, USA, 1981. ACM.
[18]
Oni Labs. Stratified javascript. http://onilabs.com/ stratifiedjs, 2012.
[19]
Jens Nicolay, Carlos Noguera, Coen De Roover, and Wolfgang De Meuter. Determining Coupling In JavaScript Using Object Type Inference. In SCAM13, 2013.
[20]
Jens Nicolay, Carlos Noguera, Coen De Roover, and Wolfgang De Meuter. Detecting Function Purity in JavaScript. In Proceedings of the 15th International Working Conference on Source Code Analysis and Manipulation (SCAM15), 2015.
[21]
Scala programming documentation. Scala package: continuations. http://www.scala-lang.org/api/2.10. 1/index.html#scala.util.continuations.package, 2016.
[22]
Ryan Seddon. Introduction to javascript source maps. http://www.html5rocks.com/en/tutorials/ developertools/sourcemaps/, 2012.
[23]
Maciej Swiech and Peter Dinda. Making JavaScript better by making it even slower. In Modeling, Analysis & Simulation of Computer and Telecommunication Systems (MASCOTS), 2013 IEEE 21st International Symposium on, pages 70–79. IEEE, 2013.
[24]
Frank Tip. A Survey of Program Slicing Techniques. Technical report, Amsterdam, The Netherlands, The Netherlands, 1994.
[25]
Andrew Tolmach. Debugging Standard ML without Reverse Engineering. In In Proceedings of the 1990 ACM Conference on Lisp and Functional Programming, pages 1–12. ACM Press, 1990.
[26]
Mark Weiser. Program slicing. IEEE Trans. Software Eng., 10(4):352–357, 1984.

Cited By

View all
  • (2021)Kotlin coroutines: design and implementationProceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3486607.3486751(68-84)Online publication date: 20-Oct-2021
  • (2022)Smelly variables in ansible infrastructure codeProceedings of the 19th International Conference on Mining Software Repositories10.1145/3524842.3527964(61-72)Online publication date: 23-May-2022
  • (2018)Tierless Web Programming in the LargeCompanion Proceedings of the The Web Conference 201810.1145/3184558.3185953(681-689)Online publication date: 23-Apr-2018
  • Show More Cited By

Index Terms

  1. Dependence-driven delimited CPS transformation for JavaScript

    Recommendations

    Comments

    Information & Contributors

    Information

    Published In

    cover image ACM SIGPLAN Notices
    ACM SIGPLAN Notices  Volume 52, Issue 3
    GPCE '16
    March 2017
    212 pages
    ISSN:0362-1340
    EISSN:1558-1160
    DOI:10.1145/3093335
    Issue’s Table of Contents
    • cover image ACM Conferences
      GPCE 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences
      October 2016
      212 pages
      ISBN:9781450344463
      DOI:10.1145/2993236
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 20 October 2016
    Published in SIGPLAN Volume 52, Issue 3

    Check for updates

    Author Tags

    1. CPS transformation
    2. JavaScript
    3. Program Dependence Graph

    Qualifiers

    • Article

    Funding Sources

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)13
    • Downloads (Last 6 weeks)1
    Reflects downloads up to 19 Feb 2025

    Other Metrics

    Citations

    Cited By

    View all
    • (2021)Kotlin coroutines: design and implementationProceedings of the 2021 ACM SIGPLAN International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software10.1145/3486607.3486751(68-84)Online publication date: 20-Oct-2021
    • (2022)Smelly variables in ansible infrastructure codeProceedings of the 19th International Conference on Mining Software Repositories10.1145/3524842.3527964(61-72)Online publication date: 23-May-2022
    • (2018)Tierless Web Programming in the LargeCompanion Proceedings of the The Web Conference 201810.1145/3184558.3185953(681-689)Online publication date: 23-Apr-2018
    • (2017)Simpler Coordination of JavaScript Web WorkersCoordination Models and Languages10.1007/978-3-319-59746-1_3(40-58)Online publication date: 27-May-2017

    View Options

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Figures

    Tables

    Media

    Share

    Share

    Share this Publication link

    Share on social media