← Back to AILP Home

Comptime

Nitpick comptime is the compile-time function evaluation (CTFE) layer. Code marked comptime is reduced to a constant value during compilation, so the resulting binary contains only the answer — never the computation.

Contents

Overview

// comptime(expr) — evaluate any pure expression at compile time
fixed int32:KB = comptime(1024);
fixed int32:MB = comptime(KB * 1024);

// comptime { ... } — run an entire block at compile time
comptime {
    fixed int32:check = 2 + 2;
};

// comptime func: — declare a CTFE-only function
comptime func:square = int32(int32:n) { pass n * n; };
fixed int32:nine = comptime(square(3));

Comptime differs from macros:

Comptime Macro
Operates on Values & types AST fragments
Type-checked? Yes (full type system) After expansion
Recursion Bounded by CTFE budget Bounded by depth guard
Side effects None (pure) Pure expansion only
Best for Type reflection, pure math, table generation Code patterns, syntactic sugar

When to Use Comptime

See also: META/NITPICK_COMPTIME/COMPTIME.md for the design tracker.