0044. Integer types, literals and explicit bit methods
- Status: Accepted
- Date: 2026-10-30
- Plan: M5.3, M5.7
- Review: Language semantics; Data, schemas and wire formats
Context
Byte sequences and wire formats need explicit widths, but i64
arithmetic and the interpreter's deterministic checked semantics
must remain the default. Nested generic types also make
>> ambiguous with closing type arguments.
Decision
Lane B owns u8 (M5.3b), u32,
u64 and i32 (M5.7), alongside
i64. Its foundational commit integrates the shared
frontend/IR/backend contract for all widths and methods
atomically; a separate test commit supplies generated runtime
boundary and backend parity matrices. This adjusts the original
three-feature-commit sequence, not the language design or other
lanes' scope. Decimal and 0x hexadecimal literals
have no suffix. Lex magnitudes through u64; larger literals get
E0003. A literal uses its expected integer type, or the other
operand's type for a bare literal (including -lit and
literal-only arithmetic such as 1 + 2, on either
side), defaulting to i64; failure to fit is E0312. Type-checking
order does not change left-to-right evaluation.
Values of different integer types do not implicitly convert.
u8(x) and the other integer type names convert one
integer with a range check; overflow traps at the type name.
wrapping_u8() and corresponding methods truncate.
Reserve the type names and conversion function names, while
allowing locals with those names. Unary minus on unsigned values
is E0313.
Arithmetic checks overflow per type; division truncates toward
zero and signed minimum remainder -1 is zero, as in ADR-0012.
Explicit wrapping_add, wrapping_sub,
wrapping_mul and wrapping_neg wrap. Bit
operations are methods bit_and, bit_or,
bit_xor, bit_not, shl,
shr, rotl and rotr. Binary
bit operands match the receiver type; shift and rotate counts are
i64 in 0..bits, otherwise trap
shift out of range at the method name; signed right
shift is arithmetic. Builtin methods take precedence over
interface methods, which remain available via qualification.
Alternatives considered
- Literal suffixes — add syntax and a second way to specify a type when annotations and expected types already provide context.
ascasts — introduce another conversion syntax and obscure the default checked behavior compared with a type-named conversion.- Bitwise and shift operators —
>>conflicts with nested generic closers; named methods also preserve the existing lone&and|diagnostics.
Consequences
This extends ADR-0012's trap kinds with
shift out of range; existing i64 arithmetic semantics
remain intact. Both backends must agree on boundaries, traps,
conversion and bit semantics without relying on C undefined
behavior. The former i64 lexical overflow diagnostic becomes E0312
during type checking.