59. Digits group with ' or _; min t and max t are an integer type's bounds, folded to literals¶
Date: 2026-11-23
Status: Accepted (Dean, 2026-11-23). Dean asked for both parts, chose the spelling min u8 / max u8, and asked that the bounds follow the target.
Context¶
Dean noticed (2026-11-23) bare bound constants across the library: 4294967295, 9223372036854775808, 65535. They are hard to read and easy to get wrong by one digit, and nothing ties 65535 to u16. lib/Pia/Core/Int.pia alone spells out every bound of u16 to u64 and i16 to i64, several times each, in its saturating contracts. He asked for two things:
- digit separators in number literals, such as
100,000or100'000; - named constants for type bounds, so that code stops using bare numbers. He prefers them as functions of the type,
min u8 = 0, rather than a table of names, and wants them to follow the target.
Two facts constrain the design. Pia has no shadowing at all (ADR 0022), and min and max are already taken: Pia.Core.Order exports min a b and max a b at every width, and Pia.Core.Charconv has a local called max. And a let constant is an unknown value inside a contract (the pia-language skill's pitfalls), so let u16_max : u32 = 65535 would not help the very contracts that need it most.
Decision¶
1. Digits group with ' or _¶
100'000, 0xFFFF'FFFF, 0b1010'0101, 4'294'967'295u64 and 1'000.25 are literals. A ' must sit between two digits of the literal's base, as in C++14, so 100' and 1'_0 are errors. _, which the lexer already accepted, keeps its looser rule, so no code changes. Separators mean nothing to the value: every reader of a literal's text (Sema, IRGen, the metaprogram interpreter, the lints) skips both, through one helper, syntax::isDigitSeparator.
, cannot group digits. It separates tuple elements and arguments, so f (1,000) would be ambiguous. Dean typed a typographic ’ (U+2019), which a phone substitutes for '; Pia's source is ASCII outside strings and comments, so only ' is accepted.
' was free after a digit: inside a name it is a prime (x'), and a name never starts with a digit.
2. min t and max t¶
min t and max t are the least and greatest values of the integer type t: min u8 = 0, max u16 = 65535, min i64 = -9223372036854775808, max byte for let byte = u8, and the bounds of a range type named by a let.
- They overload
minandmaxby argument. A call ofminormaxwith one argument that names an integer type is a bound. Every other call, such asOrder.max a b, resolves as before. Neither name is reserved, soPia.Core.Orderkeeps its functions and Charconv's localmaxstays; where a localmaxis in scope,max u8is that local applied tou8, which is an error, as shadowing would have been. - They fold to literals. IRGen replaces
max u16with the literal65535before overload resolution, so it takes its context's type like any literal, and works in contracts, where aletconstant would be unknown.ensures a * b > max u16 ==> result = max u16reads as the number did and proves the same way, with no cost. - They follow the target. Each bound comes from the type as Sema resolves it, so
max usizeandmin isizeare the bounds of the target'susize(ADR 0049). Both of Pia's models have 64-bit pointers today, andpiacrefuses a model with other pointers untilusizefollows the model'sptr_bits; when it does,max usizefollows with it, and code that wrotemax usizeinstead of18446744073709551615is already right. - Metaprograms. Dean's
min u8 = 0is the reading of a type-level function. In ordinary code the fold is done by IRGen, since an ordinary expression has no metaprogram calls. Inside a metaprogram,range_of t(ADR 0056) already gives[lo; hi].
Not yet: max t for a generic body's type parameter t. A generic body is checked once, against a stand-in type (ADR 0043), whose bounds are not known. This is the numeric_limits gap that Pia.Core.Int documents. It needs a concept that promises bounds, and is left for a later ADR.
Alternatives¶
- Named constants in a module,
Limits.u32_max: a name per type and bound, and aletconstant is unknown in contracts unless it becomes a spec function. Rejected. - Members of the type,
u32.max: reads well, but.after a type name is new syntax, and types as values have no fields today. - Other names,
lowest/highestormin_of/max_of: no overloading, but Dean chosemin/max.
Consequences¶
- The library's bare bounds become
min tandmax t, starting withPia.Core.Int,Order,BitandImage. docs/grammar.mddocuments the separators,docs/irgen.mdthe bounds, and the pia-language skill both. The VS Code grammar and the reference lexer ingrammar/pia_lexer.pyaccept'.- Tests:
tests/grammar(valid and invalid separators, shared by both lexers),tests/verify/digit_separators.piaandtests/verify/type_bounds.pia.