rustd, compiling in this page.
The program on the left is compiled to WebAssembly by rustd running in your browser. Change it while it runs: only the functions the edit touched are compiled again and swapped in, and the program carries on from where it was.
What runs here
The compiler is rustd's own: rust-analyzer's parser, name resolution and type inference,
then rustd's code generator, built as one WebAssembly module of about
26 MB (about 7 MB to download, with the source of
core). It runs in a worker in this page. No server compiles anything, and neither
rustc nor LLVM is involved at any point.
The first build of a program compiles it together with every function of core
it reaches, from core's source, which takes a few seconds. After an edit rustd
compiles the functions whose code changed, writes a small module with them, and the page
puts them into the running program's function table. Statics are left alone, which is why the
balls stay where they are. An edit that changes the type of a static starts that static
again.
What it does not do
- One file,
coreonly. The program is a single#![no_std]file. There is nostdand noalloc, so noVec,Stringorprintln!, and no crates from crates.io. - No macros of your own from other crates.
macro_rules!and the built-in macros work. Procedural macros do not, as there is no rustc here to build them. - Few error messages. rustd has no diagnostics of its own. A function that does not parse or type-check is reported by name with a terse reason, and the program keeps running with the last version of it that compiled. Nothing checks borrows or moves, so code rustc would reject can compile here.
- Not the native code generator. Natively rustd emits machine code with Cranelift or LLVM. For WebAssembly it lowers the same Cranelift IR with a lowering of its own, which is newer and less tested. Nothing is optimised across functions.
- It can be wrong. The compiler is a prototype. If a program misbehaves here, check it with rustc before believing it.
- Only what the page provides. The program draws through four functions the page
gives it (
fill,rect,circle,text) and the page calls itsframeandclick. There is no DOM access and nowasm-bindgen.
The daemon you install does more than this page: it works on whole cargo
workspaces with std and dependencies, by linking into what rustc built. A browser
version of that exists as an experiment in the repository (a Dioxus app edited live), and is
not on this page because it needs about 1 GB of memory and a module built by rustc. See
the playground
notes.