-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq #56550
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
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.
Do we have tests anywhere along the lines of
let x = std::rc::Rc::new(std::f32::NAN);
assert_ne!(x, x);
@oli-obk added a few tests, but it think they are somewhat wanky, testing the specific impl. |
Thanks for the PR @chpio and sorry for the delay! Initially reading this I was wary that this would break cases like @oli-obk mentioned above, but I think after reading over it this is correct and we should consider merging it. @rfcbot fcp merge For those just joining, this reimplements One minor worry I'd have is that for very simple |
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
We document that Eq is supposed to be reflexive, but unsafe code cannot rely on that, so its plausible that some implementations aren't following that. Isn't it possible this will break someone's code in which they had a non-reflexive PartialEq that still impl'd Eq? Are we fine with that? |
Code would only break if it relies on a buggy implementation of |
Another good point to bring up @withoutboats! In addition to relying on a buggy |
I think I'm inclined to agree, mainly from a pragmatic perspective - its not likely to come up in practice. But I'm uncertain what our general guidelines around backwards compatibility in regard to the "guarantees" that are made about the behavior of traits in std. There's nothing For example, members of the team have previously argued that types that implement both |
But there’s nothing |
@SimonSapin Definitely not. This is about backwards compatibility. I bring up unsafe because if the contract were reliable for to avoid UB, breaking that code would clearly be permissible. If Eq were an unsafe trait and we could rely on its reflexivity for memory safety, clearly it would be permissible to break code with a non-reflexive Eq impl, because it failed to uphold the invariants its required to as unsafe code. But the reflexivity is in this different category of contracts, which only exist in the std documentation and aren't part of the language. How do we draw the line about which of those contracts you need to uphold to get backwards compatibility from std, and which are just contracts that std is guaranteeing to uphold? |
I think the way I typically approach these kinds of problems is that we strive toward the world we want to be in, for example where That may be a bit cavalier though and certainly isn't as conservative as we could be. In any case one thing I've forgotten is that we could certainly run a crater run for this and just see if there's any impact there initially. @bors: try |
⌛ Trying commit d828c22 with merge aa49d8ef14939ddec0e34b346b60174a5673d48f... |
☀️ Test successful - status-travis |
@craterbot run start=master#bd47d6825bf4090517549d33cfef10d3300b4a75 end=try#aa49d8ef14939ddec0e34b346b60174a5673d48f mode=build-and-test |
I see it similar to the ability to define a |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Is crater just calling |
The current agent is in |
🎉 Experiment
|
couldn't spot any meaningful regressions here, just some timing or env-var not set failures. is anyone else willing to look into it? |
📌 Commit d828c22 has been approved by |
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq based on #42965 Is the use of the private trait ok this way? Is there anything else needed for this to get pulled?
Wouldn't it make sense to also do the same when comparing And then comparison of |
@chpio Ah that's why I didn't find it, it's in a different PR. I think such conclusions should be added as comments in the source code, they'll be lost otherwise. |
☀️ Test successful - status-appveyor, status-travis |
hmm, yeah. are you saying i should make a new pr for that? |
That would be great :) |
add comment to `Rc`/`Arc`'s `Eq` specialization in addition to rust-lang#56550 rust-lang#42965 (comment)
based on #42965
Is the use of the private trait ok this way? Is there anything else needed for this to get pulled?