-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Disable jump threading of float equality #128271
Disable jump threading of float equality #128271
Conversation
Jump threading stores values as `u128` (`ScalarInt`) and does its comparisons for equality as integer comparisons. This works great for integers. Sadly, not everything is an integer. Floats famously have wonky equality semantcs, with `NaN!=NaN` and `0.0 == -0.0`. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong. While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now.
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@bors r+ |
Rollup of 8 pull requests Successful merges: - rust-lang#125897 (from_ref, from_mut: clarify documentation) - rust-lang#128207 (improve error message when `global_asm!` uses `asm!` options) - rust-lang#128241 (Remove logic to suggest clone of function output) - rust-lang#128259 ([illumos/solaris] set MSG_NOSIGNAL while writing to sockets) - rust-lang#128262 (Delete `SimplifyArmIdentity` and `SimplifyBranchSame` tests) - rust-lang#128266 (update `rust.channel` default value documentation) - rust-lang#128267 (Add rustdoc GUI test to check title with and without search) - rust-lang#128271 (Disable jump threading of float equality) r? `@ghost` `@rustbot` modify labels: rollup
// and therefore we cannot use integer comparisons for them. | ||
// Avoid handling them, though this could be extended in the future. | ||
return None; | ||
} | ||
let value = value.const_.normalize(self.tcx, self.param_env).try_to_scalar_int()?; |
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.
While this PR is an easily backportable targeted fix, it might be worth thinking about how to prevent this more generally. It seems highly confusing that a method called try_to_scalar_int
will return floats, and it doesn't surprise me that this pass was confused by this. I would also expect try_to_scalar_int
to be OK for comparing bitwise.
Maybe it should be changed to not return anything for floats?
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.
Possibly bad suggestion, but maybe we shouldn't use valtrees to represent floats 🤔
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.
try_to_bitwise_repr
?
Rollup merge of rust-lang#128271 - Nilstrieb:jump-into-a-can-of-worms-called-float-equality, r=compiler-errors Disable jump threading of float equality Jump threading stores values as `u128` (`ScalarInt`) and does its comparisons for equality as integer comparisons. This works great for integers. Sadly, not everything is an integer. Floats famously have wonky equality semantcs, with `NaN!=NaN` and `0.0 == -0.0`. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong. While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now. fixes rust-lang#128243
Beta backport approved as per compiler team on Zulip. A backport PR will be authored by the release team at the end of the current development cycle. Given the regression that it fixes and the fact that we have a report from a user, T-compiler is inclined that this backport is worth publishing a dot release alone. @rustbot label +beta-accepted +stable-accepted |
Prepare Rust 1.80.1 point release The point release is scheduled to include: * rust-lang#128271 * rust-lang#128618
Prepare Rust 1.80.1 point release The point release is scheduled to include: * rust-lang#128271 * rust-lang#128618
Prepare Rust 1.80.1 point release The point release is scheduled to include: * rust-lang#128271 * rust-lang#128618
826: Disable jump threading of float equality r=Hoverbear a=Veykril Jump threading stores values as `u128` (`ScalarInt`) and does its comparisons for equality as integer comparisons. This works great for integers. Sadly, not everything is an integer. Floats famously have wonky equality semantcs, with `NaN!=NaN` and `0.0 == -0.0`. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong. While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now. Ferrocene-backport-of: rust-lang/rust#128271 Co-authored-by: Nilstrieb <[email protected]> Co-authored-by: Pietro Albini <[email protected]>
[beta] backports and bump stage0 - Disable jump threading of float equality rust-lang#128271 - Normalize when equating `dyn` tails in MIR borrowck rust-lang#128694 - Improve `Ord` violation help rust-lang#128273 - bump stage0 to stable 1.80.1 - Revert rust-lang#125915 on beta rust-lang#128760 - derive(SmartPointer): register helper attributes rust-lang#128925 - Fix bug in `Parser::look_ahead`. rust-lang#128994 r? cuviper
Jump threading stores values as
u128
(ScalarInt
) and does its comparisons for equality as integer comparisons.This works great for integers. Sadly, not everything is an integer.
Floats famously have wonky equality semantcs, with
NaN!=NaN
and0.0 == -0.0
. This does not match our beautiful integer bitpattern equality and therefore causes things to go horribly wrong.While jump threading could be extended to support floats by remembering that they're floats in the value state and handling them properly, it's signficantly easier to just disable it for now.
fixes (but doesnt close until beta/stable nominations are settled) #128243