Skip to content

ADR 0075: An int wider than 64 bits

Status: Final Type: Feature Created: 2026-11-07 Amends: 0002 (its 64-bit int, which A152 kept, asking for the two measurements below before any wider option was chosen), 0005 (int(s) and pow(x, y, mod) past 64 bits), 0007 (OverflowError where CPython raises it on a big int), 0020 (the int that int ** int gives grows), 0062 (<< grows as * does) Amended-By: 0077 (a list[int] element is bounded by the range every one of them is in) Related-ADRs: 0024 and 0026 (the counted values a big int joins), 0053 (the proofs that elide a check). Provenance: A189, A191, A193.

Context

CPython's int has no width. postpile's was 64 bits: an operation that left them stopped a debug build with an overflow error and wrapped in a release build (ADR 0002). A152 kept that, and named what would reopen it: the number of programs that compile and then overflow, and the cost of an overflow check in release. Both were measured on 2026-11-07 (notes/measurements.md).

The programs. All 28 of the census's programs compile, and three of them pass 64 bits under CPython. In sudoku1, a dict key is a running hashcode * 17 + hash(tuple(row)) that reaches 95 bits. genetic computes 1 << 160 and divides a float by it. tonyjpegdecoder's bit buffer GetBuff << 8 | byte is never cleared within a scan and grows past a hundred thousand bits, so a big int that is never freed would allocate gigabytes over a run. Release printed CPython's output for tonyjpegdecoder (only the low bits are read) and for sudoku1 (the dict only compares the keys), and genetic's wrapped shift was 0, which it divides by. None of p2w's compiling programs passes 64 bits.

The cost. Emitting debug's overflow check in release slows ADR 0067's thirteen programs by nearly half on the C backend and more on LLVM, by geometric mean. The cost sits in five programs (life, spectral_norm, sieve, levenshtein, matmul), where the check stops the C compiler from folding or vectorising the index arithmetic; the other eight barely move. Testing both operands of every +, -, * and comparison for a big value adds more. The ownership of a big value is a third cost on top. That figure was the check as then lowered, a division per product and no range proof in release; asked of the backend's overflow flag and after the proofs, the check costs 1.05× (C) to 1.14× (LLVM), and release keeps it (0002, A194).

Decision

int behaves as CPython's does, in a debug build and a release build alike: it grows past 64 bits. The fixed-width types Int8 to Int64 and UInt8 to UInt64 behave as machine integers of their width, which is how a program asks for a machine word. The work starts with the proofs that make the growing int affordable.

The constraint is ADR 0002's: a failed check aborts and cannot be caught, so a debug run that finishes printed exactly what a release build of the same program prints. Debug's checks only remove runs and never change one. That lets a debug run (the census's, a test suite's) vouch for the release build. An int that grew in debug only would break that guarantee: a program whose ints pass 64 bits would print CPython's values in a debug build and wrapped ones in a release build. The debug run that passed would say nothing about it. Every difference between the modes stays of the kind "debug stops where release continues".

  1. Range proofs first, in both modes. A user-level +, -, * or << with operands proven bounded needs no overflow check and no test for a big operand. The bounds come from literals and module constants, range() counters, len(), a counter stepped by a bounded amount inside range loops, and, in an executable, a parameter bounded by every direct call that reaches it. A value of a fixed-width type is unbounded for the proof, since it wraps. The analysis is 0053's, which already discharges bounds checks on those shapes. Debug gets faster from this alone.
  2. The big-int runtime is one C unit under the runtime-helper pattern: magnitude in 32-bit limbs and a sign; + - * // % divmod ** << >> & | ^ ~, pow with a modulus, negation, abs, comparisons (with an int and a float compared exactly, as CPython does), CPython's hash (the magnitude modulo 2**61 - 1), str, repr, bin, oct, hex, format's integer presentations, int(s), int(d), float(n) correctly rounded (OverflowError past a double), and an int's true division, correctly rounded whatever the operands' size. CPython's limit on a decimal conversion, 4300 digits, raises CPython's ValueError. The runtime's correctness is held to CPython by differentials, with operands drawn across the limb boundaries.
  3. The representation. An int is a 64-bit word that holds either the value or a reference to a counted big int. A word whose value lies in a reserved band at the bottom of the range, [-2**63, -2**63 + 2**48), is a reference; every other word is its own value, so a small int has the same bits in a list, a field, a dict key or an argument as it had before. A value that falls in the band is held as a big int, so a value has exactly one form, and two words are equal ints exactly when they are equal words or both are references to equal big ints. A value that enters an int from a machine source (an Int64, a hash, a literal, a C helper whose answer can be any 64-bit value) is put in that form where it enters.
  4. The fast path is the operation on the words with the overflow check, plus a test that neither operand is a reference, both omitted where step 1 proved them unneeded. The slow path, taken on a reference or on an overflow, calls the big-int runtime, which returns a word: the value when it fits outside the band, a new reference otherwise. A consumer of an int that does not handle a reference gets a guard before it, unless the word is known small: the guard answers the machine integer when the value fits in 64 bits and otherwise stops the program, naming what was too large. A site not yet taught about big values therefore aborts instead of computing a wrong value.
  5. Ownership follows 0026's model for a str, applied only when the word is a reference: a store retains, an overwrite and the end of a local's life release, a list, a dict, a set or an instance releases its int members when it is freed. A temporary is released where its statement ends, on every exit from it, as CPython drops it; a word read from a container is held until its statement ends wherever code could run between the read and the use. A list[int] holds counted words and a list[Int64] machine words. The leak counters count big ints like any other counted value.
  6. Release's int stops wrapping. ADR 0002's "wraps at the declared width" row no longer applies to int; release IR changes. The cross benchmark's gate is re-baselined, with the cost recorded in the speed index as distance from C. The fixed-width types keep their width and wrap in both modes, as 0002 has them. Their arithmetic is defined by the spec. Under the interpreter an Int64-annotated value is a plain int that never wraps; postpile does not follow it there, since CPython does not implement these types. Their differentials compare against CPython's value reduced to the declared width by the test, so no golden value is written by hand.
  7. Where CPython holds an int in a C integer (A191), the compiled program does what CPython does with a value past it, in both modes: it raises CPython's exception with CPython's message (an index, pop, insert, a repetition count, bytes(n), a to_bytes length, a padding width, str.replace's count, chr), or computes CPython's value (a slice or search bound, clamped; a union box, to_bytes, random, sys.exit, three-argument pow, which take the big value itself). The guard pass stops the program where a consumer is not taught yet, saying so, and each such stop is distance. A big int passed across the FFI boundary to a function that takes a machine integer is refused, as CPython's OverflowError would be. A range whose bounds come within the band would step a machine counter through reference words, so it stops at the loop with a message.
  8. The spec. POST §4.1.1 makes int a 64-bit integer, and the spec's table of Python types maps int to Int64. The amendment asked of the spec has three parts: the table stops mapping int to Int64; int is CPython's unbounded integer; a program asks for a machine word through the fixed-width types. It is U51 in the questions for the POST spec (notes/decisions/upstream-questions.md).

int and Int64 are two types. The annotation Int64 (and Int) is a machine integer, as Int32 is; int is CPython's. int converts to Int64 only through a cast (the owner's ruling, "explicit is better than implicit"): x: Int64 = n, -> Int64: return len(xs) and an int argument to an Int64 parameter are PP410, as they are for Int32, while a literal takes the declared type and Int64 widens to int without one. Int64 + int is an int, and list[int] and list[Int64] are different types. Int64 is refused as a union case and a channel element, as Int32 is: a union case needs a tag of its own, and int is the type to use there.

