arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2308.08347cs.PL
收藏

使用效应处理器扩展 WebAssembly

Continuing WebAssembly with Effect Handlers

Luna Phipps-Costin, Andreas Rossberg, Arjun Guha, Daan Leijen, Daniel Hillerström, KC Sivaramakrishnan, Matija Pretnar, Sam Lindley

AI总结:

本文提出 WasmFX,通过效应处理器为 WebAssembly 扩展非局部控制流支持,仅添加三个类型安全的续体指令,并在参考解释器和 Wasmtime 引擎中实现原型,初步性能良好。

摘要:

WebAssembly (Wasm) 是一种提供接近原生性能的低级可移植代码格式。它旨在作为各种源语言的编译目标。然而,Wasm 不直接支持非局部控制流特性,如 async/await、generators/iterators、轻量级线程、一等续体等。这意味着针对具有此类特性的源语言编译器必须繁琐地转换整个源程序以适配 Wasm。我们提出了 WasmFX,这是 Wasm 的扩展,通过效应处理器为非局部控制特性提供通用目标,使编译器能够直接将此类特性翻译为 Wasm。我们的扩展是极简的,仅添加了用于创建、挂起和恢复续体的三个主要指令。此外,我们的原语指令是类型安全的,提供了类型化续体,这与 Wasm 堆栈类型化的设计原则高度一致。我们给出了 WasmFX 的形式化规范并证明该扩展是健全的。我们将 WasmFX 实现为 Wasm 参考解释器的扩展,并基于 Wasmtime 的现有 fibers API 构建了 WasmFX 原型扩展,Wasmtime 是生产级 Wasm 引擎。原型的初步性能结果令人鼓舞,我们概述了未来实现原生实现的计划。

英文摘要:

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

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