You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fieldless enums should infer an integer backing (auto-increment discriminants, as i32) instead of requiring : i32: #309
A fieldless enum written without an explicit : i32: backing should behave the same as one with it — the integer backing should be inferred, discriminants should auto-increment from the last explicit value, and as i32 should yield the discriminant. Today the backing-less form is a second-class citizen: explicit discriminants are rejected at parse time, as i32 fails codegen, and (worst) an older compiler silently miscompiles the form.
lib/std/cfg/stackify.w was edited to drop : i32: from StackifyTermKind/StackifyNodeKind/etc. while keeping Br = 0-style discriminants. The v0.14.5 seed accepted this and produced a corrupted stage1 (it then emitted nonsense expected declaration parse errors at unrelated lines of out/gen/main.w), rather than failing loudly. The current compiler errors loudly on the parse form (item 1), which is better, but the form should work, not just fail loudly.
Acceptance
A fieldless enum infers an integer backing; Foo = N then bare variants auto-increment (N+1, N+2, …).
EnumVal as i32 yields the discriminant for any fieldless enum, backed or not.
No syntax accepted by one compiler version may silently miscompile in another — reject loudly or compile correctly.
Regression: enum K: A=0 B C + K.B as i32 == 1, K.C as i32 == 2.
Env: with at origin/main, darwin-aarch64. (Note: : i32: alone does not confer Copy; that is a separate axis via impl Copy.)
Fieldless enums now infer an i32 backing: explicit discriminants, auto-increment from the last explicit value, and as i32 all work without writing : i32:. Enums with payloads stay ADTs (unchanged). The bare-enum variant parser collects optional = value discriminants, detects fieldlessness, synthesizes an i32 backing node, and emits the disc-enum format — reusing all existing Sema/codegen.
Verified on current main:
enum Term: Br = 0 CondBr Select Return // Br=0, CondBr=1, Select=2, Return=3
enum Gap: A = 5 B C = 10 D // 5, 6, 10, 11
Note: the frozen v0.14.5 seed still silently miscompiles the form, but the current/next compiler compiles it correctly, so once the seed is updated the silent-miscompile path is gone. The StackifyTermKind/etc. enums in lib/std/cfg/stackify.w can now drop their : i32: backing.
Activity
ehartford commentedon May 30, 2026
Fixed in commit b4e944f.
Fieldless enums now infer an i32 backing: explicit discriminants, auto-increment from the last explicit value, and
as i32all work without writing: i32:. Enums with payloads stay ADTs (unchanged). The bare-enum variant parser collects optional= valuediscriminants, detects fieldlessness, synthesizes ani32backing node, and emits the disc-enum format — reusing all existing Sema/codegen.Verified on current main:
build + fixpoint + 111 spec / 557 behavior / 16 phase tests + EMIT-C green; regression in
test/spec/spec_ss04_4_fieldless_enum_inference.w.Note: the frozen v0.14.5 seed still silently miscompiles the form, but the current/next compiler compiles it correctly, so once the seed is updated the silent-miscompile path is gone. The
StackifyTermKind/etc. enums inlib/std/cfg/stackify.wcan now drop their: i32:backing.Infer an i32 backing for fieldless enums (#309)
Infer an i32 backing for fieldless enums (#309)
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Parser: an explicit `= N` makes a backing-less payload enum a discrim…
Enums: payload discriminants, casts, generic layouts, and fn-type com…