Growth belongs to an executable. An executable's int grows unless the build says --no-grow-ints (owner, 2026-11-10). A library and an extension module keep the 64-bit int: a big value is a reference in an int word, which a caller built without growth would read as a number. All of a program's modules are compiled with growth or all without. Where the int is 64 bits, a constant the compiler folds that it cannot hold is a compile error at its line (A193). Growth was first landed behind an option that was off by default and meant the same in both modes, so no partial landing ever had a debug build computing what a release build did not.

Consequences

  • sudoku1, genetic and tonyjpegdecoder compute CPython's values in debug and release builds. tonyjpegdecoder's buffer is freed as it is replaced, as CPython's is.
  • No executable wraps an int silently. A finished debug run still vouches for the release build.
  • Int-heavy code pays for the checks the proofs cannot discharge, in both modes, and for ownership; the cost is recorded in the speed index. It sits in a few programs that sum list elements or count in while loops, which no proof bounds yet. Further proofs that keep such an int in a register are the work left.
  • Code comments cite the steps the work was built in, which differ from the numbered decisions above: step 1 the range proofs, step 2 the big-int runtime, step 3 Int64 as a type of its own, step 4 the word with its fast path, guards and ownership, step 6 growth on by default. Step 5, the proofs that keep an int in a register: a counter a while caps (while i < n, while i * i < n, every update that moves it a rise in that loop's body), and the range of every list[int] element (0077), built on 2026-11-14; a store that grows an element on every pass, as levenshtein's do, has no proof, and the run-length assumption that would give one was declined.
  • The frontend, the list, dict and object runtimes and the leak counters each know about a reference in an int word. Where the ints are proven bounded, code emits what it emitted before.
  • A growing temporary costs QBE more moves per block edge; the bundled QBE is built with a higher cap (A165's amendment).

Alternatives considered

  • Grow in debug only, release unchanged (this ADR's first draft). Cheapest, since debug already pays for the checks. Rejected because a debug build would then compute values a release build does not, so a debug run would stop vouching for release.
  • Check overflow in release too, and stop (A152's first move). Keeps one meaning in both modes and removes the silent wrap, but gains no program: the three stop in every build. It was the fallback had the big-int runtime not been built.
  • An opt-in wide type (A152's third move): asks for an annotation no type checker requires. This decision takes the opposite default: the annotation, Int64, is asked of a program that wants a machine word, and plain int stays CPython's.
  • Keep A152's status quo. Debug traps and release wraps, which keeps the vouching guarantee; three of 28 census programs stop in debug; in release, sudoku1 and tonyjpegdecoder print CPython's output only because no wrapped value reaches it, and genetic divides by zero.