Overview
Wings uses a three-tier architecture combining a single wings-lang frontend, a Cranelift AOT backend, and a Rust managed microprocess runtime:
┌──────────────────────────────────────────────────────────────┐
│ wings-lang Source (actor / struct / state / on) │
│ Static types, immutable values, non-blocking messaging │
├──────────────────────────────────────────────────────────────┤
│ Compiler & Tooling Pipeline (wings-compile / wings-lsp) │
│ Fault-tolerant CST/AST -> Semantic & protocol checking │
│ -> Structured register IR + precise CFG live-root analysis │
│ -> Cranelift 0.118 PIC native code -> Shared lib + manifest│
├──────────────────────────────────────────────────────────────┤
│ Managed Microprocess Runtime (wings-vm) │
│ 3-level resource ledger, pooled coroutine stacks, │
│ chunked non-moving precise GC, O(1) slot+gen addressing, │
│ lock-free fast mailboxes, M:N preemptive scheduler, │
│ timers, monitors, supervision & stdio/TCP/HTTP serving │
└──────────────────────────────────────────────────────────────┘
Early Evolution Policy: During
0.0.x, the managed ABI, IR instruction set, artifact schemas, and crate interfaces carry no legacy compatibility shims; protocol changes update the implementation directly and require recompiling artifacts.SCALAR_ABI_VERSIONcurrently serves only as an internal binary-layout mismatch guard between compiled artifacts andwings-vm—formal ABI stabilization and resetting the ABI version tov1will be handled in0.1.0.
Workspace Crates & Dependency Isolation
The workspace is organized into 10 focused crates along a strict Directed Acyclic Graph (DAG), keeping internal subsystems like GC and scheduling cohesive inside wings-vm:
| Crate | Kind | Responsibility | Isolation Constraint |
|---|---|---|---|
wings-source |
lib | Source file IDs, UTF-8 byte spans, UTF-16 line/column mapping, diagnostics | Zero heavy external dependencies |
wings-syntax |
lib | Lossless lexing, resilient recursive-descent parsing (with 64-level expression depth guard), AST definitions | Depends only on wings-source |
wings-sema |
lib | Symbol resolution, type inference & checking, actor/struct/message validation | Independent of IR, Cranelift, and LSP wire types |
wings-lsp |
bin + lib | stdio JSON-RPC language server (diagnostics, hover, goto-def, references, document symbols, rename, completion) |
Must never depend on wings-ir, wings-codegen, or wings-vm |
wings-abi |
lib | Managed C ABI layouts (ScalarContext, EffectRequest, ShadowFrame), status codes, type schemas |
Pure contract definitions; no compiler or runtime logic |
wings-ir |
lib | Validated managed IR, frame/step accounting, backward CFG live-reference root analysis | Depends only on wings-abi |
wings-artifact |
lib | Bounded serialization & validation for manifest.json and multi-actor bundle.json |
Depends only on wings-abi and serde |
wings-codegen |
lib | IR-to-Cranelift machine code emission, superblock step coalescing, safepoints, native linking | Isolates heavy Cranelift dependencies |
wings-compile |
bin + lib | End-to-end compilation driver, HIR lowering (lower), check / build / build-app CLI |
Compiler toolchain entry point |
wings-vm |
bin + lib | Native loader, coroutine execution, precise GC, M:N scheduler, 3-level ledger, run / serve CLI |
Must never depend on frontend, IR, wings-codegen, or wings-compile (including dev-deps) |
CI enforces workspace dependency isolation automatically so wings-lsp stays lightweight and wings-vm never pulls in compiler crates or stack unwinding across the C ABI (corosensei explicitly disables unwind and asm-unwind).
Compilation Pipeline, Managed C ABI & Precise GC
- Why Not a Rust
#[actor]Proc-Macro: A Rust proc-macro cannot inspect or bound arbitrary loops, native stack growth, or hidden interior pointers inside opaque third-party Rust functions. A dedicated frontend lets the compiler place deterministic checks at every function entry, loop backedge, and allocation site. - Managed C ABI (
wings-abi):- Generated native handlers receive a fixed-layout
*mut ScalarContextcontaining a unified atomic safepoint control word (CONTROL_CANCELLED | CONTROL_YIELD_REQUESTED), remaining total steps, remaining time-slice steps, native stack limit pointer, active shrink-wrappedShadowFramelist head, slow-path callbacks, heap callbacks, and async effect hooks. - Arithmetic overflow, division by zero, out-of-bounds slicing, step/stack exhaustion, and cancellation propagate strictly via status codes—panicking or unwinding across the C ABI is strictly forbidden.
- Generated native handlers receive a fixed-layout
- Precise CFG Root Liveness & Chunked GC:
wings-irconstructs a control-flow graph (CFG) isomorphic to machine-code emission and runs backward liveness analysis to compute exact live reference slots at every safepoint and call site, publishing them into a shrink-wrappedShadowFramechain (linked lazily only when a path actually publishes live roots) without conservative stack/register scanning.wings-vmruns per-process non-moving mark-sweep GC starting from committedstate, theShadowFramechain, entry arguments, and candidate reply roots, polling step budgets and yield flags every 16 visited nodes/roots while pooling backing byte buffers.
- Artifact Verification & Loader Boundaries:
- Single-actor builds emit
manifest.jsonplus a native shared library (program.dylib/program.so); multi-actor bundles emitbundle.jsonwith per-actor subdirectories. - Before
dlopen,wings-vmenforces regular-file manifests (≤ 64 KiB), pre-parses ELF64 / Mach-O64 load segments to admit page-aligned image spans (≤ 64 MiB), and verifies that dynamic libraries link only against base OS system libraries (libSystemon macOS,libcon Linux).
- Single-actor builds emit
Platform Scope
First-class support targets macOS AArch64 (Apple Silicon) and Linux x86-64 (GNU). Platform-specific primitives (kqueue vs. epoll + eventfd wakeups, pthread stack bounds inspection, Mach vs. /proc memory accounting, and Mach-O / ELF preflight checks) are encapsulated inside wings-vm, keeping upper-layer IR and language semantics platform-neutral.