swift → rust → wasm
A toy Swift for the browser,
in Rust.
tswift parses, type-checks, and runs Swift entirely in Rust — no LLVM, no Clang, no Swift toolchain. The same Rust binary compiles to WebAssembly so you can run Swift code right here in the browser, at fraction of the size for full Swift.
main.swift0 lines
loading…
How it works
A pure-Rust pipeline from Swift source to output, with no C dependencies.
Swift source
tswift-lexer
tswift-parser
tswift-sema
tswift-frontend
Typed AST
Runtime evaluator
Output
Implementation status
tswift covers 8 tiers of the Swift 6.3 language surface, plus stdlib, Foundation, SwiftUI, Charts, and SwiftData.
168 implemented · 3 partial · 1 missing (172 total)
363 implemented · 1 partial · 147 missing (511 total)
399 implemented · 32 partial · 184 missing (615 total)
0 implemented · 112 partial · 590 missing (702 total)
0 implemented · 58 partial · 9 missing (67 total)
10 implemented · 2 partial · 102 missing (114 total)
Why Rust?
Rust's ownership model maps onto Swift's memory semantics surprisingly well.
Memory safety, for free
Swift's ARC becomes Rc<RefCell<T>> in Rust. Value-type copy-on-write becomes Rc::make_mut. Deterministic deinit maps to Drop. No unsafe anywhere in the stack.
One binary → WebAssembly
The same Rust crate compiles to native (fast CLI) and towasm32-unknown-unknown (browser). No platform-specific shims — the interpreter just runs.
Semantic alignment
| Swift | Rust |
|---|---|
Value-type CoW | Rc::clone + Rc::make_mut |
class ARC | Rc<RefCell<Object>> |
deinit | Drop at strong-count 0 |
weak (zeroing) | rc::Weak + .upgrade() |
overflow trap | checked_add / wrapping_add |
UTF-8 String | Rust String |
Golden fixture testing
Every feature has a .swift + .expected golden fixture. The harness runs each through the CLI and diffs stdout. 53+ fixtures pass end-to-end today.