You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
i128/u128 end to end: wide literals, formatting, boundary tests, spec §4.1 #914
Make i128/u128 first-class end to end. Plan of record: docs/i128.md — summary below.
Correction from the first filing
The original body claimed wide literals silently wrap. False — deeper probing (>> 100 discriminators, which bypass the print path) shows the wide-constant pipeline is complete and correct end to end: exact digit storage in the AST (set_int_literal_exact), CK_INT_EXACT MIR consts, wl_const_int_words(lo, hi, 2) codegen. let x: i128 = <i128 max> printing -1 was the FORMATTING defect masquerading as a literal wrap (max mod 2^64 read as i64 is -1). The too-big diagnostic also already fires correctly for 2^128.
The two real defects (verified)
Formatting truncates to 64 bits. Values are correct in the register; std.fmt bottoms out in with_fmt_i64 and the f-string fmt_to_str dispatch has no width-128 arm. f"{i128max}" prints -1, f"{2^100}" prints 0.
Negated wide literals lose the expected-type context.let neg: i128 = -<literal above i64 range> errors "does not fit default type (expected_ty=0)" despite the annotation — the unary-minus path checks against the default type. Consequence: INT128_MIN and every negative literal of magnitude > i64 max are unspellable.
Campaign (details in docs/i128.md)
D2: thread the expected type through NK_UNARY(NEGATE, NK_INT_LIT); INT128_MIN special case
D1: with_fmt_i128/with_fmt_u128 runtime renderers + width-128 dispatch arm
changed the title [-]Complete i128/u128: literals beyond 64 bits silently wrap, formatting truncates to 64 bits[/-][+]i128/u128 end to end: wide literals, formatting, boundary tests, spec §4.1[/+]on Aug 31, 2026
i64::MIN could not be written anywhere in the language before this —
not just in wide-literal contexts:
var b: i64 = -9223372036854775808
error: integer literal does not fit default type ('9223372036854775808', suffix_ty=0, expected_ty=0)
It needed five pieces, not one
The plan scopes D2 at ½–1 day for a UOP_NEGATE arm in check_unary. That arm
is necessary but not sufficient — every consumer of a negated literal had
independently re-derived the interpretation, and each got it wrong the same way,
by narrowing the operand before measuring it.
int_literal_fits_type_negated — magnitude-aware range check via exact_int_fits_signed_negative_bits
SemaCheck.w
the UOP_NEGATE arm, threading a signed integer expectation
SemaCheck.w
the NK_INT_LIT suffix branch consulting the negation context
MirLower.w
try_eval_const folds the whole negation
MirLower.w
lower_un_op emits CK_INT_EXACT instead of a runtime RK_UN_OP
The plan's guidance to call int_literal_expr_bits on the unary node is
correct and is what all of these use.
The trap worth recording
The sema fix alone is a regression, not a fix. With sema rejecting the
expression, lowering never saw it; once accepted, lower_un_op emitted a
runtime negate that trapped on exactly the value the source asked for:
var a: i32 = -2147483648i32
panic: integer overflow: negating i32 minimum value
A clean compile error became a crash. Anyone cherry-picking the check_unary
arm without the MirLower half will ship that. CK_INT_EXACT was already the
right vehicle — codegen resolves it through int_literal_expr_bits, which keeps
magnitude and sign apart until the width applies and already handles both words
for the 128-bit case.
The guarded regression the plan names — -1 in an unsigned context must still
say cannot negate an unsigned value — holds. Two guards: check_unary threads
only signed expectations, and int_literal_fits_type_negated defers to the
ordinary check for unsigned types.
Gates
:fixpoint FIXPOINT (stage2 byte-identical to stage3, with the compiler's own
negated literals routed through the new path) and the full suite green, every
target re-run rather than cached — 977 behavior, 749 compile-error, 210 spec,
51 phase, 16 codegen, 6 comptime-diff, 14 internals, 7 lexer, 9 parser.
The 749 compile-error fixtures pin diagnostics and none moved: the
negation-aware path is additive, accepting what was wrongly rejected without
loosening anything that should still be rejected.
Two notes for the rest of the campaign
D4 needs re-reading. See #943. The evaluator is not "i64-only" — it did
arithmetic at 32 bits, and separately cannot represent anything above 64
bits at all: ComptimeEval.w keeps exact.lo and discards exact.hi, so 18446744073709551616 + 1 folds to 1. The 32-bit half is fixed on issue943; the ceiling is not, and it is exactly the data0 widening D4
contemplates. The proposed "refuse 128-bit operands" mitigation would not have
fired, since the evaluator's own width for those expressions was 32.
S2's Overflow.w work has a free rider. All six arithmetic helpers truncate
their operands before the overflow check, so an out-of-range operand is
silently normalized rather than diagnosed — that ordering is what made the #943
corruption silent. Fixing it standalone is poor value now that widths resolve
correctly (it changes no observable behavior), but S2 opens Overflow.w anyway
for the word-pair helpers, and the reordering is nearly free while the file is
in play. Detail in plans/comptime-int-width.md → "S1 reassessed".
Investigated and drafted jointly by @migueldecimal128 and Claude (Claude Code).
Activity
[-]Complete i128/u128: literals beyond 64 bits silently wrap, formatting truncates to 64 bits[/-][+]i128/u128 end to end: wide literals, formatting, boundary tests, spec §4.1[/+]docs: i128/u128 end-to-end implementation plan (#914)
#943: evaluate negated integer literals against the target width
#914 D2: make signed MIN spellable — negated literals measured as mag…
#943: assert comptime integer payloads are canonical in their own type
migueldecimal128 commentedon Sep 4, 2026
D2 is done
Fixed on branch
issue943, commitff201949. Signed MIN is now spellable insuffixed form at every width, at runtime and at comptime:
i64::MINcould not be written anywhere in the language before this —not just in wide-literal contexts:
It needed five pieces, not one
The plan scopes D2 at ½–1 day for a
UOP_NEGATEarm incheck_unary. That armis necessary but not sufficient — every consumer of a negated literal had
independently re-derived the interpretation, and each got it wrong the same way,
by narrowing the operand before measuring it.
Sema.win_negated_literal_context, mirroringin_bitwise_literal_contextSema.wint_literal_fits_type_negated— magnitude-aware range check viaexact_int_fits_signed_negative_bitsSemaCheck.wUOP_NEGATEarm, threading a signed integer expectationSemaCheck.wNK_INT_LITsuffix branch consulting the negation contextMirLower.wtry_eval_constfolds the whole negationMirLower.wlower_un_opemitsCK_INT_EXACTinstead of a runtimeRK_UN_OPThe plan's guidance to call
int_literal_expr_bitson the unary node iscorrect and is what all of these use.
The trap worth recording
The sema fix alone is a regression, not a fix. With sema rejecting the
expression, lowering never saw it; once accepted,
lower_un_opemitted aruntime negate that trapped on exactly the value the source asked for:
A clean compile error became a crash. Anyone cherry-picking the
check_unaryarm without the
MirLowerhalf will ship that.CK_INT_EXACTwas already theright vehicle — codegen resolves it through
int_literal_expr_bits, which keepsmagnitude and sign apart until the width applies and already handles both words
for the 128-bit case.
The guarded regression the plan names —
-1in an unsigned context must stillsay
cannot negate an unsigned value— holds. Two guards:check_unarythreadsonly signed expectations, and
int_literal_fits_type_negateddefers to theordinary check for unsigned types.
Gates
:fixpointFIXPOINT (stage2 byte-identical to stage3, with the compiler's ownnegated literals routed through the new path) and the full suite green, every
target re-run rather than cached — 977 behavior, 749 compile-error, 210 spec,
51 phase, 16 codegen, 6 comptime-diff, 14 internals, 7 lexer, 9 parser.
The 749 compile-error fixtures pin diagnostics and none moved: the
negation-aware path is additive, accepting what was wrongly rejected without
loosening anything that should still be rejected.
Two notes for the rest of the campaign
D4 needs re-reading. See #943. The evaluator is not "i64-only" — it did
arithmetic at 32 bits, and separately cannot represent anything above 64
bits at all:
ComptimeEval.wkeepsexact.loand discardsexact.hi, so18446744073709551616 + 1folds to1. The 32-bit half is fixed onissue943; the ceiling is not, and it is exactly thedata0widening D4contemplates. The proposed "refuse 128-bit operands" mitigation would not have
fired, since the evaluator's own width for those expressions was 32.
S2's
Overflow.wwork has a free rider. All six arithmetic helpers truncatetheir operands before the overflow check, so an out-of-range operand is
silently normalized rather than diagnosed — that ordering is what made the #943
corruption silent. Fixing it standalone is poor value now that widths resolve
correctly (it changes no observable behavior), but S2 opens
Overflow.wanywayfor the word-pair helpers, and the reordering is nearly free while the file is
in play. Detail in
plans/comptime-int-width.md→ "S1 reassessed".Investigated and drafted jointly by @migueldecimal128 and Claude (Claude Code).
#943: evaluate negated integer literals against the target width
#914 D2: make signed MIN spellable — negated literals measured as mag…
#943: assert comptime integer payloads are canonical in their own type
#914: i128/u128 end to end — parse, primitive traits, acceptance (#2399)
spec §4.1: the primitive integer lists run to i128/u128 (Eric, blesse…