Compiling from a typed dialect of Scheme to WebAssembly

Christopher Rybicki
University of Massachusetts Amherst, 2020

Compilers are an important kind of software engineering tool studied within the programming language community, which serve to transform written code from one language into another. One particularly significant compilation target is WebAssembly: a recently standardized assembly language that has been designed withportability, efficiency, and modularity in mind. WebAssembly has been integrated within browsers in order to offer developers the ability to run more computationally expensive processes and algorithms as an extension of JavaScript, allowing for the increased speed and efficiency of web applications. Our goal in this work is to showthat we can design WebAssembly-targeted compilers for general languages in a way which, unlike most production compilers, guarantees type safety through all compiler passes. By achieving this goal, we hope to allow users to write type-safe programs which can be executed in a wide range of environments, while allowing compiler developers to debug, maintain, and extend their compilers more easily through the guarantees provided by type safety. To this end, we have successfully developed a prototype compiler from a typed variation of Scheme to WebAssembly which utilizes a robust type checker to validate intermediate codetransformations for correctness. This required designing and implementing several compiler passes, such as closure conversion, lambda lifting, and code generation, in a fashion which is type-safe and adaptable to the limited data types and memory mechanisms available within the WebAssembly execution environment.