trident/src.md

Source Architecture

The compiler is organized as a pipeline. Source text enters at the syntax layer, flows through type checking and optional analysis passes, and exits as Triton VM assembly (TASM).

source.tri
    |
    v
 syntax/       lexer -> parser -> AST
    |
    v
 typecheck/    type checking, borrow checking, generics
    |
    +----> tir/       Trident IR: instruction selection + stack lowering
    |        +----> triton.rs  (Triton VM TASM output)
    |
    v
 output.tasm

Parallel to the main pipeline, several modules provide analysis, tooling, and package management:

 cost/         static cost analysis (trace height estimation)
 verify/       formal verification (symbolic execution, SMT, equivalence)
 tools/        LSP, scaffolding, module resolution, introspection
 package/     content-addressed package management, store, registry

Module Map

Module LOC What it does
syntax/ 4,392 Lexer, parser, token definitions, formatter
typecheck/ 3,007 Type checker with borrow analysis, generics, and builtin registration
tir/ 3,678 Trident IR: opcode definitions, AST→TIR builder, Triton lowering, stack manager
cost/ 2,335 Static cost analyzer, per-function breakdown, optimization hints and reports, target cost models
verify/ 5,570 Symbolic execution, constraint solving, SMT encoding, equivalence checking, invariant synthesis, JSON reports
package/ 6,494 BLAKE3 hashing, Poseidon2, definitions store, registry server/client, dependency manifests, compilation cache
tools/ 5,004 Language Server, code scaffolding, definition viewer, project config, module resolution, target configuration, artifact packaging

Top-Level Files

File LOC Role
ast.rs 371 AST node definitions shared by every stage
lib.rs 2,700 Public API, re-exports, and orchestration functions (compile, analyze_costs, check_file)
main.rs 2,650 CLI entry point: argument parsing and command dispatch
linker.rs 134 Multi-module linker for cross-module calls

Total: ~36,700 lines across 57 Rust files, 5 runtime dependencies.

Compilation Pipeline

Syntax (syntax/). The lexer tokenizes source into the token types defined in lexeme.rs. The parser produces a typed AST (ast.rs). The formatter can pretty-print any AST back to canonical source.

Type Checking (typecheck/). The type checker validates types, resolves generics via monomorphization, performs borrow/move analysis, and registers builtin function signatures (builtins.rs). Diagnostics are emitted for type mismatches, undefined variables, unused bindings, and borrow violations.

TIR Pipeline (tir/). The TIR builder translates the typed AST into a flat sequence of TIROp instructions. The Triton lowering produces TASM assembly. The stack manager tracks operand positions with automatic RAM spill/reload. The linker resolves cross-module calls.

Cost Analysis (cost/). The analyzer walks the AST and sums per-instruction costs using a target-specific CostModel. The report module formats results, generates optimization hints, and provides JSON serialization for --compare workflows.

Formal Verification (verify/). The symbolic executor builds path constraints over the AST. The solver uses Schwartz-Zippel randomized testing and bounded model checking. The SMT module encodes constraints in SMT-LIB2 for external solvers. The equivalence checker proves two functions compute the same result. The synthesizer infers loop invariants automatically.

Package Management (package/). Content-addressed storage using BLAKE3 hashing with Poseidon2 for in-proof verification. The definitions store manages a local codebase of named, versioned definitions. The registry provides an HTTP server and client for publishing and pulling definitions.

Design Principles

Direct mapping. Every language construct maps to a known instruction pattern. The compiler is a thin translation layer, not an optimization engine. This makes proving costs predictable and the compiler auditable.

Target abstraction. The StackLowering trait and CostModel trait isolate all target-specific knowledge. Adding a new backend means implementing these two traits — the rest of the compiler is shared.

Re-exports for stability. lib.rs re-exports every module at the crate root so that internal reorganization does not break downstream code or the binary crate.

Folder

Homonyms

