MiniSwift – Swift Compiler for the Web

frizlab1 pts0 comments

MiniSwift — Swift Compiler for the Web

New · Studio IDE

Compiler · SwiftUI · Foundation · Metal — from scratch in C

Swift, compiled<br>in your browser.

A full Swift IDE and the complete SwiftUI runtime — write code, watch it render live. No Apple runtime, no LLVM, no install.

Open Studio<br>See live demos

also new<br>minikotlin.run

miniswift.run/studio

Live SwiftUI preview<br>Console REPL<br>File management<br>Autocomplete<br>⌘K palette<br>Shareable links

Headline · the entire SwiftUI runtime in your tab

SwiftUI, compiled in your browser.

Plain Swift source — including @State, NavigationStack, Toggle, Path, the works. Hit a tab and our in-browser compiler tokenises, parses, type-checks, and lowers to UIIR — then the canvas renderer paints it onto a real iPhone frame. Tap a button → @State mutates → an identity-aware diff engine rebuilds only the affected subtree. No iframe, no JS shim, no native runtime — just Swift → C compiler → WASM → canvas pixels. The same pipeline you'd ship to a phone, running in your tab.

Counter<br>@State · button

Greeting<br>Toggle · ternary

Stack<br>VStack · shapes

Profile<br>composition

Counter.swift<br>edit · live<br>@State · button

swift → lexer → parser → sema → uiir → canvas

Live preview<br>tap the buttons

Our compiler. Our UIIR. Our renderer. Our diff engine. All under one roof in 71K lines of C — no React, no Web Components, no proprietary runtime. The same pipeline you'd target a phone with, just landing on a canvas instead of CoreAnimation.<br>Open in Studio →

Bonus · MSL → WGSL on the side

Metal, too.

Because once you have your own compiler infrastructure, why stop at Swift? libMetal tokenises Apple MSL, lowers to MIR, emits WGSL — WebGPU paints the fragment. Edit the shader, move the mouse, watch it react. Same C-only philosophy: no LLVM, no third-party transpiler.

Tunnel<br>polar coords

Plasma<br>sine fields

Raymarch<br>distance field

Mandelbrot<br>fractal

Metaballs<br>implicit field

Tunnel.metal<br>edit · live<br>polar coords

metal → lexer → parser → mir → wgsl → webgpu

WebGPU canvas<br>atan2 + fract

The 177 KB libMetal WASM tokenises ~106 keywords, lowers to MIR with 90+ builtin rewrites, then emits WGSL plus a JSON pipeline-metadata sidecar — the same library you'd link against in C.<br>Open in Studio →

Plain Swift, Right Here

Edit, hit ▶ Run — compiler runs in your tab.

main.swift

Run

Press Run or Cmd+Enter...

Open MiniSwift Studio for the full editor, live preview and a console.

71K

Lines of C

compiler · stdlib · foundation · swiftui · metal

52

SwiftUI Views

stacks · shapes · paths · canvas · maps

75

Modifiers

layout · style · gestures · sheets · alerts

Dependencies

no npm · no llvm · no clang

Everything You Need to Run Swift

Full Language Support

Structs, classes, enums, protocols, generics, closures, async/await, error handling, pattern matching — all compiled to WebAssembly.

Standard Library

Array, Dictionary, Set, String (Unicode 17.0), Optional, Result, Range — 290 runtime functions with 180+ inlined method handlers.

Foundation

Date / Calendar arithmetic + formatting, URL components & resolution, JSON encode/decode, UUID, UserDefaults, Unicode tables — 70+ runtime functions exposed via a JS bridge.

Metal Shaders

Compile MSL (Metal Shading Language) to WGSL right in the browser. vec3 / mat4 math, mesh primitives (cube · sphere · plane · grid), camera + location passthrough — runs on WebGPU.

WebAssembly Backend

Direct IR-to-WASM compilation. No LLVM, no clang, no Binaryen. Structured control flow, dead code elimination, constant folding.

Plugin Architecture

Modular design: compiler core knows zero about stdlib. Modules register type declarations, IR handlers, and WASM builtins via plugin API.

SwiftUI Runtime ★ headline

The whole declarative UI surface — 52 views, 75 modifiers, sheets, alerts, gestures, Path & Canvas drawing — rendered to canvas via our own UIIR JSON. Identity-aware diff engine surgically rebuilds just the affected subtree on every @State mutation. Same Swift code you'd ship to a phone, no edits.

751 Tests, 100% Pass

Comprehensive test suite covering collections, concurrency, generics, error handling, strings, numerics. Zero regressions policy.

Compiler Pipeline

.swift

Lexer

Parser

Sema

IR Gen

SSA

Optimizer

WASM

.wasm

swift compiler swiftui runtime canvas metal

Related Articles