Skip to content

System Architecture

Canontra v0.4.0.0 is built as a zero-FFI, zero-network compiler pipeline in pure Haskell (GHC 9.6.6). Version 0.4.0 combines AST normalization into a single-pass CanonicalProgram and keeps hot-path data in compact unboxed vectors rather than pointer-heavy heap trees.

[ Raw Source Bytes ]
|
v
Phase 1: Ingestion & 256-Bit SIMD/SWAR FastScan (Canontra.Canonical.SIMDScan)
- UTF-8 validation, 32 bytes/cycle CRLF -> LF conversion, Unicode NFC
|
v
Phase 2: Polyglot ByteString/SIMD Direct-to-IR Parsing (Canontra.Parser.*)
- Recursive descent (Python, FastPython, JS, Go, Rust) via flatparse
- Flat Linear Arena vectors + 16-way SwissTable symbol interning
|
v
Phase 3: Single-Pass CanonicalProgram & Normalization (Canontra.Normalize.*)
- Comment/docstring/dead-statement stripping
- Language-specific alpha-renaming (canonicalizeAlphaModuleForLang)
- Purity & IEEE-754 guarded Algebraic Normal Form + pure function sorting
|
v
Phase 4: Graph & ABI Type Contract Extraction (Canontra.Analysis.*)
- Call Graph, Lengauer-Tarjan Dominator / Frontier RPO CFG, SSA DFG
- ABI-precise Type Contract (F_T: Mutability, scalar widths, ordered TypeTuple)
- Go package dir merging, TS/JS barrel resolution, Unboxed CSR matrices
|
v
Phase 5: Canonical Binary Serialization (Canontra.Canonical.Serialize)
- Strict Big-Endian lengths, 1-byte tags, IEEE-754 -0.0/NaN normalization
|
v
Phase 6: Multi-Tier SHA-256 Hashing (Canontra.Fingerprint.*)
- F0, F1, F2, F3, F_CG, F_CF, F_DF, F_T -> F4; F_R folds composite F4
|
v
Phase 7: CNTR\x07 Incremental Slab Caching (Canontra.Cache.SlabV7)
- 256-way L1 radix jump table, 64-byte CacheRecordV6, 4KB CRC-32C pages
- Per-file FileGraphSummary payloads + transparent CNTR\x06/CNTR\x05 upgrade
|
v
Phase 8: Impact Slicing, Interchange & AI Harness Snaps (BatchImpact, Harness.*, Export.*)
- CSR backward reachability cones (--pr-base), SARIF v2.1.0, Graphviz DOT
- Stateless canontra snap checkpoints (0.1-alpha) under .canontra/snaps/
  • Single-Pass CanonicalProgram (Canontra.Normalize.Normalize): Runs normalization once per file via toCanonicalProgram, avoiding double parses and repeated AST walks in computeManifest.
  • Flat Linear Arena (Canontra.IR.Arena): Stores AST nodes in four parallel unboxed arrays (astTags, astFirstChild, astNextSibling, astPayloads) with zero intermediate CST heap allocations.
  • SwissTable Symbol Interning (Canontra.Parser.SwissTable): Open-addressing hash table with 16-way 8-bit h2 control-byte probing for O(1) symbol deduplication.
  • Unboxed CSR Graph (Canontra.Analysis.CSRGraph): Stores cross-file call and data-flow edges in flat Vector Word32 (csrRowOffsets, csrColIndices) and Vector Word16 (csrEdgeFlags) arrays using Set/IntMap deduplication.
  • Mutable MV.IOVector Chase-Lev Scheduler (Canontra.Repository.Parallel): Lock-free ChaseLevDeque backed by mutable MV.IOVector circular buffers for multi-core file scanning (+RTS -N).
  • Stateless AI Harness (Canontra.Harness.{Store,SubVersion,Guard}): Content-addressed .canontra/snaps/ storage with zero background daemon, zero IPC, and preflight SHA-256 + path-containment checks.
Layer Modules
IR & Canonical Primitives Canontra.Types, Canontra.IR.{Program,Declaration,Expression,Dependency,Arena}, Canontra.Canonical.{Float,Unicode,FastScan,SIMDScan,StreamingHash,FusedStream,Serialize}
Polyglot Frontends Canontra.Parser.{Python,FastPython,JS,Go,Rust,Polyglot,Outline,Ingest,SymbolTable,SwissTable}
Normalization Canontra.Normalize.{Alpha,Algebraic,Normalize,Fused,Rules}
Graphs & Impact Canontra.Analysis.{Scope,Symbol,CallGraph,CFG,CFGCanonical,DFG,CompactGraph,CSRGraph,WholeRepoGraph,Impact,BatchImpact,TypeContract}
Fingerprints Canontra.Fingerprint.{Source,Structural,Declaration,Dependency,CallGraph,ControlFlow,DataFlow,TypeContract,Composite,Bundle,WholeRepoCallGraph,WholeRepoDataFlow}
Cache, Repo & Security Canontra.Cache.{Common,Inode,MerkleCache,PagedCache,SlabV6,SlabV7}, Canontra.Repository.{Parallel,Repository,MerkleDAG,Watcher,Git}, Canontra.Security.Path
Harness (Alpha), CLI & Verification Canontra.Harness.{Store,SubVersion,Guard}, Canontra.CLI.{Commands,Cache,Completions}, Canontra.Comparison.{Compare,Diff}, Canontra.Export.{SARIF,Graph}, Canontra.Verification.{Determinism,Metamorphic}