strata/src
src
bostrom-mcp/src
src
pussy-ts/src
src
optica/src
src
cyb/src
src
lens/src
src
zheng/src
src
honeycrisp/src
src
pussy.meme/src
src
pussy-landing/src
src
bostrom.network/src
src
bbg/src
src
soft3.js/src
src
radio/iroh-blobs/src
src
radio/iroh-ffi/src
src
lens/brakedown/src
src
radio/iroh-dns-server/src
src
cyb/src-tauri/src
src
lens/binius/src
src
radio/iroh-willow/src
src
rs/rsc/src
src
radio/radio-cli/src
src
radio/iroh-relay/src
src
honeycrisp/aruminium/src
src/ core library. zero external dependencies — only macOS system frameworks via FFI. | file | purpose | |------|---------| | `lib.rs` | public API surface: re-exports, error types | | `device.rs` | `Gpu` — GPU discovery, properties, factory methods | | `buffer.rs` | `Buffer` — zero-copy shared…
lens/ikat/src
src
strata/ext/src
src
rs/core/src
src
hemera/wgsl/src
src
honeycrisp/rane/src
src
lens/porphyry/src
src
honeycrisp/unimem/src
src
honeycrisp/acpu/src
src
radio/cyber-bao/src
src
radio/iroh-car/src
src
cyb/cyb-boot/src
src
strata/core/src
src
radio/iroh/src
src
rs/macros/src
src
radio/iroh-docs/src
src
radio/iroh-gossip/src
src
lens/assayer/src
src
hemera/rs/src
src
radio/particle/src
src
lens/core/src
src
strata/proof/src
src
radio/iroh-base/src
src
hemera/cli/src
src
nox/metal/src
src
strata/compute/src
src
rs/mir-format/src
src
bostrom-mcp/rust/src
src
strata/kuro/wgsl/src
src
radio/tests/integration/src
src
trident/editor/zed/src
src
cw-cyber/contracts/hub-tokens/src
src
cw-cyber/contracts/litium-stake/src
src
strata/nebu/cli/src
src
strata/genies/wgsl/src
src
strata/jali/rs/src
src
strata/jali/wgsl/src
src
cw-cyber/contracts/hub-networks/src
src
strata/kuro/cli/src
src
cw-cyber/packages/hub-base/src
src
cw-cyber/contracts/cybernet/src
src
radio/iroh/bench/src
src
cw-cyber/contracts/std-test/src
src
strata/jali/cli/src
src
cyb/cyb/cyb-shell/src
src
cyb/cyb/cyb-ui/src
src
cw-cyber/contracts/hub-libs/src
src
cw-cyber/contracts/cw-cyber-subgraph/src
src
strata/trop/wgsl/src
src
strata/genies/rs/src
src
strata/genies/cli/src
src
cw-cyber/contracts/litium-refer/src
src
cw-cyber/contracts/cw-cyber-passport/src
src
cw-cyber/contracts/litium-wrap/src
src
cw-cyber/contracts/hub-channels/src
src
rs/tests/macro-integration/src
src
cw-cyber/contracts/cw-cyber-gift/src
src
cw-cyber/packages/cyber-std/src
src
cw-cyber/contracts/litium-core/src
src
strata/trop/rs/src
src
cw-cyber/contracts/hub-protocols/src
src
cw-cyber/contracts/hub-skills/src
src
cyber-ts/packages/cyber-ts/src
src
cyb/cyb/cyb-portal/src
src
cw-cyber/packages/cyber-std-test/src
src
cw-cyber/contracts/litium-mine/src
src
cw-cyber/contracts/graph-filter/src
src
cyb/cyb/cyb-services/src
src
strata/nebu/wgsl/src
src
strata/trop/cli/src
src
radio/iroh-ffi/iroh-js/src
src
honeycrisp/unimem/experiments/hyp_probe/src
src
radio/iroh-ffi/kotlin/lib/src
src
honeycrisp/unimem/experiments/iosurface_probe/src
src
cyb/src-tauri/gen/android/buildSrc/src
src
honeycrisp/unimem/experiments/dext_iosurface_pa/client/src
src
cyb/src-tauri/gen/android/app/src
src
honeycrisp/unimem/experiments/dext_contiguous_alloc/client/src
src

Graph