Design decisions

49. Int stops one above -2^63 (codegen and performance, 2026-11-21)

  • 49.1 Int.MIN is -(2^63 - 1) in the compiler too, and -2^63 is no Int anywhere. The spec settled this (1.1, design/spec/11-types.md); the implementation still had Int.MIN = i64::MIN. Now read rejects -9223372036854775808 in both cpl run and the C++, arithmetic and narrowing (Int(x) from I128/F64, floor/ceil/round, bit_ceil) that would produce it stop with the usual overflow error, and constants folded by codegen agree. This frees the pattern as ?Int's none everywhere. Int.MIN / -1 is Int.MAX, so ediv and emod lose their -1 guards. Reverse: set cpl_ir::INT_MIN back to i64::MIN and drop the != i64::MIN filters; ?Int then needs 16 bytes outside proven tables again.
  • 49.2 Float to Int is exact at the ends in both builds. The interpreter's bound was ±9.2e18, the C++'s ±2^63, so Int(9.21e18) disagreed; both now accept exactly the floats strictly between -2^63 and 2^63, and floor/ceil/round share the check (they cast unchecked in C++, undefined past the range). Reverse: none needed; any bound must be the same in both.
  • 49.3 Bitset words are U64. A word with only bit 63 set is -2^63, which is no Int, and the old helpers built it from Int.MIN. With U64 (wrapping, logical shifts) the helpers for bit 63 disappear. Reverse: none while Int stays symmetric.
  • 49.4 Every ?Int is cpl::OptInt, 8 bytes, with -2^63 as none. With 49.1 the pattern is free everywhere, so locals, fields, arguments, lists, maps and tables all use it; the proof that a table never stores Int.MIN (niche::packed_tables) and the pack/unpack plumbing in codegen are gone. Reason: values take the fewest bytes their types allow, and a layout that depended on a whole-program proof changed with unrelated edits. Reverse: map Ty::Opt(Int) back to std::optional<ll> in names.rs (and restore the table proof to keep tables packed). Cost: the Niche template (about 1 KB) now appears in every program that touches a ?Int, including a passing xs.first; 65 small ports grew more than 5% and the baseline was rewritten. The template was trimmed (unused >, <=, >=, a duplicate constructor); over the corpus the median went 10,345 -> 10,899 B, p95 28,064 -> 27,734 B, max 58,744 -> 58,821 B, none over 64 KB.