lang::typecheck::whnf

lang/src/typecheck/whnf.mo

defwhnf#
pub def whnf (scope : Scope) (locals : LocalScope) (t : Term) : Term

Reduce t to weak-head normal form: keep reducing at the HEAD until the head is rigid (a pi, a sort, a literal, a constructor, a variable with no body, ...). Sub-terms are left alone -- the head is all a structural comparison looks at before recursing, and each recursive step goes back through unify, which reduces again.

pub because the Stage 3 reducer pins (proofs/src/checker/cubical_props.mo) observe the cubical reductions directly, not only through type_check -- the constant-family/variable-family distinction lives here and nowhere else.

defnormalize_path_endpoints#
pub def normalize_path_endpoints (scope : Scope) (locals : LocalScope) (t : Term) : Term

Rewrite every path application at a literal endpoint INSIDE t, not only at its head. whnf_path_endpoint_app fires on a top-level p i0/p i1, but a result type can bury the application under the binders an unfolded definition introduced: transp (fn i => Equiv A (p i)) (idEquiv A) whnf's to Equiv A (p i1), whose Sigma spelling mentions p i1 in a Pi codomain and a lambda body. Structural comparison then descends into those binders and never gives whnf the node with the right locals, so p i1 stayed stuck and eqToEquiv could not return Equiv A B.

LocalScope is NAME-keyed, so descending under a binder needs no de Bruijn shifting: push the binder (when it has a spellable name) so a shadowing occurrence resolves to the binder, and leave the outer entries alone.

defas_cubical_type#
pub def as_cubical_type (t : Term) (scope : Scope) (locals : LocalScope) : Term

Classify t as the Term.cubical it denotes when it is a SATURATED application of a bound cubical primitive -- the pure half of type_check_app's own try_type_check_cubical_call preamble, for a term that arrives as a TYPE rather than as a call being checked.

It exists because path_parts_of (lang/typecheck/cubical.mo) is syntactic: it recognizes Term.cubical. A path type SPELLED as a library def -- Path A a b, whose body is Cubical.PathP (fn _ => A) a b -- unfolds under delta into PathP (fn _ => A) a b, an APPLICATION SPINE of the pathp primitive's NAME, so before this every path rule (the fn i => dispatch, the endpoint rewrite in normalize_path_boundary, and unify's comparison of a Path-spelled type against the PathP the rules echo back) missed it.

Same guards, and the same reasons, as the checked-call probe: a sentinel free head, no LOCAL shadowing the name, a registered primitive, and an arity EQUALITY (a partially applied imeet i is not the cubical term).