Repository navigation
fix(format): the base-conversion chunk is bounded by bigint's limb base, tested by division - #230
Merged
Merged
Conversation
…se, tested by division %py-fmt-chunk-of looked for the largest base^k under 10^9 by multiplying until the product reached it. On a 4-byte word 16^8 is 2^32, which multiplies to zero, and a zero never reaches a bound: loading the bundle allocated until the machine refused, which is why no state image and no Python ran on 32-bit arm (4.19 GB on a Raspberry Pi 4, then exit 2). The bound is bigint's own limb base, sized to the word (10^9 on an 8-byte word, 10^4 on a 4-byte one), so a chunk stays inside one limb on either, and it is tested by division, which cannot wrap. On 64-bit the chunks are what they were; on the Pi the load now peaks at 1.07 GB. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Importing bigint at the top of format.x moved it ahead of the compile ladder and python's tokenizer registrations, and on a 4-byte word that order left every integer literal reading as a symbol while bigint.x itself loaded. bigint-base is runtime-num.x's import into this module, bound by the time a program formats and not before; the three chunks are made then, and nothing about the load moves. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
%py-fmt-chunk-offound the largest base^k under 10^9 by multiplying until the product reached it. On a 4-byte word 16^8 is 2^32, which multiplies to zero, and a zero never reaches a bound: loading the bundle allocated until the machine refused. That is why no state image and no Python ran on 32-bit arm (jonruttan/x-os#85's armv7 leg; 4.19 GB on a Raspberry Pi 4, then exit 2).The bound is now bigint's own limb base,
bigint-base, sized to the word (10^9 on an 8-byte word, 10^4 on a 4-byte one), so a chunk stays inside one limb on either; and it is tested by division, which cannot wrap. On 64-bit the chunks are what they were.The chunks are made at first use, not when
format.xloads.bigint-basereachespython/corethroughruntime-num.x, which loads afterformat.x; a top-level import ofx/num/bigintfromformat.xchanged the load order and broke integer reading on the Pi.Verified
31-formatand58-floordiv-bigints, 21 tests, 0 failed.format.xand died before. Python boots from source:print(1+1)prints 2, andhex(2**70),oct(2**70)print0x400000000000000000 0o200000000000000000000000.%py-f-exact,python-ieee-raw) read the payload as one integer, but on a 4-byte word it is two words. 13 of the 21 cases fail withno < for VECTORfor that, and one58-floordiv-bigintsbatch segfaults.🤖 Generated with Claude Code