-
-
Notifications
You must be signed in to change notification settings - Fork 145
fix(runtime,codegen): bitnot ToNumber coercion + modulus zero/sign-of-zero #5822
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -458,7 +458,17 @@ pub unsafe extern "C" fn js_dynamic_bitnot(a: f64) -> f64 { | |
| ); | ||
| return js_nanbox_bigint(result as i64); | ||
| } | ||
| (!(a as i64 as i32)) as f64 | ||
| // Apply ToNumber first so that ~"3", ~true, ~new Boolean(true), etc. | ||
| // coerce correctly before the ToInt32 truncation. | ||
| let a_num = crate::builtins::js_number_coerce(a); | ||
| // ES ToInt32: NaN, ±0, ±Infinity all map to 0; finite values use | ||
| // C-style i64 truncation (equivalent to modulo-2^32 + sign-extend). | ||
| let a_i32 = if a_num.is_nan() || !a_num.is_finite() { | ||
| 0i32 | ||
| } else { | ||
| a_num as i64 as i32 | ||
| }; | ||
| (!a_i32) as f64 | ||
|
Comment on lines
+464
to
+471
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🌐 Web query:
💡 Result: As of Rust 1.45.0, casting a floating-point number ( Citations:
🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect the target file around the referenced lines.
sed -n '420,500p' crates/perry-runtime/src/value/dynamic_arith.rs
echo
echo '--- SEARCH ToInt32 helpers ---'
rg -n "ToInt32|to_int32|Int32" crates/perry-runtime/src -g '!**/target/**' || trueRepository: PerryTS/perry Length of output: 14514 🏁 Script executed: #!/bin/bash
set -euo pipefail
sed -n '420,500p' crates/perry-runtime/src/value/dynamic_arith.rs
echo
echo '--- SEARCH ToInt32 helpers ---'
rg -n "ToInt32|to_int32|Int32" crates/perry-runtime/src -g '!**/target/**' || trueRepository: PerryTS/perry Length of output: 14514 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- math.rs ToInt32 helper ---'
sed -n '1,120p' crates/perry-runtime/src/math.rs
echo
echo '--- builtin_thunks.rs ToInt32 helper ---'
sed -n '70,110p' crates/perry-runtime/src/object/global_this/builtin_thunks.rs
echo
echo '--- parse_int helper ---'
sed -n '80,120p' crates/perry-runtime/src/builtins/numbers.rsRepository: PerryTS/perry Length of output: 5596 Use the JS ToInt32 path here instead of 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| /// Dynamic right shift: BigInt >> if either operand is BigInt, else i32 >> for numbers. | ||
|
|
||
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.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 279
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 9006
Guard the integer modulo fast path against runtime zero divisors
right_is_known_zeroonly filters literal0/0.0, butis_integer_valued_expralso accepts integer locals, updates, and nested integer arithmetic, so a non-literal RHS can still be0at runtime and reachsrem(I64, ..., 0). Add a runtimeri == 0check and fall back tofremin that case.🤖 Prompt for AI Agents