Skip to main content
NM-RFC-0014

Compile-time constant expressions

Design document · English reading edition

RFCs record designs and changes. A proposal appearing here does not mean its feature is ready to use. Explore current language support

Status recorded in the original: Proposed

Bound original source · SHA-256
69cc87b7b2e17f4118fb4c6efa8ecc84bbdca8557672fb5af57e1927d6984a2e

Reading edition reviewed: 2026-10-02

Purpose and scope

Proposes evaluating a small integer-expression language in structural positions such as fixed sizes and repeat counts. Typed compile-time folding replaces source-wide textual substitution.

Core design rules

  • Expressions are limited to integer literals, const Int references, parentheses and closed arithmetic operations.
  • Division must be exact integer division; a remainder is not rounded away. Intermediate values remain safe integers.
  • The original expression is retained for formatting and IR while its concrete structural value is computed before execution.

Example from the original

This example illustrates the design recorded in the original. It is not by itself a claim of executable or stable support; check required options and the current version.

nm
module scalable_ghz;

const N: Int = 6;
const LAST: Int = N - 1;
const SHOTS: Int = 2 * 512;

fn main() {
  let q: QReg<N> = qreg[N];
  H(q[0]);
  for i in 0..LAST {
    CNOT(q[i], q[i + 1]);
  }
  sample SHOTS {
    let bits: BitVec<N> = measure_all(q[0..LAST]);
  }
}

Limits and interpretation

  • Measurements, mutable values and runtime parameters cannot determine register size.
  • General user functions, exponentiation and type-level programming are outside this contract.

Status and implementation boundary

The proposed source records compile-time constant negotiation. Accepting a structural expression does not raise the selected simulation backend's qubit ceiling.

Table 1
Review topicInformation to check
Source revisionSHA-256 digest bound to this reading edition
AvailabilityCurrent capability record and tool options
Evidence boundaryModel, size and interpretation limits above