🤖 AI Summary
Explicit subtyping coercions in algebraic effect handlers incur significant compilation overhead for polymorphic functions—particularly in effect-polymorphic systems, where coercions are compiled as additional function parameters.
Method: We propose an effectful polymorphic calculus augmented with a constraint-simplification mechanism, integrated into an explicit-coercion λ-calculus framework based on algebraic effects and handlers.
Contribution/Results: We formally define and prove the soundness of a coercion-simplification phase—the first such result for effect-polymorphic systems—that eliminates redundant coercions via semantics-preserving constraint reduction, avoiding full monomorphization. Implemented in the Eff language, our approach completely eliminates all coercions in benchmark programs, yielding generated code whose performance matches hand-written monomorphized code.
📝 Abstract
Algebraic effect handlers are becoming increasingly popular way of structuring and reasoning about effectful computations, and their performance is often a concern. One of the proposed approaches towards efficient compilation is tracking effect information through explicit subtyping coercions. However, in the presence of polymorphism, these coercions are compiled to additional arguments of compiled functions, incurring significant overhead. In this paper, we present a polymorphic effectful calculus, identify simplification phases needed to reduce the number of unnecessary constraints, and prove they preserve the semantics. In addition, we implement the simplification algorithm in the Eff language, and evaluate its performance on a number of benchmarks. Though we do not prove optimality of presented simplifications, the results show that the algorithm eliminates all the coercions, resulting in a code as efficient as manually monomorphised one.