Two structural changes landed together as one coherent body of work.
## 1. Engine is name-clean from higher-order projects
The engine no longer carries "topolei" in its own naming surface.
Higher-order projects depend on the engine, not vice versa, so the
engine should be self-named.
topolei-cubical (Cargo) → cubical-transport
libtopolei_cubical.a → libcubical_transport.a
topolei_cubical.h → cubical_transport.h
TOPOLEI_FFI_ABI_VERSION → CUBICAL_TRANSPORT_ABI_VERSION
topolei_cubical_* (14 FFI fns) → cubical_transport_*
topolei_shim_* (9 shim fns) → cubical_transport_shim_*
Inter-repo references describing topolei as a downstream consumer
(README, KERNEL_BOUNDARY.md, INDUCTIVE_TYPES.md, etc.) are preserved
as legitimate dependency-direction descriptions.
## 2. Universe-stratified, dependently-typed CType
CType : ULevel → Type (genuinely indexed inductive)
with dependent pi/sigma carrying a binder name, a lift constructor
for cumulativity, and parameter lists of Σ-packaged types.
Per CCHM rules:
· univ ℓ : CType (ℓ.succ)
· pi/sigma : CType (max ℓ_A ℓ_B), with named binder
· path A : at A's level
· glue T A : T and A at same level
· ind : at user-chosen level (heterogeneous-level params)
· interval : CType .zero
· lift : CType (ℓ.succ), data-preserving
Every existing engine module cascades through {ℓ : ULevel} implicits
on functions/theorems, pi/sigma binder updates, and Σ-packaged params
lists. CTerm stays un-indexed (universe lives on CType).
## 3. Substrate machinery for the cascade
Universe.lean — ULevel inductive + max algebra (assoc, comm, etc.),
all theorems proven structurally.
Syntax.lean — adds SkeletalCType enum + CType.skeleton level-erasure
projection + per-constructor skeleton_* simp lemmas +
CType.ind_skeleton_ne_pi disjointness lemma. Used to
discharge cross-level HEq cases in TransportLaws/CompLaws
without invoking K.
## 4. Rust ABI v3 → v4
Lean 4 keeps implicit {ℓ : ULevel} parameters at runtime as constructor
fields, in declaration order interleaved with explicit args (verified
via probeLayout instrumentation). Layout for level-bearing constructors
documented in cubical_transport.h §"v4 layout tables".
CType.pi : 5 fields — [ℓ_d, ℓ_c, var, A, B]
CType.path : 4 fields — [ℓ, A, a, b]
CType.glue : 9 fields — [ℓ, φ, T, f, fInv, sec, ret, coh, A]
CType.ind : 3 fields — [ℓ, S, params]
CType.lift : 2 fields — [ℓ, A]
CTerm.transp : 5 fields — [i, ℓ, A, φ, t] (i precedes ℓ)
CVal.vCompFun : 9 fields — [ℓ_d, ℓ_c, env, i, dom, cod, φ, u, t]
... etc
All Rust marshalling (value.rs, eval.rs, transport.rs, composition.rs,
glue.rs, beta.rs, dim_absent.rs, readback.rs, subst.rs, ffi.rs, tags.rs)
updated to match.
## Discipline
· Zero sorry in CubicalTransport/.
· Zero noncomputable instances; zero Classical.propDecidable shortcuts.
· No CType.level projection (the level lives in the inductive's index).
· No parallel CTypeU type.
· No stub substrate types (def Ω := CType.univ etc.).
· Tests restored to full coverage (EvalTest 623 lines, FFITest 351
lines with classifier-runtime tests intact).
## Verification
cd cubical-transport-hott-lean4
lake build # 48 jobs OK
./.lake/build/bin/cubical-test
# ── 49/49 passed ──
# ── 46/46 properties passed ──
# PASS: all smoke + property tests
cd ../topolei
lake build # 90 jobs OK
./.lake/build/bin/probe-test
# ── 7/7 probes passed ──
# PASS: GPU output matches Lean ShaderSemantic
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3.7 KiB
cubical-transport — Rust backend
Rust implementation of the cubical-transport HoTT evaluator for topolei — Lean 4's cubical-HoTT kernel extension.
See FFI_DESIGN.md and FFI_COMPLETENESS.md at the project root for
the full C ABI contract and per-function axiom audit.
Build
# Native staticlib + cdylib (linux / macos / windows):
cargo build --release
# wasm32-unknown-unknown (for Lean-wasm composite artifacts):
cargo build --release --target wasm32-unknown-unknown
Artifacts:
| Target | Path |
|---|---|
| Native staticlib | target/release/libcubical_transport.a |
| Native cdylib | target/release/libcubical_transport.so (linux), .dylib (macos), .dll (windows) |
| Wasm cdylib | target/wasm32-unknown-unknown/release/cubical_transport.wasm |
| Wasm staticlib | target/wasm32-unknown-unknown/release/libcubical_transport.a |
Discipline
no_stdthroughout — wasm32-unknown-unknown has no std, and native uses the same source for ABI uniformity.- Pure-functional evaluator — no IO, no threads, no allocator. All
objects live in Lean's heap; Rust operates via
lean_object*pointers. - Hand-rolled
lean_runtime.rs— ~12extern "C"declarations for the Lean runtime primitives we need. Nolean-sysdependency (that crate isn't wasm-ready).
Phase tracker
- Phase A ✅: crate skeleton + stubs.
- Phase B ✅: full evaluator implementation (14 FFI entries).
- Phase C ✅:
@[implemented_by]wiring + native staticlib linkage- smoke tests (9/9 passing via
lake build cubical-test).
- smoke tests (9/9 passing via
- Phase D.wasm ✅: wasm32 target + JS test harness (10/10 passing
via
node test/wasm_harness.mjs). SeeWASM.mdfor integration with a Lean-wasm composite artifact. - Phase D.properties ✅: 46 property-based tests in
CubicalTransport/PropertyTest.leancovering λ β-rules, Σ β-rules, eval determinism, DimExpr idempotence + literals, FaceFormula absorption, readback roundtrip. 55/55 total (9 smoke + 46 property). - Phase D.bench ✅: baseline perf benchmarks via
cubical-benchexe: λ β & Σ projections 11 ns/iter, normalizers ~50 ns/op, readback 11 ns/iter (100k iters, accumulator prevents DCE).
Testing
Two test surfaces, both currently passing:
Native smoke tests (Lean-side)
lake build cubical-test
./.lake/build/bin/cubical-test
Expected output: ── 9 / 9 passed ──, covering λ-fragment eval,
Σ β-rules, readback, and normalizer reductions. Source:
CubicalTransport/FFITest.lean + CubicalTest.lean.
Wasm smoke tests (Node.js harness)
cargo build --release --target wasm32-unknown-unknown
node test/wasm_harness.mjs
Expected output: ── 10 / 10 tests passed ──. The harness
implements a minimal JS version of Lean's runtime (bump allocator +
object header helpers) to exercise both scalar and heap-allocating
reductions. See WASM.md for the full ABI contract and integration
with a Lean-wasm composite artifact.
Layout
native/cubical/
├── Cargo.toml
├── README.md — this file
├── include/
│ └── cubical_transport.h — C declarations (ABI v1)
└── src/
├── lib.rs — crate root; panic handler
├── lean_runtime.rs — hand-rolled Lean C ABI
└── ffi.rs — #[no_mangle] exports (stubs in Phase A)
Future expansion (Phases B–C):
└── src/
├── cubical/
│ ├── mod.rs
│ ├── eval.rs
│ ├── transport.rs
│ ├── comp.rs
│ ├── glue.rs
│ └── readback.rs
├── subst/
│ ├── mod.rs
│ ├── dim_expr.rs
│ └── face.rs
└── ...