ES
Tooling & InternalsCompiler · ABI v3

Compiler Pipeline, ABI v3 & Bootstrap

Inside Wysna's architecture — Seed vs Selfhost pipelines, 8-byte NaN-boxed WVal64 Runtime ABI v3, SSO strings, atomic ARC + CoW, and 3-stage deterministic fixed-point bootstrap.

Wysna maintains a strict separation of compiler stages and runtime contracts so every emitted native artifact is verified before a single line of C99 or LLVM IR is generated.


01 · SOURCEWysna Code*.wysna + toml02 · CHECKERChecked ASTTypes · Generics · T!E03 · DESUGARTyped HIRMatch · Contracts04 · IR CONTRACTVerified MIRARC · CoW · CPSEffects · SandboxANSI C99 (Zig)WASI / WASMLLVM (opt-in)
Every compilation path passes through verified MIR before backend code emission.
  1. CompilerService & CompilationSession: Manages immutable source snapshots, interface-digest incremental early cutoff, module graphs, and canonical type interning.
  2. Checked AST → Typed HIR: Resolves nominal types, monomorphized generics, from ... use imports, exhaustive match checks, and requires/ensures contracts.
  3. Verified MIR: Independent MIR verifier checks SSA-like control flow, ownership/lifetime drops, temporary scope cleanup (preventing quadratic CoW detaches in loops), CPS state-machine lowering for async fn, and effect summaries.
  4. Backends:
    • ANSI C99 (Primary Stable): Emits clean, auditable C99 linked against runtime/wysna_runtime.h and compiled via bundled Zig 0.15.2 (or system clang/gcc).
    • WebAssembly (wasi-command, browser-library): Emits WASI commands or zero-install Zig reactor browser modules (Seed).
    • Direct LLVM (--backend=llvm-experimental): Opt-in LLVM IR emitter retained under CI smoke tests on Linux x64 and macOS arm64 (currently frozen while C99 leads on binary size and cold compile speed).

2. Runtime ABI v3 (WVal64 — 8-Byte NaN-Boxing)

Section titled “2. Runtime ABI v3 (WVal64 — 8-Byte NaN-Boxing)”

Introduced in v0.7.0 (W_RUNTIME_ABI_VERSION 3), every runtime value fits in a single 8-byte WVal64 machine word:

  • Inline Scalars & Booleans: Immediate unboxed values without heap indirection.
  • Small String Optimization (SSO): Strings <= 6 UTF-8 bytes live inline directly inside the 8-byte WVal64 value with zero heap allocation; longer strings carry an O(1) cached hash_cache.
  • Unboxed Scalar Lists: list[int], list[float], and list[bool] use specialized contiguous buffers with O(1) release and memcpy CoW detachment.
  • Atomic ARC + Optional Cycle Collection: Lock-free atomic reference counting guarantees deterministic destruction at scope exit; deferred Bacon-Rajan cycle collection can be enabled via WYSNA_COLLECT_CYCLES=1, complemented by static compile-time retain cycle warnings ([W6002]).
  • Shared Static Key Tables: Struct and object instances share static key tables across WStructBuf allocations to minimize per-instance memory overhead.
  • Source Debugging (#line): Opt-in C99 #line directives map generated C back to exact .wysna source lines (DX-R01).

3. Deterministic 3-Stage Self-Hosted Bootstrap

Section titled “3. Deterministic 3-Stage Self-Hosted Bootstrap”

The self-hosted compiler (selfhost/compiler.wysna, 34 modules) reaches a mathematically verified deterministic fixed point:

SEED ENGINE• Full reference profile (Python 3.10+ & bundled Zig)• AST → Typed HIR → Verified MIR → C99 / LLVM• Owns REPL, WASI, Browser WASM & test oracleInstallers: .pkg · .deb · .rpm · .exe · .zipNATIVE SDK• Written in pure Wysna (34 modules, zero Python)• Independent CheckedProgram → MIR → ANSI C99• 3-stage bootstrap fixed point (C0 == C1 == C2)13 MCP tools · Stage-3 LSP · native wysna.lockShared Verification Contract · 209 / 209 Four-Engine Conformance Parity8B WVal64 ABI v3 · Atomic ARC + CoW · ASan/UBSan verified · Apache-2.0
Seed constructs the initial bootstrap binary; Stage-0 → Stage-1 → Stage-2 must produce bit-identical C99 outputs (C0 == C1 == C2).
  • Stage 0: Initial engine compiles selfhost/compiler.wysna → emits C0.
  • Stage 1: C0 compiles selfhost/compiler.wysna → emits C1.
  • Stage 2: C1 compiles selfhost/compiler.wysna → emits C2.
  • Fixed-Point Gate: CI and tools/package_native.py require sha256(C0) == sha256(C1) == sha256(C2) AND independent native bootstrap verification via tools/bootstrap_from_native.sh without Python.