Item 2 (Agra ruling): a compile-time INTEGRAL float (`4.0`, `N : f64 : 4.0`, `N :: 4.0`) used as an array dimension / Vector lane / generic value-param count / `inline for` bound now folds to its integer at the shared leaf — `program_index.floatToIntExact`, used by both the `.float_literal` arm of `evalConstIntExpr` and `moduleConstInt`. All four consumers route through the one evaluator, so `[4.0]s64` lays out the same `[4]s64` uniformly; a non-integral (`4.5`) or negative value stays rejected by the downstream `foldDimU32` gate. Pass-0 now pre-registers float-valued module consts for forward-alias parity with int consts. Item 1: a generic value-param bind (`Box($K: u32)`) never range-checked the folded arg, so `Box(5_000_000_000)` compiled and ran. The bind now range-checks against the param's declared type — a `u32` count through the shared `foldDimU32` gate (making program_index's "single u32 gate for value-param counts" doc true), any other integer type through the new `program_index.intTypeRange` — and emits a clean "value N does not fit in u32 parameter K" otherwise. The declared type is threaded via a new `TemplateParam.value_type`. Regressions: examples 0145 (integral-float array dim), 1504 (Vector lane), 0611 (inline-for bound), 0209 (value-param integral-float), 1132 (non-integral float dim rejected), 1133 (negative float dim rejected), 1134 (oversized u32 value-param rejected) + program_index float-fold unit tests. Gate: zig build, zig build test, 406/0 run_examples.
30 lines
1.3 KiB
Plaintext
30 lines
1.3 KiB
Plaintext
// An array dimension accepts any compile-time numeric constant whose value is a
|
|
// positive INTEGRAL number — an integral float (`4.0`) folds to its integer just
|
|
// like `4`. A float-typed const (`N : f64 : 4.0`), an untyped-float const
|
|
// (`M :: 4.0`), and a direct float literal (`[4.0]s64`) all lay out the same
|
|
// `[4]s64` as the integer spelling, so element store/read is in bounds.
|
|
//
|
|
// Regression (issue 0083 / F0.4 attempt 8, Agra ruling): an integral float used
|
|
// as a dimension was wrongly rejected "must be a compile-time integer constant".
|
|
// The shared const-int evaluator now folds an integral float literal (and a
|
|
// float-typed module const) via `program_index.floatToIntExact`; a non-integral
|
|
// float (`4.5`) is still rejected (see 1132).
|
|
#import "modules/std.sx";
|
|
|
|
N : f64 : 4.0; // float-typed const
|
|
M :: 4.0; // untyped float const
|
|
|
|
main :: () {
|
|
a : [N]s64 = ---; // dim from a float-typed const
|
|
a[0] = 10; a[3] = 40;
|
|
print("a len={} a0={} a3={}\n", a.len, a[0], a[3]);
|
|
|
|
b : [M]s64 = ---; // dim from an untyped float const
|
|
b[1] = 21;
|
|
print("b len={} b1={}\n", b.len, b[1]);
|
|
|
|
c : [4.0]s64 = ---; // direct integral-float-literal dim
|
|
c[2] = 32;
|
|
print("c len={} c2={}\n", c.len, c[2]);
|
|
}
|