docs(spec): make the count zero-rule context-dependent per consumer (0083)
The count description claimed every count must be "positive integral", which is wrong: zero is context-dependent. Verified at HEAD — an array dimension (`[0]s64`) and a generic value-param count (`Box(0)`, $N:u32) both accept zero as a length-0 instantiation, while a `Vector` lane count stays strictly positive (`Vector(0,f32)` rejected). Negatives are rejected for array dims and unsigned value-params, but a signed value-param accepts a negative; only the integral requirement (folds 4.0, rejects 4.5) is common to all three. Split the count paragraph into per-consumer bullets stating the exact range each accepts. Range-bound paragraph unchanged. Pin the zero contrast with examples 0147 (array-dim + value-param zero accepted) and 1505 (Vector zero-lane rejected). No compiler-code change.
This commit is contained in:
19
examples/0147-types-zero-count-context.sx
Normal file
19
examples/0147-types-zero-count-context.sx
Normal file
@@ -0,0 +1,19 @@
|
||||
// Zero is a context-dependent count. An array dimension and a generic
|
||||
// value-param count both ACCEPT zero — `[0]T` is a valid empty (zero-length)
|
||||
// array, and `Box(0)` is a length-0 instantiation. (A `Vector` lane count
|
||||
// rejects zero — see 1505.) This pins the zero-accepting half of the
|
||||
// context-dependent count rule documented in specs.md (Array Types).
|
||||
//
|
||||
// Regression (F0.4 attempt 12): the spec previously claimed every count must be
|
||||
// "positive integral", which wrongly implied `[0]T` / `Box(0)` are illegal.
|
||||
#import "modules/std.sx";
|
||||
|
||||
Box :: struct($N: u32) { items: [N]s64; }
|
||||
|
||||
main :: () {
|
||||
a : [0]s64 = ---;
|
||||
print("array_dim={}\n", a.len);
|
||||
|
||||
b : Box(0) = ---;
|
||||
print("value_param={}\n", b.items.len);
|
||||
}
|
||||
15
examples/1505-vectors-zero-lane-rejected.sx
Normal file
15
examples/1505-vectors-zero-lane-rejected.sx
Normal file
@@ -0,0 +1,15 @@
|
||||
// A zero `Vector` lane count is rejected — a vector must have at least one lane
|
||||
// (strictly positive). Contrast with an array dimension / value-param count,
|
||||
// where zero is a valid length-0 instantiation (see 0147). This pins the
|
||||
// zero-rejecting half of the context-dependent count rule (specs.md, Array
|
||||
// Types).
|
||||
//
|
||||
// Regression (F0.4 attempt 12): the spec now states the zero rule per consumer;
|
||||
// the `Vector` lane count stays strictly positive while array dims / value-param
|
||||
// counts accept zero.
|
||||
#import "modules/std.sx";
|
||||
|
||||
main :: () {
|
||||
v : Vector(0, f32) = ---;
|
||||
print("unreachable: {}\n", v.x);
|
||||
}
|
||||
1
examples/expected/0147-types-zero-count-context.exit
Normal file
1
examples/expected/0147-types-zero-count-context.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
2
examples/expected/0147-types-zero-count-context.stdout
Normal file
2
examples/expected/0147-types-zero-count-context.stdout
Normal file
@@ -0,0 +1,2 @@
|
||||
array_dim=0
|
||||
value_param=0
|
||||
1
examples/expected/1505-vectors-zero-lane-rejected.exit
Normal file
1
examples/expected/1505-vectors-zero-lane-rejected.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
examples/expected/1505-vectors-zero-lane-rejected.stderr
Normal file
5
examples/expected/1505-vectors-zero-lane-rejected.stderr
Normal file
@@ -0,0 +1,5 @@
|
||||
error: Vector lane count must be a positive compile-time integer constant
|
||||
--> examples/1505-vectors-zero-lane-rejected.sx:13:16
|
||||
|
|
||||
13 | v : Vector(0, f32) = ---;
|
||||
| ^
|
||||
23
specs.md
23
specs.md
@@ -651,11 +651,24 @@ Arrays can also be constructed programmatically with the `Array` builtin:
|
||||
MyArr :: Array(5, s32); // equivalent to [5]s32
|
||||
```
|
||||
|
||||
A **count** — an array dimension, a `Vector` lane count, or a generic
|
||||
value-param count — accepts any compile-time numeric constant whose value is a
|
||||
positive integral number. An integral float (`4.0`, or a float-typed const
|
||||
`N : f64 : 4.0`) folds to its integer (`[4.0]s64` ≡ `[4]s64`); a non-integral
|
||||
float (`4.5`) or a negative value is rejected.
|
||||
A **count** is a compile-time integer used as an array dimension, a `Vector`
|
||||
lane count, or a generic value-param count. Every count must be **integral**: an
|
||||
integral float (`4.0`, or a float-typed const `N : f64 : 4.0`) folds to its
|
||||
integer (`[4.0]s64` ≡ `[4]s64`), while a non-integral float (`4.5`) is rejected.
|
||||
The accepted *range* of a count is **context-dependent** — zero is legal for
|
||||
some counts and not others:
|
||||
|
||||
- **Array dimension** — any compile-time integer ≥ 0. `[0]T` is a valid empty
|
||||
(zero-length) array; a negative dimension is rejected ("array dimension must
|
||||
be non-negative").
|
||||
- **Generic value-param count** — bounded by the parameter's declared integer
|
||||
type. Zero is allowed (`Box(0)`, for `Box :: struct($N: u32)`, is a length-0
|
||||
instantiation); a value outside that type's range is rejected (`-1` or
|
||||
`5_000_000_000` for a `u32` param). A negative count is therefore accepted
|
||||
only when the declared type is signed.
|
||||
- **`Vector` lane count** — any compile-time integer ≥ 1 (strictly positive). A
|
||||
zero-lane or negative vector (`Vector(0, f32)`) is rejected ("Vector lane
|
||||
count must be a positive compile-time integer constant").
|
||||
|
||||
A **range bound** — the start/end of an `inline for` or `for` range — is a
|
||||
range *endpoint*, not a count, so the count rules above do not apply. A bound
|
||||
|
||||
Reference in New Issue
Block a user