-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix unsoundness for VecDeque #53571
Fix unsoundness for VecDeque #53571
Conversation
I fully agree with the For the revert, maybe we want to keep the tests and benches? |
Shouldn't there be a test to make sure the unsoundness couldn't be accidentally reintroduced in the future? |
We can't really test for UB... ... except miri can. I guess someone could add a test to the miri test suite. Ideally doing more than just a debug print; essentially running much of the rustc test suite covering |
322261c
to
3bf2cd4
Compare
@RalfJung I've now restored the tests and the benches. |
What kind of test do you plan to add? |
…onSapin" This partially reverts commit d5b6b95, reversing changes made to 6b1ff19. Fixes rust-lang#53529. Cc: rust-lang#53564.
Hm, I think this would make more sense as a unit test in |
3a1d997
to
41c43f5
Compare
@RalfJung Done! |
Awesome! r=me once traivs is happy. @bors delegate+ |
✌️ @MaloJaffre can now approve this pull request |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Oh while you are fixing this anyway, maybe you could add some assertions checking that we are getting back the values we expect (in |
41c43f5
to
30c3fb3
Compare
Sure! |
30c3fb3
to
3133025
Compare
3133025
to
f8d5ed4
Compare
@bors r=RalfJung |
📌 Commit f8d5ed4 has been approved by |
☀️ Test successful - status-appveyor, status-travis |
Reoptimize VecDeque::append ~Unfortunately, I don't know if these changes fix the unsoundness mentioned in #53529, so it is stil a WIP. This is also completely untested. The VecDeque code contains other unsound code: one example : [reading unitialized memory](https://play.rust-lang.org/?gist=6ff47551769af61fd8adc45c44010887&version=nightly&mode=release&edition=2015) (detected by MIRI), so I think this code will need a bigger refactor to make it clearer and safer.~ Note: this is based on #53571. r? @SimonSapin Cc: #53529 #52553 @yorickpeterse @jonas-schievink @Pazzaz @shepmaster.
Regarding a regression test for this: Memory Sanitizer would also have discovered this issue, and it introduces tolerable (~3x) slowdown, which is much less extreme than MIRI. |
Optimize VecDeque::append Optimize `VecDeque::append` to do unsafe copy rather than iterating through each element. On my `Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz`, the benchmark shows 37% improvements: ``` Master: custom-bench vec_deque_append 583164 ns/iter custom-bench vec_deque_append 550040 ns/iter Patched: custom-bench vec_deque_append 349204 ns/iter custom-bench vec_deque_append 368164 ns/iter ``` Additional notes on the context: this is the third attempt to implement a non-trivial version of `VecDeque::append`, the last two are reverted due to unsoundness or regression, see: - rust-lang#52553, reverted in rust-lang#53571 - rust-lang#53564, reverted in rust-lang#54851 Both cases are covered by existing tests. Signed-off-by: tabokie <xy.tao@outlook.com>
See individual commit for more details.
r? @RalfJung.
Fixes #53566, fixes #53529