# Space-Efficient Gradual Typing in Coercion-Passing Style

**Authors:** Yuya Tsuda, Atsushi Igarashi, Tomoya Tabuchi

arXiv: 1908.02414 · 2020-11-11

## TL;DR

This paper introduces a coercion-passing style approach for space-efficient gradual typing, providing a formal translation and implementation that prevents stack overflows with manageable performance overhead.

## Contribution

It proposes a novel coercion-passing style technique for efficient gradual typing, including a formal translation and practical implementation in the Grift compiler.

## Key findings

- Prevents stack overflows in gradually typed programs.
- Execution can be up to 3 times slower with the new method.
- Formal correctness of the translation is proven.

## Abstract

Herman et al. pointed out that the insertion of run-time checks into a gradually typed program could hamper tail-call optimization and, as a result, worsen the space complexity of the program. To address the problem, they proposed a space-efficient coercion calculus, which was subsequently improved by Siek et al. The semantics of these calculi involves eager composition of run-time checks expressed by coercions to prevent the size of a term from growing. However, it relies also on a nonstandard reduction rule, which does not seem easy to implement. In fact, no compiler implementation of gradually typed languages fully supports the space-efficient semantics faithfully.   In this paper, we study coercion-passing style, which Herman et al. have already mentioned, as a technique for straightforward space-efficient implementation of gradually typed languages. A program in coercion-passing style passes "the rest of the run-time checks" around---just like continuation-passing style (CPS), in which "the rest of the computation" is passed around---and (unlike CPS) composes coercions eagerly. We give a formal coercion-passing translation from $\lambda$S by Siek et al. to $\lambda$S$_1$, which is a new calculus of first-class coercions tailored for coercion-passing style, and prove correctness of the translation. We also implement our coercion-passing style transformation for the Grift compiler developed by Kuhlenschmidt et al. An experimental result shows stack overflow can be prevented properly at the cost of up to 3 times slower execution for most partially typed practical programs.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1908.02414/full.md

## Figures

52 figures with captions in the complete paper: https://tomesphere.com/paper/1908.02414/full.md

## References

47 references — full list in the complete paper: https://tomesphere.com/paper/1908.02414/full.md

---
Source: https://tomesphere.com/paper/1908.02414