Dependence-driven delimited CPS transformation for JavaScript

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.

[1]  Coen De Roover,et al.  Determining dynamic coupling in JavaScript using object type inference , 2013, 2013 IEEE 13th International Working Conference on Source Code Analysis and Manipulation (SCAM).

[2]  Peter A. Dinda,et al.  Making JavaScript Better by Making It Even Slower , 2013, 2013 IEEE 21st International Symposium on Modelling, Analysis and Simulation of Computer and Telecommunication Systems.

[3]  Coen De Roover,et al.  Detecting function purity in JavaScript , 2015, 2015 IEEE 15th International Working Conference on Source Code Analysis and Manipulation (SCAM).

[4]  Olivier Danvy,et al.  Three Steps for the CPS Transformation ∗ (detailed abstract) , 1992 .

[5]  Frank Tip,et al.  A survey of program slicing techniques , 1994, J. Program. Lang..

[6]  Gang Yu,et al.  Adding delimited and composable control to a production programming environment , 2007, ICFP '07.

[7]  David A. Padua,et al.  Dependence graphs and compiler optimizations , 1981, POPL '81.

[8]  David W. Binkley,et al.  Program slicing , 2008, 2008 Frontiers of Software Maintenance.

[9]  Amr Sabry,et al.  The essence of compiling with continuations , 1993, PLDI '93.

[10]  Peter Thiemann,et al.  Type Analysis for JavaScript , 2009, SAS.

[11]  Coen De Roover,et al.  Towards Tierless Web Development without Tierless Languages , 2014, Onward!.

[12]  Olivier Danvy,et al.  CPS-transformation after strictness analysis , 1992, LOPL.

[13]  Andrew W. Appel,et al.  Compiling with Continuations , 1991 .

[14]  Patrick Cousot,et al.  Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints , 1977, POPL.

[15]  Slocum Miller James,et al.  Multischeme : a parallel processing system based on MIT scheme , 1987 .

[16]  Lasse R. Nielsen A Selective CPS Transformation , 2001, MFPS.

[17]  Matthias Felleisen,et al.  Implementation and use of the PLT scheme Web server , 2007, High. Order Symb. Comput..

[18]  Martin Odersky,et al.  Implementing first-class polymorphic delimited continuations by a type-directed selective CPS-transform , 2009, ICFP.

[19]  Yukiyoshi Kameyama,et al.  A sound and complete axiomatization of delimited continuations , 2003, ICFP '03.

[20]  Martin Odersky,et al.  JavaScript as an Embedded DSL , 2012, ECOOP.

[21]  Andrew W. Appel,et al.  Debugging standard ML without reverse engineering , 1990, LISP and Functional Programming.

[22]  Olivier Danvy,et al.  Assessing the Overhead of ML Exceptions by Selective CPS Transformation , 1998 .

[23]  Ivan Beschastnikh,et al.  Don't Call Us, We'll Call You: Characterizing Callbacks in Javascript , 2015, 2015 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM).