Feature contract: compile-time — SurfaceCompileTime → the operand's normal form as closed first-order data (arity 1)#
(compile-time E) asks the compiler to evaluate a CLOSED term E with the
kernel's unbounded naturals and to hand the program the result as data: a
literal such as 10^30 / 7^20, whose intermediates no 64-bit runtime natural
could hold. The form is draft-edition only (Alpha.Surface.Module's edition
gate refuses SurfaceCompileTime outside alpha-2027).
1. Lexical and grammar rules, including precedence and termination#
(compile-time E): the head and exactly one operand term
(Alpha.Surface.Parser, unary). No operand, or a second one, is
ALPHA-PARSE-UNEXPECTED. The parser reads (compile-time ...) as this form
in every edition.
2. Scope and binding rules, including generated names#
The form binds nothing. E must be closed with respect to LOCAL binders:
after elaboration, a free variable that is a lambda, let, branch or other
local binder of the enclosing definition (of any quantity, erased included)
is ALPHA-COMPILE-TIME-OPEN. Module-level definitions, earlier in the module
or imported, may be named; their values are unfolded by the normalization.
3. Type and quantity requirements#
E is elaborated with the form's expected type, if any, and type-checked. It
is then normalized (Inductive.dataNormalFormInContext: the outer constructor is
selected first, then its fields are normalized) and the normal form must be
first-order data (Alpha.Core.compileTimeValue): natural, byte and Bytes
literals, constructor applications and pairs of such data, and the types such
values carry as arguments (Nat, Byte, Bytes, universes, family
applications, Π and Σ types). Anything else, such as a function or a stuck
computation, is ALPHA-COMPILE-TIME-STUCK. Every natural in the data, at any
depth, must be at most 2^64 − 1, the runtime's naturals; otherwise
ALPHA-COMPILE-TIME-RANGE. E is checked against the expected type before it
is normalized (Elaborate.hs), and the kernel then checks the folded value in
its place (so (compile-time (nat-add 1 2)) at Bytes is
ALPHA-TYPE-MISMATCH). The folded value has no runtime uses of any
local (it is closed).
4. Effects, totality, and evaluation-order rules#
The evaluation happens during checking, once per elaboration of the form; the program does no work for it. Totality is the normalizer's: the form adds no fuel or bound (see the limits below).
5. Elaboration into existing core or a specifically versioned new core extension#
None: the form has no core node. The elaborator replaces it by the folded
data (a compact RNatLiteral for a natural), so the checked core, the
checked interface, erasure and ALRI see only ordinary literals and
constructors.
6. Representation and target support, where relevant#
The runtime receives the literal; every lane that runs the surrounding program runs it. A natural is a 64-bit runtime natural, hence the range check.
7. Error codes and primary/secondary origins#
All at the form's span: ALPHA-COMPILE-TIME-OPEN (a local binder),
ALPHA-COMPILE-TIME-RANGE (a natural past 64 bits), ALPHA-COMPILE-TIME-STUCK
(not first-order data); ALPHA-TYPE-MISMATCH for the folded value at the wrong
type; ALPHA-PARSE-UNEXPECTED for a wrong operand count;
ALPHA-EDITION-UNSUPPORTED-FORM under alpha-2026.
8. Formatting and migration rules#
alpha fmt formats it as any one-operand form. No migration: the head does
not exist in alpha-2026.
9. Positive, negative, execution, and edge-case tests#
tests/language/draft/compile-time/:Folds.alpha(10^30 / 10^20, a named global unfolded,Bytesand constructor data, 2^64 − 1, a closed form under a lambda), the execution testRuns.alpha(10^24 mod 251 = 25 as the exit status), and the negatives in the front matter.- The defect cases
tests/defects/compile-time-open(an open operand,ALPHA-COMPILE-TIME-OPEN, with the 10^30 / 7^20 positive control) andtests/defects/compile-time-range(2^64,ALPHA-COMPILE-TIME-RANGE, with the 2^64 − 1 control), both reviewed 2026-09-25.
10. Compatibility with the old edition, serialized forms, and cache keys#
New in alpha-2027; alpha-2026 refuses it at the edition gate. Serialized
forms contain only the folded value, so no checked-interface tag or runtime
opcode is added.
Known discrepancies and limits#
Eis type-checked before it is normalized, so a subterm the normal form would discard is still checked:DiscardedIllTyped.alphaisALPHA-TYPE-MISMATCH, and the ill-typed self-application inIllTypedDiverges.alphaisALPHA-TYPE-APPLICATION-001instead of a loop inalpha check. Folding a well-typed operand ends; its cost is the only limit.