r/Compilers • • 3h ago

BuildLang 2.0: Self-hosted zero-C systems & GPU compiler (5 shader backends, RNS-CRT GPU FP64, e-graph superopt certs)

Hi r/Compilers,

Over the past year I have been building BuildLang 2.0, an open-source, self-hosted systems and GPU compiler written with zero C runtime or C toolchain dependencies. I am sharing the architecture and design tradeoffs here and would genuinely appreciate technical critique from other compiler engineers.

Architecture Overview

  1. Zero-C 3-Stage Fixed-Point Bootstrap: The compiler self-hosts across native and portable backends (PE64, ELF64, RV64, and WASM) with direct object/executable emission and no dependency on libc or an external C linker. CI enforces cryptographic fixed-point convergence (Stage-2 == Stage-3 bit-for-bit, GAPS = 0).
  2. Explicit Effect Rows & Linear Disjoint Ownership: Functions declare effects directly in their type signature (performs {} statically proves mathematical purity: no I/O, no ambient global mutation, no nondeterministic clocks). Memory management combines Polonius-style CFG borrow analysis with Austral-inspired linear disjoint ownership (--strict-ownership), enforcing single-consumption invariants along every CFG path without GC.
  3. Single-Source SSA Shader IR (5 Backends + Subgroup Uniformity): Rather than splitting host code and device shaders across separate languages and header-padding conventions, a single .bld kernel lowers through a shared SSA Shader IR to SPIR-V (checked with spirv-val), WGSL, HLSL, GLSL, and MSL. Prior to emission, static SSA uniformity analysis verifies subgroup and workgroup barrier convergence, and host-device buffer structs are statically layout-checked across std140, std430, cbuffer, and scalar block rules. A bounded-fuel reference VM executes the same kernels on CPU (3.88M invocations/sec) to verify 0-ULP CPU/GPU parity.
  4. Certified E-Graph Equality Saturation & Superoptimization: Mid-end algebraic and bitvector optimizations run through bounded equality saturation over e-graphs, emitting machine-checkable rewrite certificates so aggressive instruction-combining passes do not silently introduce poison/undef mismatches.
  5. Fused GPU Ozaki-II RNS-CRT Exact Arithmetic: Because consumer GPUs heavily throttle hardware IEEE-754 FP64, we implemented fused Ozaki-II Residue Number System + Chinese Remainder Theorem (RNS-CRT) codegen targeting INT8 Tensor Cores (PR #432). On an RTX 4090, this path achieves 8.29x higher throughput and 120x tighter accuracy than native hardware FP64 by deferring rounding until final reconstruction.

Source & Technical Documentation

I would welcome feedback or hard questions on any part of the pipeline, especially around combining effect rows with linear capabilities across CFG joins, e-graph extraction cost models for GPU targets, or cross-ABI struct layout verification.

0 Upvotes

0 comments sorted by