Specification

Phase 1: Implementation — Index

The shape-typed core compiled end-to-end. Eight sections that take Phase 0's spec from paper to working language: a compiler in OCaml, a runtime in Rust, a parallel verification track in Lean 4, comprehensive testing, observability built in from day one, and the first version of the public API for external library authors.

Phase 1 is implementation work, not specification. Where Phase 0 committed to what the language is, Phase 1 commits to what gets built and how. The discipline is the same as Phase 0's — concrete decisions with rationale, tracked open issues, abandonment triggers stated explicitly — but the substance is engineering rather than formal rules.

The eight sections

  1. Scope, Milestones, and Exit Criteria — What Phase 1 delivers, broken into three internal milestones. The end-to-end transformer block forward pass on GPU as the load-bearing acceptance criterion. Risks and abandonment criteria stated explicitly.

  2. Compiler Implementation — OCaml end-to-end: parser, elaborator, type-checker, lowering pipeline, LLVM driver. The bidirectional type-checking discipline. Plain ADTs for the typed IR (not GADTs). The dramatic simplification of the GPU path: dispatch to library kernels rather than custom kernel generation.

  3. Runtime Implementation — Rust end-to-end: MemoryResource trait + four implementations, Tensor struct with DLPack-compatible #[repr(C)] prefix, ~17 FFI entry points the compiler emits calls to, CUDA toolchain integration, the DLPack interop demo as the runtime's flagship validation.

  4. Observability — Tracing, Logging, Diagnostics — The instrumentation infrastructure that makes Phase 1 debuggable from day one. Three pillars (tracing, logging, diagnostics). Logs for OCaml, tracing + nvtx-rs for Rust. Cross-system correlation via module IDs. Performance discipline: < 5% overhead in default mode, < 1% disabled.

  5. Operation Set Extensions — Four new primitives that close the Phase 0 expressibility gap: variadic-batch matmul, gather, softmax-as-primitive, repeat_interleave. Each with typing rules, CPU lowering through MLIR linalg, GPU lowering through the runtime FFI, and tests. The "idiomatic transformer block in <200 lines" acceptance criterion.

  6. Verification Track — Lean 4 mechanization running parallel to implementation. Phase 0 §1–§4 stated; basic proofs for §1 and §3; one non-trivial proof — subject reduction for the elementwise fragment — fully proven. Translation validation infrastructure committed; trusted-mode discharge for Phase 1, full discharge in Phase 6.

  7. Testing, Quality, and Public ABI — The cross-cutting quality concerns. The testing pyramid (unit, integration, golden vs. PyTorch, GPU end-to-end). Two-tier CI (standard always; GPU on PRs touching GPU paths). Performance regression infrastructure consuming observability traces. Three ABI categories with snapshot tests. Library author's guide v0.1 with worked example as the load-bearing acceptance criterion.

  8. Exit Criteria and Phase 2 Entry — Consolidated acceptance criteria from all seven preceding sections. The judgment-call exit criterion in operational terms (five questions). Risks revisited with implementation context. Phase 2 entry conditions and the handoff manifest. The arc forward — what Phase 2 starts with and where the project goes after.

Key commitments

The decisions that shape everything Phase 1 builds:

Decision Section
Three-language stack: OCaml + Rust + Lean 4 (per Phase 0 §5.2) 2, 3, 6
Plain ADTs for the typed IR; well-formedness as a maintained invariant 2 §5.1
GPU operations dispatch to library kernels (cuBLAS, cuDNN); no custom kernel generation in Phase 1 2 §8
Bidirectional type-checking with batched SMT discharge 2 §5.2, §6
MemoryResource trait + four implementations as the memory architecture 3 §4
Tensor struct with DLPack-compatible #[repr(C)] prefix; zero-copy interop 3 §5
~17 FFI entry points: small, orthogonal, stateless (handler-friendly per the bootstrap track) 3 §6
Observability built in from day one, not retrofitted 4
Cross-system correlation via 128-bit module IDs 4 §6
NVTX integration for NVIDIA Nsight visibility 4 §7
Four operation extensions: variadic matmul, gather, softmax, repeat_interleave 5
Phase 1 verification: one non-trivial proof (elementwise subject reduction) 6 §5
Lean mechanization is canonical when it disagrees with implementation 6 §7.1
Two-tier CI: standard always, GPU on relevant PRs 7 §7
Three-category public ABI with snapshot testing 7 §8
Library author's guide v0.1 with worked example 7 §9

Cross-cutting commitments worth elevating

A few patterns recur across multiple sections and deserve specific attention:

The forbidden temptations in Phase 1. Section 1 §5 forbids tape-based AD, sharding type prototypes, sparsity primitives, tile-IR work — each has a designated framework in a designated phase. Cutting corners in Phase 1 short-circuits the design work that gives them shape. This discipline is hard to maintain in solo projects.

Cheap-now, expensive-later commitments. The DLPack ABI prefix (Section 3 §5), the runtime FFI design discipline (Section 3 §6), the translation-validation obligation format (Section 6 §6), the ABI snapshot tests (Section 7 §8.3). Each costs little to commit to during Phase 1; each is expensive or impossible to retrofit.

Load-bearing acceptance criteria. Three single-criterion tests that operationalize the rest: the transformer block forward pass on GPU (§1), the DLPack interop demo (§3), the library author's guide worked example (§7). Each can be verified independently; each fails if the corresponding architectural commitment was wrong.

What Phase 1 does not include

Phase 1's scope is bounded. The following are deliberately deferred:

This is the contract for what Phase 2 onward will need to handle. Phase 1 must not accidentally implement any of it; doing so creates inconsistencies between phases and forces re-work.

Suggested reading order

For a first pass: read in numerical order, 1 → 8. Sections 2 and 3 are the longest; allocate accordingly.

For someone implementing Phase 1: Section 1 first to internalize the milestones; then Sections 2 and 3 in detail; then Section 4 (observability is cross-cutting); then Sections 5–7 as the work in each domain begins; Section 8 for the exit decision.

For someone evaluating whether to commit to Phase 1 implementation: Section 1 (scope and exit criteria), Section 8 (the consolidated acceptance criteria), then a quick pass through the open issues sections of 2–7 (the §13–§14 of each) to surface the cumulative engineering risk.

For someone reviewing the design without intent to implement: Section 1 for framing; Section 8 for synthesis; then drill into whichever section's domain interests them.

Phase 1 exit criteria

Section 8 §2 consolidates the criteria. Briefly:

Phase 1 is the gateway phase. Phase 0 was paper, cheap to walk away from. Phases 2–7 build on Phase 1 in compounding ways. Phase 1's exit decision is the moment the project commits to the framework as built; after Phase 1, revision becomes more expensive every phase.

Related documents

What's next

If Phase 1 is accepted: Phase 2 begins with the AD-as-handler proof of concept (per the bootstrap-and-self-modeling forward track §6). The full Phase 2 plan is written when Phase 2 is nearing.

If Phase 1 surfaces design issues: revise the affected Phase 0 or Phase 1 sections; re-evaluate; restart Phase 1 implementation. The cost of revision is large but bounded; the cost of building Phase 2+ on patched foundations is much larger.

If the project is paused or abandoned: the Phase 0 spec, the Phase 1 implementation work to that point, and the forward-track documents stand as a research artifact regardless. The thesis was tested honestly; whatever the answer, the path forward is clear.