Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork476
Replace all u64/i64 for length, index or offsets into usize/isize#4083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
On platforms that are 32-bits (or 128?) this should make array anditerations faster in general. On platforms that are 64-bits, thiswill have no effect.
codecovbot commentedDec 11, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
jedel1043 commentedDec 12, 2024
Test262 conformance changes
Broken tests (9): |
jedel1043 commentedDec 12, 2024
Hmm, there were some test regressions. Can you investigate them? Maybe it was just a typo somewhere. |
hansl commentedDec 13, 2024
@jedel1043 I don't know how to manually re-run the test262 on this project, so I'll leave that to you as a reviewer. Thanks! |
jedel1043 commentedDec 13, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@hansl tests already ran, it's just on the output of the "Update comment / Write a new comment" steps for the Test262 action. We really need to setup something so that this thing works on external repos 😅 |
jedel1043 commentedDec 13, 2024
Test262 conformance changes
|
jedel1043 left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Looks great!
Approving this, but can you open an issue to add CI tests for a 32-bit architecture? I'd really like to potentially test that just to avoid introducing platform-dependent regressions.
hansl commentedDec 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Scratch that. I won't be able to easily run test262, but I'll run the integration tests and the unit tests tonight and report back. Will also create an issue. |
hansl commentedDec 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
core/engine/src/value/mod.rs Outdated
| pubfnto_length(&self,context:&mutContext) ->JsResult<usize>{ | ||
| // 1. Let len be ? ToInteger(argument). | ||
| // 2. If len ≤ +0, return +0. | ||
| // 3. Return min(len, 2^53 - 1). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
We used to have it beusize, but we changed it because on32-bit systems it does not capture the full range that a JavaScript length can be. (for arrays it's fine to put it asusize since it's between0..2^32-1, but for strings and typed arrays, the upper bound is2^53-1 (max safe representable integer in af64).
Setting it tousize truncates the values on 32-bit platforms giving wrong results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For example, one place thatto_length is used isString.padEnd() on themaxLength parameter, putting2^32-1 would work on 32-bit platform anything greater will be truncated (i.e.2^32 will be truncated to0), on 64-bit platform this would be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
MAX_STRING_LENGTH is 2^32-1.
From the MDN:
The language specification requires strings to have a maximum length of 253 - 1 elements, which is the upper limit for precise integers. However, a string with this length needs 16384TiB of storage, which cannot fit in any reasonable device's memory, so implementations tend to lower the threshold, which allows the string's length to be conveniently stored in a 32-bit integer.
In V8 (used by Chrome and Node), the maximum length is 229 - 24 (~1GiB). On 32-bit systems, the maximum length is 228 - 16 (~512MiB).
In Firefox, the maximum length is 230 - 2 (~2GiB). Before Firefox 65, the maximum length was 228 - 1 (~512MiB).
In Safari, the maximum length is 231 - 1 (~4GiB).
HalidOdatDec 15, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The issue isn't with allocation of the strings, rather that it breaks the math and checks in many places.
EDIT: What I mean is that even if the allocation is limited, the spec still assumes at the length is the full range, and all the math and checks before the final allocation should be able to hold that range.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
That's all fine. If there's a bug with math being broken, then we need to fix it.
I would assume test262 and/or our tests would find any discrepancies, and I'd consider any issue a blocker for this PR. I'm currently running the full test262 suite on a Rasp Pi 2 equivalent. Everything works locally on my aarch64 Mac.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you can provide me with a valid JavaScript snippet that works on other implementations but doesn't work on this PR, I'll be more than happy to add it to tests and fix this PR.
hansl commentedDec 19, 2024
Okay so after running test262 a bunch, and testing in browsers and Deno, I would still like to build this PR the right way but will need to move to a different approach:
This should still result in performance improvements on 32-bits platforms (e.g. in wasm32). I may type the new sizes For now this PR will be back to draft. |

On platforms that are 32-bits (or 128?) this should make array and iterations faster in general. On platforms that are 64-bits, this will have no effect.