Repository navigation
#914: i128/u128 end to end — parse, primitive traits, acceptance - #2399
Conversation
Stages 1-2 of docs/proposals/i128.md already landed (#1922 full-width formatting, D125 exact constants): boundary literals, negated wide literals and checked overflow all verified on main before this change. This lands the remainder. Stage 3: parse_i128/parse_u128 in std.string, written in plain With over checked u128 magnitude arithmetic — string_to_int's exact rule (0 on invalid, digits until non-digit), INT128_MIN spelled without negating 2^127 in width, out-of-range magnitudes panic. First-class traits: i128/u128 were missing from the primitive lists every other width is on, so print(x) for x: i128 failed its Display bound while f"{x}" worked; Clone, Debug, Display, ToString, Eq, Ord and Default now cover both widths. Stage 4 acceptance: boundary literals with >>100 layer discriminators, div/mod sign matrix, format/parse round-trips, overflow and parse-range panic fixtures, literal above-max/below-min error fixtures, and a __int128 c_import round-trip. --dump-abi on fn f(x: i128, y: u128) shows plain COPY params — no ABI special-casing. Stage 6 (the spec SS4.1 primitive-list sentence) is Eric's to bless and is proposed in the PR, not landed here.
|
Battery run 1 at 3b9f841: RED — and it earned its keep. Root cause (CodegenDispatch |
mir_build_saturating_bin_op mangled the intrinsic as llvm.uadd.sat.i64 for every width past 32 and widened an i128 multiply to i128 with 64-bit clamp bounds, so any saturate-mode program touching i128/u128 arithmetic emitted invalid IR (the battery's behav_project_overflow_modes, compiling std's new parse_u128 under overflow=saturate, is what caught it). The intrinsic name now carries the operand width, the multiply widens through wl_int_type_n (i256 for i128), and the clamp bounds come from the width-generic cg_int_* helpers the vector path already uses — one derivation per fact. Fixture: behav_914_i128_saturating_ops exercises the explicit +|/-|/*| operators at both 128-bit boundaries, which share the mode's lowering.
f2dbb4a to
e9eac05
Compare
…d 2026-10-13) (#2401) The compiler implements i128/u128 end to end (#914: exact literals, formatting, parsing, traits, checked arithmetic, c_import __int128), but §4.1 claimed only to i64/u64; the types appeared solely in the reserved-names clause. The list now claims what ships. Wording proposed in #2399 and blessed by Eric verbatim. Co-authored-by: Eric Hartford <[email protected]>
What
The implementation remainder of #914 (plan:
docs/proposals/i128.md). Stages 1–2 already landed — #1922 full-width formatting and D125 exact constants — and I verified on main before this change that boundary literals, negated wide literals (INT128_MIN), the sign/hex specs and checked overflow all behave. This PR lands stages 3–4:parse_i128/parse_u128inlib/std/string.w, plain With over checked u128 magnitude arithmetic —string_to_int's exact rule (0 on invalid, digits until the first non-digit). INT128_MIN is spelled without negating 2^127 in width; a magnitude past the signed range panics by name, past u128 by checked arithmetic.lib/std/traits.w/builtins.w, soprint(x)forx: i128failed its Display bound whilef"{x}"worked. Clone, Debug, Display, ToString, Eq, Ord, Default now cover both widths.>> 100layer discriminators, div/mod sign matrix, format/parse round-trips, add-overflow and parse-overflow panic fixtures, above-max/below-min literal error fixtures, and a__int128c_import round-trip.--dump-abionfn f(x: i128, y: u128) -> i128shows plain COPY params — no ABI special-casing, per the plan's non-goals.Failing-first evidence: with the installed compiler,
parse_i128is an undefined variable andprint(x: i128)fails the Display bound; all eight fixtures pass on this branch's stage1.For Eric's blessing (stage 6, not in this PR)
docs/spec/004_types.md§4.1 lines 5–6 list signed integers toi64and unsigned tou64; i128/u128 appear only in the reserved-names clause (line 27). Proposed exact wording:Say the word and it lands as its own commit; #914 stays open for that sentence after this merges.
Gate and battery results posted when run.