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-25669cc87b7b2e17f4118fb4c6efa8ecc84bbdca8557672fb5af57e1927d6984a2e
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 Intreferences, 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.
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.
| Review topic | Information to check |
|---|---|
| Source revision | SHA-256 digest bound to this reading edition |
| Availability | Current capability record and tool options |
| Evidence boundary | Model, size and interpretation limits above |