A toy Swift for the browser, in Rust

CharlesW1 pts0 comments

tswift — Swift Runtime in Rustswift → rust → wasm<br>A toy Swift for the browser,<br>in Rust.<br>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.<br>Open PlaygroundHow it works →GitHub

main.swift0 lines<br>▶ Runloading…

Output<br>Ready.

How it works<br>A pure-Rust pipeline from Swift source to output, with no C dependencies.<br>Swift source<br>→tswift-lexer<br>→tswift-parser<br>→tswift-sema<br>→tswift-frontend<br>→Typed AST<br>→Runtime evaluator<br>→Output

🔍<br>Frontend Pipeline<br>Pure-Rust lexer → AST → parser → semantic analysis. No C, no LLVM, no unsafe code.<br>⚙️<br>Runtime Evaluator<br>Tree-walking interpreter with ARC via Rc, copy-on-write value semantics, and native closures.<br>📦<br>Libraries<br>Native Rust implementations of Swift's stdlib, Foundation (incl. UserDefaults/FileManager persistence), SwiftUI, Charts, and a SwiftData subset.

Read the full architecture →

Implementation status<br>tswift covers 8 tiers of the Swift 6.3 language surface, plus stdlib, Foundation, SwiftUI, Charts, and SwiftData.<br>Language (Tiers 0–7)98%–99%

168 implemented · 3 partial · 1 missing (172 total)

Standard Library71%

363 implemented · 1 partial · 147 missing (511 total)

Foundation65%–70%

399 implemented · 32 partial · 184 missing (615 total)

SwiftUI0%–16%

0 implemented · 112 partial · 590 missing (702 total)

Charts0%–87%

0 implemented · 58 partial · 9 missing (67 total)

SwiftData9%–11%

10 implemented · 2 partial · 102 missing (114 total)

Full status dashboard →

Why Rust?<br>Rust's ownership model maps onto Swift's memory semantics surprisingly well.<br>Memory safety, for free<br>Swift's ARC becomes Rc> 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<br>The same Rust crate compiles to native (fast CLI) and towasm32-unknown-unknown (browser). No platform-specific shims — the interpreter just runs.

Semantic alignment<br>SwiftRustValue-type CoWRc::clone + Rc::make_mutclass ARCRc>deinitDrop at strong-count 0weak (zeroing)rc::Weak + .upgrade()overflow trapchecked_add / wrapping_addUTF-8 StringRust String<br>Golden fixture testing<br>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.

swift rust tswift implemented partial missing

Related Articles