0020. Records are value structs with a lookahead literal rule
- Status: Accepted; cycle rule amended by 0270
- Date: 2026-10-30
- Plan: M4.1
- Review: Language semantics
Context
The first user-defined types need familiar syntax and predictable immutable semantics, while preserving existing block parsing and both execution backends.
Decision
Declare struct Point { x: i64, y: i64 }, with at
least one uniquely named field. Construct
Point { x: 1, y: 2 }: every field exactly once, any
written order, evaluated left to right in that order. Read
p.x; assignment to a field is E0406, with help
pointing to M4.2's shallow with update.
Ident { is a literal only when the following
tokens, skipping newlines, are Ident :. There is no
context flag. A name-colon pair cannot start a statement, so
if p == Point { x: 1 } { … } is unambiguous.
Records are nominal values, copied independently on assignment or calls. Type declarations may appear in any source order; their namespace includes builtins and is separate from functions and locals. Fields accept every implemented value type. Reject direct and indirect by-value cycles with E0410, showing the first DFS cycle in source order. Dependencies include declarations nested anywhere in type arguments; typed IDs represent links.
Every value type supports structural equality: record fields in
declaration order, strings by bytes including NUL. Only i64, bool
and str print; other types get E0309 with field-printing help
(unit retains its existing fix). C uses flat structs and
structural equality helpers (ADR-0023). Interpreter records share
immutable Rc<[Value]> storage with Clone
handles; overwriting a local never mutates another value and
releases obsolete storage.
Alternatives considered
- Rust-style no-struct-in-condition flag — unnecessary context-sensitive parsing when name-colon lookahead distinguishes literals from blocks.
recordkeyword —structtransfers from familiar languages.- Observable shared-pointer records — aliasing would violate value semantics; internal Rc storage is immutable and unobservable.
- Recursive by-value layouts — unbounded sizes; use tables and typed IDs.
Consequences
Field order must survive formatting and lowering even when layout order differs. Layouts are finite and definition-before-use. Large by-value copies remain until M5.6 destination passing; no allocation or representation optimization is introduced without measurements.