576 research outputs found
Logical relations for coherence of effect subtyping
A coercion semantics of a programming language with subtyping is typically
defined on typing derivations rather than on typing judgments. To avoid
semantic ambiguity, such a semantics is expected to be coherent, i.e.,
independent of the typing derivation for a given typing judgment. In this
article we present heterogeneous, biorthogonal, step-indexed logical relations
for establishing the coherence of coercion semantics of programming languages
with subtyping. To illustrate the effectiveness of the proof method, we develop
a proof of coherence of a type-directed, selective CPS translation from a typed
call-by-value lambda calculus with delimited continuations and control-effect
subtyping. The article is accompanied by a Coq formalization that relies on a
novel shallow embedding of a logic for reasoning about step-indexing
Answer Refinement Modification: Refinement Type System for Algebraic Effects and Handlers
Algebraic effects and handlers are a mechanism to structure programs with
computational effects in a modular way. They are recently gaining popularity
and being adopted in practical languages, such as OCaml. Meanwhile, there has
been substantial progress in program verification via refinement type systems.
However, thus far, there has not been a satisfactory refinement type system for
algebraic effects and handlers. In this paper, we fill the void by proposing a
novel refinement type system for algebraic effects and handlers. The
expressivity and usefulness of algebraic effects and handlers come from their
ability to manipulate delimited continuations, but delimited continuations also
complicate programs' control flow and make their verification harder. To
address the complexity, we introduce a novel concept that we call answer
refinement modification (ARM for short), which allows the refinement type
system to precisely track what effects occur and in what order when a program
is executed, and reflect the information as modifications to the refinements in
the types of delimited continuations. We formalize our type system that
supports ARM (as well as answer type modification) and prove its soundness.
Additionally, as a proof of concept, we have implemented a corresponding type
checking and inference algorithm for a subset of OCaml 5, and evaluated it on a
number of benchmark programs. The evaluation demonstrates that ARM is
conceptually simple and practically useful. Finally, a natural alternative to
directly reasoning about a program with delimited continuations is to apply a
continuation passing style (CPS) transformation that transforms the program to
a pure program. We investigate this alternative, and show that the approach is
indeed possible by proposing a novel CPS transformation for algebraic effects
and handlers that enjoys bidirectional (refinement-)type-preservation.Comment: 66 page
Continuation Passing Style for Effect Handlers
We present Continuation Passing Style (CPS) translations for Plotkin and Pretnar's effect handlers with Hillerström and Lindley's row-typed fine-grain call-by-value calculus of effect handlers as the source language. CPS translations of handlers are interesting theoretically, to explain the semantics of handlers, and also offer a practical implementation technique that does not require special support in the target language's runtime. 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 first by uncurrying it to yield a properly tail-recursive translation and second by making it higher-order in order to contract administrative redexes at translation time. We prove that the higher-order CPS translation simulates effect handler reduction. We have implemented the higher-order CPS translation as a JavaScript backend for the Links programming language
Linear and Affine Typing of Continuation-Passing Style
Submitted for the degree of Doctor of Philosophy, Queen Mary, University of Londo
On the Expressive Power of User-Defined Effects: Effect Handlers, Monadic Reflection, Delimited Control
We compare the expressive power of three programming abstractions for
user-defined computational effects: Bauer and Pretnar's effect handlers,
Filinski's monadic reflection, and delimited control without
answer-type-modification. This comparison allows a precise discussion about the
relative expressiveness of each programming abstraction. It also demonstrates
the sensitivity of the relative expressiveness of user-defined effects to
seemingly orthogonal language features. We present three calculi, one per
abstraction, extending Levy's call-by-push-value. For each calculus, we present
syntax, operational semantics, a natural type-and-effect system, and, for
effect handlers and monadic reflection, a set-theoretic denotational semantics.
We establish their basic meta-theoretic properties: safety, termination, and,
where applicable, soundness and adequacy. Using Felleisen's notion of a macro
translation, we show that these abstractions can macro-express each other, and
show which translations preserve typeability. We use the adequate finitary
set-theoretic denotational semantics for the monadic calculus to show that
effect handlers cannot be macro-expressed while preserving typeability either
by monadic reflection or by delimited control. We supplement our development
with a mechanised Abella formalisation
Wasm/k: Delimited Continuations for WebAssembly
WebAssembly is designed to be an alternative to JavaScript that is a safe,
portable, and efficient compilation target for a variety of languages. The
performance of high-level languages depends not only on the underlying
performance of WebAssembly, but also on the quality of the generated
WebAssembly code. In this paper, we identify several features of high-level
languages that current approaches can only compile to WebAssembly by generating
complex and inefficient code. We argue that these problems could be addressed
if WebAssembly natively supported first-class continuations. We then present
Wasm/k, which extends WebAssembly with delimited continuations. Wasm/k
introduces no new value types, and thus does not require significant changes to
the WebAssembly type system (validation). Wasm/k is safe, even in the presence
of foreign function calls (e.g., to and from JavaScript). Finally, Wasm/k is
amenable to efficient implementation: we implement Wasm/k as a local change to
Wasmtime, an existing WebAssembly JIT. We evaluate Wasm/k by implementing C/k,
which adds delimited continuations to C/C++. C/k uses Emscripten and its
implementation serves as a case study on how to use Wasm/k in a compiler that
targets WebAssembly. We present several case studies using C/k, and show that
on implementing green threads, it can outperform the state-of-the-art approach
Asyncify with an 18% improvement in performance and a 30% improvement in code
size
- …