Skip to content
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

Conversation

Noratrieb
Copy link
Member

@Noratrieb Noratrieb commented Jul 27, 2024

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 (but doesnt close until beta/stable nominations are settled) #128243

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.
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2024

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 27, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 27, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 27, 2024
@Noratrieb
Copy link
Member Author

@oli-obk @cjgillot as potential reviewers

@saethlin saethlin added beta-nominated Nominated for backporting to the compiler in the beta channel. stable-nominated Nominated for backporting to the compiler in the stable channel. labels Jul 27, 2024
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 27, 2024

📌 Commit f305e18 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 27, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
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()?;
Copy link
Member Author

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?

Copy link
Member

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 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try_to_bitwise_repr?

@bors bors merged commit f62ae7e into rust-lang:master Jul 27, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2024
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
@rustbot rustbot added this to the 1.82.0 milestone Jul 27, 2024
@Noratrieb Noratrieb deleted the jump-into-a-can-of-worms-called-float-equality branch July 27, 2024 20:55
@apiraino
Copy link
Contributor

apiraino commented Aug 1, 2024

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

@rustbot rustbot added beta-accepted Accepted for backporting to the compiler in the beta channel. stable-accepted Accepted for backporting to the compiler in the stable channel. labels Aug 1, 2024
@pietroalbini pietroalbini removed the stable-nominated Nominated for backporting to the compiler in the stable channel. label Aug 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
Prepare Rust 1.80.1 point release

The point release is scheduled to include:

* rust-lang#128271
* rust-lang#128618
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
Prepare Rust 1.80.1 point release

The point release is scheduled to include:

* rust-lang#128271
* rust-lang#128618
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 6, 2024
Prepare Rust 1.80.1 point release

The point release is scheduled to include:

* rust-lang#128271
* rust-lang#128618
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Aug 7, 2024
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]>
@cuviper cuviper modified the milestones: 1.82.0, 1.81.0 Aug 13, 2024
@cuviper cuviper removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 15, 2024
[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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. stable-accepted Accepted for backporting to the compiler in the stable channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants