-
-
Notifications
You must be signed in to change notification settings - Fork 159
fix(typedarray): dispatch, not drop, when a Uint8Array-specialized element helper's receiver is not one #8120
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| ### Fixed | ||
|
|
||
| - **Reassigning a `Uint8Array` binding dropped element writes and read | ||
| `undefined` (#8111).** The `Uint8Array`-specialized twin of #8100. | ||
| `js_uint8array_get`, `js_uint8array_index_get_value` and `js_uint8array_set` | ||
| (`typedarray/access.rs`) are a SEPARATE emission path from the two helpers | ||
| #8109 fixed: codegen picks them from `is_uint8array_receiver` | ||
| (`perry-codegen/src/expr/index_{get,set}.rs`), which reads | ||
| `receiver_class_name` rather than the `local_type_hint` predicate #8100 is | ||
| about — but it fires for a reassigned `Uint8Array` local just the same. | ||
|
|
||
| Each had a three-way shape (registered typed array of the right kind / | ||
| registered buffer / fall off the end) and TWO of those arms answered for a | ||
| receiver that is perfectly readable: the trailing arm (a plain array, object | ||
| or string) and the wrong-KIND arm (a registered typed array that is not | ||
| `Uint8Array` / `Uint8ClampedArray`). Reads answered `0` / `undefined`; the | ||
| store was dropped with no trace at all. Unlike #8100 these helpers were | ||
| memory-SAFE — they validated before dereferencing — they just answered | ||
| wrongly, silently, in the shipped default configuration. | ||
|
|
||
| Measured against the pinned node oracle (`v26.5.1`, `.node-version`), both | ||
| arms exit 0: | ||
|
|
||
| ``` | ||
| node perry before | ||
| store: [5,10] [9,10] <- write DROPPED | ||
| dyn: 10 undefined | ||
| read: 5 10 2 10 undefined undefined 2 10 | ||
| obj store+read: 42 8 undefined undefined | ||
| string read: h i undefined undefined | ||
| wrong-kind: 77 12 2 undefined undefined 2 | ||
| ``` | ||
|
|
||
| Correct in BOTH arms: a real `Uint8Array` (`3 250 2`), a `Buffer` | ||
| (`200 2`), a plain array (`5 10`), a plain object (`5 10`), a | ||
| `Uint8ClampedArray` (`255 2`). `Q.length` and `Q.at(1)` were already right, so | ||
| the binding really did hold the plain array — only the specialized element | ||
| accessors were wrong. | ||
|
|
||
| The read arms now delegate to `js_typed_array_get`, which owns #8109's | ||
| `classify_element_read_receiver` dispatch, so this path INHERITS it rather | ||
| than growing a third classifier — including the property that a | ||
| `GC_TYPE_TYPED_ARRAY` / `GC_TYPE_NATIVE_TYPED_VIEW` header still wins on a | ||
| registry miss, so a lookup failure can cost the diversion but never the | ||
| element read. The store arm asks the same classifier directly, because | ||
| `js_dyn_index_set` has its own return-value contract and the value arrives as | ||
| an `i32`. `js_uint8array_get`'s ABI is a byte-typed `i32`, so a recovered | ||
| value there goes through `ToNumber` rather than having its NaN-box bits | ||
| reinterpreted, and `undefined` still collapses to the `0` byte sentinel | ||
| (#6088). | ||
|
|
||
| The wrong-KIND arms are REMOVED rather than kept as the issue suggested: | ||
| `js_typed_array_{get,set}` are kind-generic (they read `(*ta).kind`), node | ||
| reads and writes the real element there, and `js_typed_array_set` even | ||
| performs the spec's `ToBigInt` `TypeError` for a Number written into a bigint | ||
| view. `Uint8Array` / `Uint8ClampedArray` behaviour is unchanged and pinned by | ||
| two control tests (`300 -> 44` wrapping, `300 -> 255` clamping). | ||
|
|
||
| RESIDUAL, documented in-code and not introduced here: codegen narrows | ||
| `js_uint8array_set`'s value to `i32` at the call site (`fptosi`, | ||
| `perry-codegen/src/expr/arrays_finds.rs`) because the DECLARED receiver is a | ||
| byte view, so a fractional value written through a reassigned binding arrives | ||
| already truncated — `Q[0] = 1.5` stores `1` where node stores `1.5`. Closing | ||
| that needs an f64-valued entry point plus a codegen change, not a | ||
| runtime-side dispatch. Every integer store is exact. | ||
|
|
||
| Validation: the issue's probe is byte-identical to node post-fix. 7 unit tests | ||
| in `crates/perry-runtime/src/typedarray/element_read_receiver_tests.rs`, each | ||
| asserting the recovered VALUE rather than "did not panic"; | ||
| sabotage-verified after a real rebuild — reverting `access.rs` turns 4 of them | ||
| red, and the 3 that stay green are the intended controls. | ||
| `cargo test -p perry-runtime --lib`: 2380 passed / 0 failed / 4 ignored | ||
| (`main`: 2361 / 0 / 4). `perry-codegen`: 1434 passed / 11 failed, identical to | ||
| the `main` baseline (#8092). |
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
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
Oops, something went wrong.
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.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the canonical heap-address predicate.
These helpers duplicate a partial address-floor check. Use
crate::value::addr_class::is_plausible_heap_addrfor receiver routing so all helpers apply the runtime handle-band and heap-address rules consistently.crates/perry-runtime/src/typedarray/access.rs#L579-L580: replaceaddr < 0x1000.crates/perry-runtime/src/typedarray/access.rs#L631-L632: replaceaddr < 0x1000.crates/perry-runtime/src/typedarray/access.rs#L664-L665: replaceaddr < 0x1000.Based on learnings, receiver classification must use
crate::value::addr_class::is_plausible_heap_addrinstead of lower-level address checks.📍 Affects 1 file
crates/perry-runtime/src/typedarray/access.rs#L579-L580(this comment)crates/perry-runtime/src/typedarray/access.rs#L631-L632crates/perry-runtime/src/typedarray/access.rs#L664-L665🤖 Prompt for AI Agents
Source: Learnings