oxilean-kernel
The Trusted Computing Base (TCB) of OxiLean
The kernel is the core responsible for type checking in the Calculus of Inductive Constructions (CiC). Only code in this crate needs to be trusted for logical soundness.
Design Principles
- Zero external dependencies -- only
stdis used - No
unsafecode -- enforced by#![forbid(unsafe_code)] - 113,179 SLOC -- comprehensive implementation
- WASM-compatible -- no system calls
Module Overview
| Module | Status | Description |
|---|---|---|
arena.rs |
Implemented | Typed arena allocator with Idx<T> index type |
name.rs |
Implemented | Hierarchical names (Nat.add.comm) with name! macro |
level.rs |
Implemented | Universe levels (Zero, Succ, Max, IMax, Param) |
expr.rs |
Implemented | Core expression type (11 variants) |
subst.rs |
Implemented | Substitution: instantiate, abstract, lift_bvars |
reduce.rs |
Implemented | WHNF reduction (beta, delta, zeta, iota, projection, quotient) |
infer.rs |
Implemented | Type inference for all Expr forms |
def_eq.rs |
Implemented | Definitional equality with proof irrelevance |
check.rs |
Implemented | Declaration checking (Axiom, Definition, Theorem) |
inductive.rs |
Implemented | Inductive types, positivity check, recursor generation |
env.rs |
Implemented | Global environment (declaration storage) |
whnf.rs |
Implemented | Weak head normal form evaluation |
quot.rs |
Implemented | Quotient type support |
builtin.rs |
Implemented | Built-in constant definitions and operations |
Core Types
Arena<T> & Idx<T>
Typed arena allocator. All expression nodes are allocated contiguously for cache-friendly traversal. Idx<T> is a u32-based index with zero-cost PhantomData typing.
let mut arena = new;
let idx: = arena.alloc;
let val: &MyType = arena.get;
Name
Hierarchical names representing identifiers like Nat.add.comm:
// Convenience macro:
let n = name!; // -> Nat.add.comm
Level
Universe levels for the sort hierarchy Prop : Type 0 : Type 1 : ...:
Expr
The core expression type -- all terms in the type theory:
| Variant | Description | Example |
|---|---|---|
BVar(u32) |
Bound variable (de Bruijn index) | #0, #1 |
FVar(FVarId) |
Free variable (unique ID) | x, alpha |
Sort(Level) |
Universe sort | Prop, Type u |
Const(Name, Vec<Level>) |
Named constant | Nat.add.{u} |
App(Box<Expr>, Box<Expr>) |
Application | f a |
Lam(BinderInfo, Name, Box<Expr>, Box<Expr>) |
Lambda | fun (x : T), body |
Pi(BinderInfo, Name, Box<Expr>, Box<Expr>) |
Pi / forall | Pi (x : T), body |
Let(Name, Box<Expr>, Box<Expr>, Box<Expr>) |
Let binding | let x : T := v in body |
Lit(Literal) |
Literal | 42, "hello" |
Proj(Name, u32, Box<Expr>) |
Projection | s.1 |
Usage
use ;
// Create Prop (Sort 0)
let prop = Sort;
// Create Type 0 (Sort 1)
let type0 = Sort;
// Create identity function type: Pi (alpha : Type 0), alpha -> alpha
let alpha = str;
let id_type = Pi;
Testing
License
Copyright COOLJAPAN OU (Team Kitasan). Apache-2.0 -- See LICENSE for details.