cubical-transport-hott-lean4/native/cubical
Maximus Gorog c2e3ecb3e3
Some checks are pending
Lean Action CI / build (push) Waiting to run
Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI
Implements the cells-spec vision: a computation space that preserves
auditability, correctness, interactivity. Phase 1 (Lean kernel +
naga-IR Rust backend) is closed; foundation hypothesis stack
(Selection H1+H2, Subobject H3, Trace H5, Obs.Ctx C2, Cubical.Trace)
landed.

Highlights:
- Cubical-HoTT syntax + value/eval/readback in Lean
- naga-IR pipeline (no GLSL string crosses FFI; 17/17 probes pass)
- Honesty audit: every non-transport (sealed cells, vertex shader,
  Y-flip, presentation conventions) is documented as such
- Polymorphic Trace α as free monoid; Cubical.Trace gives
  CTerm → Trace CTerm by structural fold (homomorphism = definition)
- Selection as Huet zipper; Subobject as Boolean algebra over WCell
- All theorems proven; the proof IS the implementation

See STATUS.md for the resume guide.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 20:40:45 -06:00
..
include Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
src Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
test Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
build.rs Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
Cargo.lock Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
Cargo.toml Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
README.md Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
shim.c Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00
WASM.md Initial commit: topolei — cubical-transport HoTT in Lean 4 + Rust FFI 2026-04-27 20:40:45 -06:00

topolei-cubical — 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/libtopolei_cubical.a
Native cdylib target/release/libtopolei_cubical.so (linux), .dylib (macos), .dll (windows)
Wasm cdylib target/wasm32-unknown-unknown/release/topolei_cubical.wasm
Wasm staticlib target/wasm32-unknown-unknown/release/libtopolei_cubical.a

Discipline

  • no_std throughout — 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 — ~12 extern "C" declarations for the Lean runtime primitives we need. No lean-sys dependency (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).
  • Phase D.wasm : wasm32 target + JS test harness (10/10 passing via node test/wasm_harness.mjs). See WASM.md for integration with a Lean-wasm composite artifact.
  • Phase D.properties : 46 property-based tests in Topolei/Cubical/PropertyTest.lean covering λ β-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-bench exe: λ β & Σ 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: Topolei/Cubical/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/
│   └── topolei_cubical.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 BC):

└── src/
    ├── cubical/
    │   ├── mod.rs
    │   ├── eval.rs
    │   ├── transport.rs
    │   ├── comp.rs
    │   ├── glue.rs
    │   └── readback.rs
    ├── subst/
    │   ├── mod.rs
    │   ├── dim_expr.rs
    │   └── face.rs
    └── ...