Work

Efficiënte handlers voor algebraïsche effecten

Year: 2019
Type: dissertation
Abstract: In programming languages, a side effect occurs whenever a computation has another effect beside returning its result. There are many examples of side effects such as printing or modifying mutable states. Traditionally, these effects are implicit and built into a language. However, lately, programming using explicit effects is gaining in popularity, since it allows for the free composition of effects. Additionally, it offers a natural separation between the syntax of effects and their semantics, the former given by effect declarations and the latter provided by the so-called "effect handlers". This composition adds an extra layer of modularity to programming with effects and handlers, as it allows the same program to behave differently depending on which handlers are used to deal with its effects. Unfortunately, such flexibility comes at a cost. Even though efficient runtime representations for effects and effect handlers have already been studied, most handler-based programs are still much slower than effect-free hand-written code. In this thesis, we address the performance issue of handler-based programs while preserving the modularity they provide. We investigate this issue in two paradigms: Functional and Logic Programming. For the Functional Programming part, we focus on Eff, which is an ML-based language with explicit effects. We show that the performance gap can be drastically narrowed (in some cases even closed) utilising a type-and-effect directed optimising compilation. The main aim of these optimisations is to eliminate code related to effects and handlers. Our approach consists of two stages. Firstly, we combine source-to-source transformations with function specialisation in order to aggressively reduce handler applications. Secondly, we show how to elaborate the source language into a handler-less target language in a way that incurs no overhead for non-effectful computations. Our approach eliminates much of the overhead of handlers and yields competitive performance with hand-written OCaml code. However, implementing these optimisations for Eff is error-prone because its core language is implicitly-typed, making code transformations very fragile. We also present in this thesis an explicitly-typed polymorphic core calculus for algebraic effect handlers with a subtyping-based type-and-effect system to remedy this fragility. The proposed calculus tracks the use of subtyping through cast expressions with explicit coercions as subtyping proofs, quickly exposing typing bugs during program transformations. For the Logic Programming part, we build on delimited control primitives for Prolog to introduce algebraic effects and handlers into the language. Delimited control is used to manipulate the program control-flow dynamically, and to implement a wide range of control-flow and data-flow effects. Unfortunately, delimited control is a rather primitive language feature that is not easy to use. Hence, we use effect handlers as a structured method that makes use of delimited control. We illustrate the expressive power of the feature and provide an implementation using elaboration into the delimited control primitives. Finally, delimited control adds a non-negligible performance overhead when used extensively. To address this issue, we present an optimised compilation approach that combines partial evaluation with dedicated rewrite rules. The rewrite rules are driven by a lightweight effect inference system that analyses which effects may be called by a program. We illustrate the effectiveness of our approach on a range of benchmarks which shows that the overhead of delimited control is reduced to hand-written Prolog efficiency after the optimisation process.
Author: Saleh, A.
Institution: KU Leuven
Language: English
Subfield: Software
Open Access status: green
OpenAlex ID: W7055942992
Cites: 70
Cited by:
Related to: 10