Core specification
This is the normative description of the native dependent core: what
compiler/core.jh accepts, how its terms compute, and what compiler/core_lower.jh
makes of them. The design explains why each part exists and
how source is written; where the two differ about what is accepted, this page is
meant to be right, and a difference is a bug in one of them or in the code. The
elaborator (core_elab.jh) and the textual parser (core_parse.jh) are not
described: they are untrusted, since the kernel checks their output.
Status. The full properties in What is intended are not mechanically proved. The Lean 4 formalization proves arithmetic-fragment consistency and semantic conversion soundness, plus capture-avoiding index/value substitution, conversion-aware finite-scope beta preservation and logical consistency for a separate index-dependent calculus with value lets. These are not proofs of this whole calculus or the implementation. The remaining properties rest on the independent evaluator, rejection suites and reviews. The roadmap starts the full proof from this specification. Do not describe the kernel as verified.
tests/core_spec.py fails if a term of Term has no entry in
The terms, so the page cannot silently fall behind by a whole term;
it cannot tell whether a rule’s text is still accurate.
Judgments
Section titled “Judgments”The kernel’s input is a graph of term nodes, in which every child’s id is below its
parent’s. check validates this for every node, reachable or not, before typing.
Terms use de Bruijn indices. A context Γ lists bindings x : T, each erased or
runtime. There are three judgments:
- Typing,
Γ ⊢g t : T(infer). The positiongis either code, which may run, or ghost, which is a type or evidence and never runs. Some rules below say they check a part “in ghost position”. A ghost position stays ghost in every part beneath it. - Conversion,
a ≡ b(equal): the normal forms of a and b areidentical. - Uses,
use(t, v) = n(uses): how many times running a checked code term t uses variable v. Types and evidence are not visited.
require is Γ ⊢g t : T' with T' ≡ T. Checking is by inference over annotated
terms: nothing is solved or searched for.
A program is a sequence of families and definitions, each of which sees only those
before it (check). A definition d : T = v requires T to be a type or proposition
in ghost position, and ⊢g v : T, where g is ghost when T is a proposition and code
otherwise. There is no recursion between definitions.
Quantities
Section titled “Quantities”- Erased binders hold evidence, or a u64 or data value known only to types and
evidence (
binder: an erased binder’s type is a proposition, U64 or a data type). Reaching one from code is rejected (“erased value used at runtime”). A proposition’s binder must be erased. - Unrestricted values are
U64,I64, refinements and flat data. They may be used any number of times. - Owned (
owned) values are buffers and boxed data. Linear (linear) values are owned values and values ofBack. A runtime lambda on a linear binder, in code, requiresuse(body, 0) = 1, counting the function’s later parameters as part of it (uses_function). So every linear value is used exactly once at run time. - Borrows (
Ref(T)) are copied freely. They cannot be freed, consumed, stored in data or returned past their lend.
Three rules keep a linear value from being hidden in something that could run twice or not at all:
userejects a lambda that captures a linear value, unless it is the head of a redex, or a case or continuation given all its arguments, each of which runs once.- A partial application cannot take a non-erased linear argument (
unsaturated), nor capture one. - A continuation that receives owned values has no function as its result
(
not_function):Load,Lend,Take, andElimandCaseintoType 0, with the one exception underCase. An elimination intoPropmay give a function proposition: evidence does not run.
A type argument at run time must satisfy both first-order kind
(first_order_kind) and first-order value (first_order) checks. Its expected
kind normalizes to a universe, optionally preceded by a telescope whose domains
all normalize to U64. Runtime and erased U64 index binders are both allowed.
This expected-kind check also applies when the argument is a variable rather
than a lambda. The value’s normal form must mention no buffer, boxed data,
borrow, Pi or Back, since a type variable is used without linearity and could
stand for one. Its lambda annotations are omitted by the value scan only after
the expected kind has restricted family inputs to U64 indices.
Checking the value alone is insufficient: fn(A: Type) { A } has a plain body,
but substituting it for F can expose Buffer(n) behind a formerly neutral
F(Buffer(n)) domain. The conservative runtime rule therefore rejects families
over types, type families, signed indices and other non-U64 domains, even if a
particular family’s result would be harmless. Ordinary monomorphic type arguments
and U64-indexed families remain supported. Ghost computations in types/evidence
are unaffected; for example an identity type function can still appear directly
in a binder annotation that normalizes to Buffer(n). This restriction closes the
higher-kinded ownership-instantiation counterexample; it is not a new theorem
of whole-Core typing or mode preservation.
Families
Section titled “Families”A family (signature, declare) is a name, a kind (proposition or data), an arity of
at most 16 U64 indices, of which a data type’s first params are parameters (a
proposition has none), and constructors, each a closed telescope ending in the family
applied to indices. A family is visible
only after its own declaration, so it can occur only as a whole field F(indices) or
as the result: this is strict positivity.
- A field of a proposition is erased, or a U64. A recursive field is erased.
- A field of a data type is erased, or a
U64, anI64, a refinement, a buffer or an earlier data type. A recursive field of a data type is a runtime value, never erased, with the type’s parameters. A field’s type may mention the fields before it. - A data type’s constructor binds the parameters first, erased, and returns them unchanged.
- The telescope, a recursive field’s family and the parameters are matched as written,
before normalization: an alias for the telescope’s tail is not unfolded, and
n + 0does not count as the parameter n. Other field types are normalized after they are checked. - A data type is boxed when a runtime field is recursive, a buffer or boxed. A boxed type cannot hold a flat data value, which has no representation.
Case types (case_type, data_case_type, recursion_case_type, view_case_type) are
computed from the telescope and appear under Elim and Case and
View.
The terms
Section titled “The terms”Each entry gives the term’s Type rule, Uses, what it Reduces to in normal,
and how it Runs after erasure (Lower.expr). “Congruence” means normal forms of the
parts; “the parts” under Uses means the sum of the uses of the listed parts; “no uses”
means it is not visited. In a rule, T(x) is application.
Var, Global
Section titled “Var, Global”- Type. The context’s or the definition’s type, weakened. An erased
Varis rejected in code. AGlobalmust be defined earlier. - Uses.
Var(k)is 1 if k is v.Globalhas no uses: definitions are closed. - Reduces.
Varis normal.Globalunfolds to the normal form of its value. - Runs.
Varis its environment entry.Globaldoes not remain after normalization.
Universe, Prop, U64, I64, Array, Lt, Eq, Pi, Refine, Buffer, Ref, Ind
Section titled “Universe, Prop, U64, I64, Array, Lt, Eq, Pi, Refine, Buffer, Ref, Ind”- Type.
Universe(n) : Universe(n + 1), n below 32.Prop,U64andI64are inUniverse(0).Array(n),Refine(p)withp : U64 -> Prop, andBuffer(n)are inUniverse(0), with n : U64 in ghost position.Lt(a, b)andEq(a, b)are inProp, on U64 in ghost position.Ref(T)is inUniverse(0), T inUniverse(0)and owned.Ind(F, xs)needs F’s arity of U64 indices and is inUniverse(0)for data andPropotherwise.Pi(e, A, B)checks the binder, then isPropif B is a proposition, which is impredicative, and otherwiseUniverse(max(level of A, level of B)). - Uses. None.
- Reduces. Congruence.
- Runs. Types have no runtime form.
runtimemapsU64andRefineto u64,I64to i64,Buffer,Refand boxedIndto a pointer.
Lam, App
Section titled “Lam, App”- Type.
Lam(e, A, b)checks the binder, then b under it at the same position, with the use count in code when A is linear; its type isPi(e, A, B).App(f, a)needs f’s type to normalize toPi(e, A, B), requiresa : A, in ghost position if e, and has typeB[a]. In code a type argument is first order. At the top of a spine in code, a result that is still a function is a partial application: its head must not be aCase, and its arguments must not be linear. - Uses. A
Lamalone counts as 0 but rejects a capture. AnAppspine with a lambda head counts the runtime arguments and the body. AVieworCasehead counts its cases with the arguments as binders. Otherwise the head’s uses. In each case every remaining runtime argument is added. A partial application with any use is rejected. - Reduces.
App(Lam(e, A, b), a)isb[a]. In runtime mode, for a non-erased a, if a is effectful or reads, the redex is kept, binding a once, and if a may trap, the result isStrict(a, b[a]). An erased argument has no evaluation to keep. ApplyingIfLtorIfEqapplies both alternatives; applyingStrict(t, g)isStrict(t, g(a)); applying a kept redex moves the argument inside it. - Runs. A kept redex evaluates a, then the body. A head that is a
View, aCasewith erased arguments, or a recursion’s result is called with its arguments. Any other application has no runtime form.
Natural, Integer, Elements, Index
Section titled “Natural, Integer, Elements, Index”- Type.
Natural : U64,Integer : I64.Elements(xs) : Array(|xs|)with each x : I64.Index(a, i, p) : I64where a’s type isArray(n)orRef(Buffer(n)), i : U64 andp : Lt(i, n)in ghost position. - Uses. The elements;
Indexa and i. - Reduces. Congruence. An array read does not compute.
- Runs. Constants; a local array; a load at the index, with no bounds check.
Refl, Transport, Decide, ZeroLe, LtAdd, LtCancel, LtLe
Section titled “Refl, Transport, Decide, ZeroLe, LtAdd, LtCancel, LtLe”These are evidence, and every part is in ghost position.
- Type.
Refl(a) : Eq(a, a).Transport(P, e, p) : P(b)forP : U64 -> Prop,e : Eq(a, b),p : P(a). So equality eliminates only into propositions.Decide(a, b) : Lt(a, b)when a and b normalize to numerals with a below b.ZeroLe(a) : Lt(0, a + 1).LtAdd(a, b, c, p) : Lt(a + c, b + c)fromp : Lt(a, b), andLtCancelthe converse.LtLe(x, y, z, p, q) : Lt(x, z)fromp : Lt(x, y)andq : Lt(y, z + 1): the naturals are discrete.
- Uses. None.
- Reduces.
Transport(P, Refl(_), p)is p. The others are congruence. - Runs. Erased.
Arith, UAdd, USub, Strict
Section titled “Arith, UAdd, USub, Strict”- Type.
Arith(op, a, b) : I64on I64.UAdd(a, b) : U64on U64.USub(a, b, p) : U64withp : Lt(b, a + 1)in ghost position.Strict(a, b)has b’s type, a being checked. Source and textual core cannot writeStrict: normalization makes it. - Uses. The operands;
Stricta and b. - Reduces.
Arithon two integers folds unless it overflows, which stays a runtime trap.UAddbecomes the canonical sum (sum): variables in index order, then other terms, in structural order in the pure model and in their evaluation order in runtime mode, then the constant. In ghost mode a constant beyond 2^64 - 1 is a deterministic balancedUAddtree of U64 literals; runtime mode leaves such a sum as written. Collection charges every visited occurrence, including repeated graph references, to the checker step budget.(x - y) + ycancels to x when the sum has y’s parts, unless a part is effectful or y holds aStrict, keeping y’s traps. At most 64 cancellations are tried, after which the sum simply stays as it is.USubcancels(r + b) - bto r under the same conditions.Strict(a, b)is b if a cannot trap. Conversion ignoresStrict.
- Runs. Checked:
ArithandUAddtrap on overflow.USubcannot underflow: it has evidence.Strictevaluates a for its effects, then b. U64 terms therefore denote natural numbers.
Pack, Witness, Proof
Section titled “Pack, Witness, Proof”- Type.
Pack(P, a, q) : Refine(P)withP : U64 -> Propandq : P(a)in ghost position and a : U64 at the current position.Witness(s) : U64andProof(s) : P(Witness(s))fors : Refine(P), the latter in ghost position. - Uses.
PackandWitnesstheir value.Proofnone. - Reduces.
Witness(Pack(_, a, _))is a, and a witness of a branch is the branch of witnesses, keepingStrict.Proof(Pack(_, _, q))is q, throughStrict. Conversion ignoresPack’s evidence. - Runs. A refinement is its u64.
IfLt, IfEq
Section titled “IfLt, IfEq”- Type.
IfLt(a, b, yes, no)needs a and b : U64.yesis checked under an erased binder ofLt(a, b), orEq(a, b)forIfEq, and its type must not depend on it;nohas the same type. - Uses. a and b, plus the alternatives, which must use v equally.
- Reduces. On two numerals, the chosen alternative,
yesgivenDecideorRefl. Otherwise congruence. - Runs. A comparison and a branch, with no evidence. Both alternatives have one layout.
Con, Elim, Case
Section titled “Con, Elim, Case”- Type.
Con(F, k, xs)needs a constructor k of F and all and only its fields, and instantiates its telescope field by field. Runtime fields of data are at the current position, and erased fields and all fields of a proposition are in ghost position. Its type is the telescope’s result.Elim,CaseandViewneed exactly one case per constructor.Elim(F, P, cases, x)on a proposition:P : U64... -> Prop, each case ofcase_type:(fields...) -> (erased ih : P(indices of r))... -> P(result), x evidence of F, all in ghost position. Only propositions eliminate this way.Elimon data, andCase(eliminate):P : (indices...) -> F(...) -> ProporType 0, x of that type. Each case gives P at the node built from its fields, from those fields: forCase,data_case_type, with recursive fields owned; forElimon boxed data,recursion_case_type, with recursive fields erased and a hypothesisih : P(r)per recursive field, erased when P is a proposition. IntoPropit is evidence, in ghost position. The result isP(indices..., x), which, intoType 0, is no function.Caseis for boxed data. As the head of an application it may have a result that is a function of erased arguments only (erased_function), evidence, indices or data, and the application’s top must supply all of them, so nothing is left that could hold the owned values its cases receive and run twice.
- Uses.
Conits runtime fields.ElimandCase: x, plus one case’s uses, which must be equal across cases. A recursion’s cases run once per node, so they may not use an outer linear value.Elimon a proposition has none. - Reduces.
Elimon a known constructor is its case applied to the fields, then to theElimof each recursive field.Caseon a known constructor is its case applied to the fields, so the node is never built. Only runtime normalization distributesCase, andElimon data, overIfLtandIfEqin the scrutinee. Pure conversion keeps an elimination on a symbolic branch, including its dependent motive. Both modes distribute overStrict. A data type’s parameters are not given to a case. - Runs. A boxed
Conallocates a node of a tag and one slot per runtime field.Caseswitches on the tag, loads the fields and frees the node at the end of the block, and a node of the same size built before then reuses it.Elimon boxed data is a recursive function that calls itself on each recursive field first, then frees the node. Flat data has no representation: its case analysis must reduce away, and lowering rejects what does not. Runtime normalization sequences a flat constructor’s effectful or borrowed-reading runtime fields through its checked telescope before substituting the constructor. Fields are evaluated once in declaration order; erased fields stay erased. This sequencing does not run during pure conversion and does not introduce a general flat-data runtime layout. A flat result crossing a lend continuation or an effectful branch may still fail to lower; bind scalar results before building the record in those cases.
Fold, Loop
Section titled “Fold, Loop”- Type.
Fold(n, init, body): n : U64, init an I64 or an owned value of type A,body : (i : U64) -> (erased p : Lt(i, n)) -> A -> A. Its type is A.Loop(n, T, init, body):T : U64 -> Type 0orProp,init : T(0),body : (i : U64) -> (erased p : Lt(i, n)) -> T(i) -> T(i + 1), of typeT(n). IntoType 0, T’s body must beU64,I64, a refinement, a buffer or boxed data. IntoProp, everything is in ghost position and the accumulator is erased.- For both, a body that touches memory must be written with its three binders.
- Uses. n and init. The body runs many times, so any use in it is rejected.
- Reduces. A count of 0 is init. Otherwise congruence: a loop is never unrolled, and its result is known through its type. In runtime mode a body without three leading binders is eta-expanded, so that lowering finds them; lowering does not read their annotations.
- Runs. A counted loop whose accumulator is a local.
LoopintoPropis erased.
Alloc, Load, Store, Free, Drop
Section titled “Alloc, Load, Store, Free, Drop”- Type.
Alloc(n, x) : Buffer(n)with n : U64 and x : I64.Store(b, i, v, p) : Buffer(n)forb : Buffer(n), i : U64, v : I64,p : Lt(i, n)in ghost position.Load(b, i, p, k): b, i and p as forStore, andk : I64 -> Buffer(n) -> T, of type T, which depends on neither and is no function.Free(b, rest)andDrop(F, x, rest)have rest’s type, b a buffer, x of boxed F.
- Uses. The parts;
Load’s k with its two arguments as binders. - Reduces. Memory operations do not compute. In the pure model
FreeandDropare rest, andAlloc,LoadandStoreare neutral. In runtime mode all are congruence. - Runs.
Alloccallsmallocfor8 * n + 8bytes, checked, and traps on null.LoadandStoreare offsets with no bounds check.Freecallsfree.Dropcalls one function per family that frees the node, its buffers and the owned fields within.
Lend, Borrow, Deref
Section titled “Lend, Borrow, Deref”- Type.
Lend(x, f, g): x owned of type T,f : Ref(T) -> A,g : A -> T -> R. A isU64,I64, a refinement, an array, a buffer, data or aBack(outlived), so it holds no borrow; R depends on neither and is no function.- When x is a variable and f and g are lambdas, the lend is dependent (
dependent_lend): f’s body is checked with r =Borrow(x), where code may also borrow x by name, and A may mention it; g’s body is checked with the owner given back equal to x, and uses x exactly once by either name. Borrow(x) : Ref(T)for x of owned T, in ghost position, or in code only for a variable x inside the reader of a lend of it (lending).Deref(r) : Tforr : Ref(T), in ghost position only.
- Uses. A dependent lend: the reader with r =
Borrow(x), plus the continuation with y = x. Any other lend: x, f with one binder and g with two.BorrowandDerefhave none. - Reduces. In the pure model a lend is
g(f(Borrow(x)), x).Deref(Borrow(x))is x andBorrow(Deref(r))is r. In runtime mode a lend is congruence. - Runs. A borrow is the owner’s pointer: x, then f, then g.
Borrowis its variable’s pointer.Derefis erased.
- Type.
View(rec, F, T, cases, x): x :Ref(F(ps)), F boxed with no true indices. T is any type inUniverse(0), or a motiveRef(F(ps)) -> Universe(0), whose body, past anyPi, must beU64,I64, a refinement, a buffer, data or an array of a length mentioning none of those binders. Each case isview_case_type: the fields, those on the heap asRef, then, ifrec, a result per recursive field, then T at a borrow of the node it reads, whose heap fields areDerefof their borrows. Its type is T, or T(x) with a motive. - Uses. x, plus one case’s uses, equal across cases, with a function result’s arguments as binders. A recursion’s cases may not use an outer linear value. Nothing is consumed by reading.
- Reduces. In the pure model a view of
Borrow(v)with v a known node is its case applied to the fields, heap ones asBorrow, then, ifrec, the view of each recursive field. It distributes overStrictin v, but stays neutral on symbolicIfLtandIfEqso its dependent motive is retained. In runtime mode, congruence. - Runs. The same switch and recursion as for owned data, freeing nothing. A function result’s arguments are parameters of the recursion, and a hypothesis is a call.
Back, Give, Take
Section titled “Back, Give, Take”- Type.
Back(e, T, M) : Universe(0): T inUniverse(0)and owned,M : T -> Universe(0)orProp, with e set exactly when M gives a proposition (back_motive). IntoUniverse(0), M’s body isU64,I64, a refinement, a buffer, boxed data or aBack, which holds no borrow and is no function.Give(e, M, x, a) : Back(e, T, M)for x of owned T anda : M(x), in ghost position if e.Take(v, k):v : Back(e, T, M)and k literally two lambdas,fn(x : T) { fn(a : M(x)) { rest } }, the second erased exactly if e, whose annotations are compared by conversion. rest’s type depends on neither binder and is no function.
- Uses.
Givex, and a unless e.Takev, plus k with two binders.Backnone. - Reduces.
Take(Give(_, _, x, a), k)isk(x, a), through the rules forApp.Back,Giveand any otherTakeare congruence, and conversion ignoresGive’s erased evidence. - Runs.
Giveis x alone if e, and otherwise an unboxed pair of x and a.Takebinds its parts.
Absurd
Section titled “Absurd”- Type.
Absurd(T, p) : Tfor T a type or proposition that is no function, and p evidence ofLt(i, n)with n normalizing to 0. - Uses. None: it cannot run.
- Reduces. Congruence.
- Runs. An unreachable terminator, if T has a layout: lowering rejects one that has none, such as an array or flat data.
Modes of normalization
Section titled “Modes of normalization”normal computes in one of two modes. The pure model is used by the kernel for
conversion: any argument may be substituted, memory operations are neutral, and lends and views of
known values compute. Runtime mode (runtime) is used by lowering on code to run: an
argument that is effectful or reads stays bound once, traps are kept by Strict, and lends and views
stay. Runtime normalization also distributes data eliminations over symbolic branches to remove
flat data before MIR lowering. Pure conversion does not: a dependent motive may give the alternatives
different types, while IfLt and IfEq require one common type. Consequently a symbolic elimination
and its manually distributed form need not be definitionally equal. Concrete scrutinees still compute.
At an application, an argument normalized to Lam is already a function value:
its body is not evaluated when passed. It can be substituted even when the body
contains arithmetic, reads or memory effects. Likewise Strict(Lam(...), b)
normalizes to b. For a runtime lambda application, a Strict(prefix, value)
argument becomes Strict(prefix, App(lambda, value)) before substitution, so its
prefix is evaluated once before the body. Discarding a nested strict result
reassociates Strict(Strict(prefix, value), b) to
Strict(prefix, Strict(value, b)). This allows arithmetic captured by a partial
application without a runtime closure, while retaining capture-time overflow
traps even when the function is unused. Applying the function still normalizes
its body under the ordinary runtime rules. A retained redex representing an
effectful capture is floated out of a runtime lambda’s argument position, with
the consumer shifted under its binder. Discarding such a redex similarly moves
the discard under that binder. The effectful argument is never substituted or
duplicated; only its bound value is reused. This handles called and unused partial
applications such as f(free(alloc(n, 7), 5)) without runtime closure allocation. This exception is local to application and
Strict: the predicates below still inspect lambda bodies when analyzing invoked
loop and induction cases. Runtime normalization is not covered by a general
formal preservation or compiler refinement theorem.
Three syntactic predicates decide this, each conservative at the depth limit, and otherwise the disjunction over a term’s children:
effectful:Alloc,Load,Store,Free,Drop,Case, and boxedConandElim.may_trap: those, andArith,Strict,UAdd, and in runtime mode a call of a variable.reads:Viewwith a result that is not a function,Fold,Loop, and a call of a view or variable.
Absurd and Back are neither effectful nor trapping; a Give is as its owner, and its result unless
erased; Refine and Proof do not trap, and Pack is as its witness. Index has no special case: a
read of an array or a borrowed buffer may be substituted and so repeated, which is safe since the
buffer cannot change while it is lent.
Conversion (identical) is syntactic equality of normal forms, up to:
Strict(_, y)being y;- evidence being irrelevant in
USubandPack, and in an erasedGive.
Other evidence is compared as written. The structural order used to canonicalize
sums (compare, conversion_children) ignores exactly the same evidence, including
inside otherwise different atoms. Replacing an irrelevant proof must not change
where an atom sorts relative to another one. All children still participate in
graph validation, typing and substitution; irrelevance never excuses invalid evidence.
Lowering
Section titled “Lowering”compile checks the whole program again, independently of what elaboration checked, and normalizes
constructor types. There must be at least one export. An export’s parameters are all non-erased U64
or I64, since a foreign caller has no evidence to give, and its result is U64, I64 or a refinement.
Its normal form has a lambda for each parameter. Its body is normalized in runtime mode, and
Lower.expr emits MIR by the Runs entries above: evidence and erased binders have no locals, and
reaching one is an internal error.
Lowering may reject a checked program with a diagnostic. It does not emit code for one that
it cannot represent, so a program accepted by core check need not compile.
The marked .jh frontend’s check also checks executable lowering. Known core cases are:
- a term with no runtime form, such as flat data computed at run time by a view;
- a recursion whose result is an array, since
runtimehas no layout for one; - a
Load,Lend,Take, case or hypothesis whose continuation is not literally lambdas after normalization, such as a function chosen by a branch; - a case or branch whose alternatives have different layouts;
- a function result not called with all its arguments;
- an
Absurdat a type with no layout.
Limits
Section titled “Limits”Checking stops with an error, never acceptance, at any of these. Failing to compute is not evidence.
- 200,000 terms (
LIMIT), counting those the kernel makes as well as its input. - 1,000,000 steps (
STEPS) of the kernel’s recursive operations, reset for each definition with the families before it. Lowering’s normalization continues the last count. Structural equality and sum ordering charge each visited pair, including repeated DAG references; sorting variables, cancellation candidate comparisons, pool copying and removal shifts also consume this budget. Exhaustion propagates as a diagnostic rather than equality, inequality or an unsuccessful cancellation. Depth exhaustion in comparison is likewise an error, including identical IDs. These are operation charges, not a wall-clock or allocation-complexity theorem: other recursive predicates and vector/node cloning are not individually metered by these comparison checks. - Recursion depth 128 (
DEPTH), a budget for each operation rather than a bound on source nesting: for example, each field of a telescope starts anew.
What is intended
Section titled “What is intended”These are the properties the rules are meant to have. They are stated for a closed, checked program, and are tested but not proved:
- Consistency. There is no closed evidence of
Lt(0, 0). - Preservation. The pure model’s reductions are intended to preserve types. Symbolic data
elimination and views retain their motives instead of distributing into differently typed branches.
This repairs the rechecking failures in
examples/core_data.jhcandcore_indexed.jhc, as well as dependent heap cases and views.jihoo core preserves FILErechecks each definition’s pure normal form at its declared type in ghost position. Thecoresuite requires it to pass on every core example, accepted fixture and preservation regression, without expected failures. This finite check is not a proof of preservation or of runtime quantity soundness. Runtime normalization is a separate lowering transformation whose correctness remains to be established. - Quantities. In the erased program every linear value is used exactly once, and no borrow outlives its lend. Allocations are freed exactly once on every path that does not trap.
- Safety. Accesses with evidence are in bounds, and
Absurdis not reached. - Adequacy. The erased program computes the pure model’s value, or traps on an overflow or a failed allocation.
What stays trusted is the kernel’s implementation of these rules, core_lower.jh, MIR to LLVM, LLVM and
the runtime.
Formalization boundary
Section titled “Formalization boundary”The specification above, rather than historical feature snapshots in the design notes, is the intended starting point for a Lean formalization. There is not yet a machine-checked soundness proof for the whole specified calculus. A useful order is typing and capture-avoiding substitution, conversion and pure preservation, quantities and borrow lifetimes, then runtime normalization and erasure adequacy. Each theorem must state which term forms and reduction rules it covers.
Pure ghost normalization is not runtime evaluation: it can erase evidence and ignore resource use. Rechecking pure normal forms is regression evidence only; it does not establish linearity, trap preservation, allocation behavior or the correctness of lowering. The executable semantics must account for those separately. A proof of the core calculus alone does not verify the source elaborator, the implementation of its checker, MIR to LLVM, LLVM or the runtime. Partial lowering and documented source inference restrictions are not additional core typing rules and should not silently narrow a theorem advertised for the whole core.
The Lean proof boundary
now includes closed local-array selection and unsigned subtraction safety in the
higher-order Raw.Beta fragment, including ZeroLe. Bounds follow from typing
and closed literal consistency, without assuming evidence normalization. Literal
operands are required, or explicit finite beta/add evaluations to those operands.
This does not discharge the whole-calculus, quantity/borrow or lowering obligations
above; actual kernel and native behavior are checked by finite regression tests.
A quantity control foundation proves exact resource counts for successful abstract control executions and upper bounds for finite prefixes, including traps. Local binders, branches, repetition, known once-called continuations and erased code have separate rules. The missing whole-core projection, operational simulation and heap/borrow lifetime obligations are explicit; these results do not yet establish item 3 above.
Mixed binder and owner-alias accounting extends that foundation with mode-aware scopes and capture-avoiding identification of variable slots. Returned-owner aliases are counted together before branch agreement. Authenticating the modes and aliases from whole-core typing, and proving heap/borrow and runtime correspondence, remain separate obligations.
Binder-capability projection now derives modes and lend permissions from normalized-domain summaries and checks them against actual checked Core telescopes. Its formal result is conditional on authentic summaries: formation/normalization provenance, first-order type instantiation, source-owner identity and borrow lifetimes are not established by this classification theorem.
Rooted context provenance now derives descriptors along original lambda edges and resolves a Lend’s variable owner with Core’s reverse context indexing. Its structural theorem is relative to a faithful syntax view and contextual domain observer; the actual kernel interfaces are regression-tested, not proved. Whole-Lend continuation projection and heap/borrow soundness remain outstanding.
Scoped Lend projection derives reader/continuation controls in a bounded structural fragment and keeps the fresh result distinct from the returned owner. Its use-accounting theorems are relative to faithful typed observations and abstract control execution; whole-kernel substitution, runtime and heap/borrow correspondence remain open.
Lend substitution correspondence proves that variable/borrow substitution commutes with quantity-annotated source projection, including nested scopes/Lends, and compares it with actual kernel substitution. Native transformation refinement and typed mode stability, as well as runtime and heap/borrow soundness, remain separate obligations.
The heap/lease primitive semantics now proves allocation/lease invariant preservation, permanent expiry, no double free, and a nested-reader payload frame property. Coupling exact free-event identities to checked quantity traces yields actual deallocation, conditional on that trace projection. This is not a proof that whole-Core typing establishes the primitive preconditions or prevents escaping borrows; recursive heap fields, allocator address reuse and native execution correspondence remain open.
The structured scalar Lend fragment now derives reader authority, scalar-only results, heap-transition preconditions, lease-map restoration and exact free-event projection from its own scoped syntax. It instantiates the existing original/returned-owner quantity rule. A live target with no preexisting lease is an entry premise, not a proof of unique ownership aliases. Full graph/context correspondence and the broader owned-result, nested-Lend and recursive-heap cases remain open.
The bounded original-constructor Lend bridge now checks the exact root/type/lambda spine, tracks scalar/ghost binder shifts and original/returned-owner aliases, and translates supported read bodies to the scoped model. Forward and reverse correspondence cover the new restricted constructor semantics; every admitted execution satisfies the primitive heap endpoint. This does not yet formalize the whole Core operational semantics or prove the native exporter faithfully supplies the view; opaque constructors, general ownership contexts and broader heap features remain outside its scope.
Linear allocation/admitted-call programs now thread distinct live, lease-free allocation capabilities through finite calls to the admitted Lend graph fragment. They derive call-entry guards and prove concrete allocation/release conservation, exactly-once freeing of tracked resources and an empty final heap for closed complete executions. These are formal caller-program rules, not yet a translation of general native caller graphs. Successful-allocation, finite-control and scalar-fragment restrictions remain explicit; full capabilities, failures, recursion and MIR correspondence remain open.
Original finite caller graphs now recognize literal allocation and App/Lam call-binding spines directly from constructor IDs. A lexical-binding interpretation proves consumed names remain tombstones while live capability slots compact, and admitted closed caller executions inherit heap safety and a completely empty final live heap. This is a restricted heap-effect semantics, not scalar-result preservation or general native caller/lowering adequacy; the trusted exporter and finite successful- allocation restrictions remain explicit.
Lease-free heap erasure now translates this admitted caller subset into an independent pointer-identity heap with no lease state. Callee scalar results, observable effect order and erased final heaps correspond; target determinism plus source totality covers all complete target runs, including exact release/no-leak guarantees. This is an abstract erasure stage, not native MIR CFG or final caller-result adequacy.
The result-bearing caller extension distinguishes scalar bindings from live owner slots and consumed-owner tombstones. Its finite return fragment can select a literal or an earlier/later callee result; owner insertion and consumption preserve the meaning of existing scalar names. This addresses caller results for that restricted constructor subset, not general Core arithmetic/control flow or native MIR/machine result adequacy.
Bounded emitted-MIR execution
retains actual local/block/instruction identities for closed one-cell caller
examples, including malloc/assert and the initialization-loop backedge. A checked
source/MIR pair compares its scalar result and allocation/free lifecycle under
an independent bounded MIR semantics. This is conditional translation validation,
not a general core_lower.compile theorem or concrete-address machine refinement;
unsupported shapes and exhausted fuel reject rather than certify a partial run.
The pure model now also has bidirectional payload-erasure adequacy: every finite execution of an annotation/proof-payload-erased term lifts back to the source, with scalar and trap observations preserved. This is generic over the existing pure grammar and retains ghost binder slots. It is not a theorem about the full Core grammar or native ghost-slot deletion/lowering.
The typed owned-result Lend slice
now accounts separately for a newly allocated Buffer result and the original
owner. Direct continuation typing derives alias-safe consumption and primitive
heap guards. This covers a previously omitted outlived result class only for
the stated one-cell subset, not all specified ownership rules; see the
release-gap assessment.
The common constructor judgment also distinguishes scalar and owned returns. An owned result retains exactly one live, unborrowed capability instead of falsely treating that result as a leak. Fresh-context consumption composes with the existing scalar continuation guarantees; arbitrary dependent result substitution and general lowering remain outside this slice.
A owned-producing application extension connects recursive direct App/Lam graph nodes to producer evaluation and binding of the exact returned capability. The producer accounts for every current resource and the body receives only the result. The singleton body restriction is not a proof that arbitrary captures can be discarded.
Framed application retains captured owner/scalar bindings across an explicit static resource split. Its frame safety is derived from typing and execution; deterministic evaluation is stated for a fixed partition plan, not arbitrary erased or inferred plans.
The constructor-closure integration uses that same framed judgment for calls inside allocation, Free, mixed Lend and let continuations. Lend readers retain their existing restrictions: the new continuation runs after the lease closes, not inside an active reader.
The plan-free lexical execution bridge relates that composed ownership judgment to concrete captured lexical values. Static resource plans do not select runtime behavior: supported typed plans produce the same value, exact events and final heap. Consumed names stay in the runtime environment but cannot be accessed through the static context. This statement still covers the documented fragment, not arbitrary Core programs or a refinement proof for the native compiler.
The runtime-length refinement adds exact lengths and indices for uniformly initialized, read-only buffers. Its source judgment interprets open runtime U64 parameters and branch-derived Lt evidence, including a no-read path for zero length. It is a semantic closing-instance result for a stated source subset, not the general dependent Core typing theorem or a proof of native allocation capacity.