Herramientas y ArquitecturaCompiler · 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.
Esta página aún no está disponible en tu idioma.
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.
1. Canonical Compilation Pipeline
Section titled “1. Canonical Compilation Pipeline”CompilerService&CompilationSession: Manages immutable source snapshots, interface-digest incremental early cutoff, module graphs, and canonical type interning.- Checked AST → Typed HIR: Resolves nominal types, monomorphized generics,
from ... useimports, exhaustivematchchecks, andrequires/ensurescontracts. - 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. - Backends:
- ANSI C99 (Primary Stable): Emits clean, auditable C99 linked against
runtime/wysna_runtime.hand compiled via bundled Zig 0.15.2 (or systemclang/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).
- ANSI C99 (Primary Stable): Emits clean, auditable C99 linked against
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
<= 6UTF-8 bytes live inline directly inside the 8-byteWVal64value with zero heap allocation; longer strings carry anO(1)cachedhash_cache. - Unboxed Scalar Lists:
list[int],list[float], andlist[bool]use specialized contiguous buffers withO(1)release andmemcpyCoW 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
WStructBufallocations to minimize per-instance memory overhead. - Source Debugging (
#line): Opt-in C99#linedirectives map generated C back to exact.wysnasource 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:
- Stage 0: Initial engine compiles
selfhost/compiler.wysna→ emitsC0. - Stage 1:
C0compilesselfhost/compiler.wysna→ emitsC1. - Stage 2:
C1compilesselfhost/compiler.wysna→ emitsC2. - Fixed-Point Gate: CI and
tools/package_native.pyrequiresha256(C0) == sha256(C1) == sha256(C2)AND independent native bootstrap verification viatools/bootstrap_from_native.shwithout Python.