2,400 research outputs found

    Continuation-Passing C: compiling threads to events through continuations

    Get PDF
    In this paper, we introduce Continuation Passing C (CPC), a programming language for concurrent systems in which native and cooperative threads are unified and presented to the programmer as a single abstraction. The CPC compiler uses a compilation technique, based on the CPS transform, that yields efficient code and an extremely lightweight representation for contexts. We provide a proof of the correctness of our compilation scheme. We show in particular that lambda-lifting, a common compilation technique for functional languages, is also correct in an imperative language like C, under some conditions enforced by the CPC compiler. The current CPC compiler is mature enough to write substantial programs such as Hekate, a highly concurrent BitTorrent seeder. Our benchmark results show that CPC is as efficient, while using significantly less space, as the most efficient thread libraries available.Comment: Higher-Order and Symbolic Computation (2012). arXiv admin note: substantial text overlap with arXiv:1202.324

    Continuing WebAssembly with Effect Handlers

    Get PDF
    WebAssembly (Wasm) is a low-level portable code format offering near native performance. It is intended as a compilation target for a wide variety of source languages. However, Wasm provides no direct support for non-local control flow features such as async/await, generators/iterators, lightweight threads, first-class continuations, etc. This means that compilers for source languages with such features must ceremoniously transform whole source programs in order to target Wasm. We present WasmFX an extension to Wasm which provides a universal target for non-local control features via effect handlers, enabling compilers to translate such features directly into Wasm. Our extension is minimal and only adds three main instructions for creating, suspending, and resuming continuations. Moreover, our primitive instructions are type-safe providing typed continuations which are well-aligned with the design principles of Wasm whose stacks are typed. We present a formal specification of WasmFX and show that the extension is sound. We have implemented WasmFX as an extension to the Wasm reference interpreter and also built a prototype WasmFX extension for Wasmtime, a production-grade Wasm engine, piggybacking on Wasmtime's existing fibers API. The preliminary performance results for our prototype are encouraging, and we outline future plans to realise a native implementation

    Credible Communication in Dynastic Government

    Get PDF
    It has been suggested that ``horizontal accountability," i.e., a system of governance where auditing functions lie outside the executive branch, can ensure credible disclosure of information. This paper examines a model of intertemporal information provision in government that suggests a cautious approach to that view. Government consists of a succession of regimes, each ruling for one period before relinquishing power to a successor. Without external auditing, credible communication cannot be sustained. Hence, expenditure policies are suboptimal. Even with external auditing, credible communication requires ideological conflicts between the auditor and the regime. Moreover, because information transmission stops when the auditor's and the regime's biases coincide, effective deterrents even in the ``good" periods (when the auditor's and the regime's biases differ) are difficult to construct. As a result, in standard constructions of equilibrium, efficient policy choices are shown to be unsustainabledynastic government, dynamic policy bias, auditor neutrality, credible communication

    Effect handlers via generalised continuations

    Get PDF
    Plotkin and Pretnar's effect handlers offer a versatile abstraction for modular programming with user-defined effects. This paper focuses on foundations for implementing effect handlers, for the three different kinds of effect handlers that have been proposed in the literature: deep, shallow, and parameterised. Traditional deep handlers are defined by folds over computation trees, and are the original construct proposed by Plotkin and Pretnar. Shallow handlers are defined by case splits (rather than folds) over computation trees. Parameterised handlers are deep handlers extended with a state value that is threaded through the folds over computation trees. We formulate the extensions both directly and via encodings in terms of deep handlers, and illustrate how the direct implementations avoid the generation of unnecessary closures. We give two distinct foundational implementations of all the kinds of handlers we consider: a continuation passing style (CPS) transformation and a CEK-style abstract machine. In both cases, the key ingredient is a generalisation of the notion of continuation to accommodate stacks of effect handlers. We obtain our CPS translation through a series of refinements as follows. We begin with a first-order CPS translation into untyped lambda calculus which manages a stack of continuations and handlers as a curried sequence of arguments. We then refine the initial CPS translation by uncurrying it to yield a properly tail-recursive translation, and then moving towards more and more intensional representations of continuations in order to support different kinds of effect handlers. Finally, we make the translation higher-order in order to contract administrative redexes at translation time. Our abstract machine design then uses the same generalised continuation representation as the CPS translation. We have implemented both the abstract machine and the CPS transformation (plus extensions) as backends for the Links web programming language

    Effect handlers via generalised continuations

    Get PDF

    Credible Communication in Dynastic Government

    Get PDF
    This paper examines the mechanics of intertemporal information provision in dynastic governments. It has been suggested that "horizontal accountability," i.e., a system of governance where auditing functions lie outside the executive branch, can ensure credible disclosure of information. The results here suggest a cautious approach to that view. Government is modelled as a dynastic sequence of regimes. Each regime rules for one period, chooses an expenditure level, then relinquishes power to its successor. When information about past policy choices comes exclusively from the reports of previous regimes, each regime has an incentive to choose its (suboptimal) one shot expenditure policy, and then misrepresent its choice to its successor. I examine the credible communication equilibria taking into account the reporting incentives of an auditor who can independently verify the information each period. In an environment where "liberal" (i.e., those prefering larger government expenditures) and "conservative" (those prefering smaller expenditures) regimes and auditors evolve over time, it is shown that: "conservative" ("liberal") auditors are not credible when the current regime is also "conservative" ("liberal"). Moreover, because information transmission stops when the auditor's and the regime's biases coincide, e_ective deterrents even in the "good" periods (when the auditor's and the regime's biases di_er) are di_cult to construct. In all periods the equilibrium requirement of auditor neutrality constrains the dynamic incentives for e_cient policy choices. The main result shows that these constraints typically bind away from optimal policies in standard constructions of equilibrium.dynastic government, dynamic policy bias, auditor neutrality, credible communication.

    Formalizing Implementation Strategies for First-Class Continuations

    Get PDF
    We present the first formalization of implementation strategies for first-class continuations. The formalization hinges on abstractmachines for continuation-passing style (CPS) programs with a specialtreatment for the current continuation, accounting for the essence offirst-class continuations. These abstract machines are proven equivalentto a standard, substitution-based abstract machine. The proof techniqueswork uniformly for various representations of continuations. As a byproduct, we also present a formal proof of the two folklore theorems that onecontinuation identifier is enough for second-class continuations and thatsecond-class continuations are stackable.A large body of work exists on implementing continuations, but it is predominantly empirical and implementation-oriented. In contrast, our formalization abstracts the essence of first-class continuations and providesa uniform setting for specifying and formalizing their representation
    corecore