-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element #36355
Merged
bors
merged 1 commit into
rust-lang:master
from
bluss:vec-extend-from-slice-aliasing-workaround
Sep 12, 2016
Merged
Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element #36355
bors
merged 1 commit into
rust-lang:master
from
bluss:vec-extend-from-slice-aliasing-workaround
Sep 12, 2016
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
bluss
force-pushed
the
vec-extend-from-slice-aliasing-workaround
branch
2 times, most recently
from
September 8, 2016 22:02
e9fc619
to
a8702bf
Compare
…with_element Due to missing noalias annotations for &mut T in general (issue rust-lang#31681), in larger programs extend_from_slice and extend_with_element may both compile very poorly. What is observed is that the .set_len() calls are not lifted out of the loop, even for `Vec<u8>`. Use a local length variable for the Vec length instead, and use a scope guard to write this value back to self.len when the scope ends or on panic. Then the alias analysis is easy. This affects extend_from_slice, extend_with_element, the vec![x; n] macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not have triggered since inlining can be enough for the compiler to get it right).
bluss
force-pushed
the
vec-extend-from-slice-aliasing-workaround
branch
from
September 9, 2016 00:39
a8702bf
to
765700b
Compare
Verified that it fixes the two issues. (More or less by finding programs that exhibit the regression behavior, and then that the new version fixes it). |
bluss
changed the title
WIP Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element
Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element
Sep 9, 2016
Adding fixes #17844 since Vec::clone uses extend_from_slice |
Thanks. I'm thrilled to see this fixed. |
⌛ Testing commit 765700b with merge 4d91323... |
bors
added a commit
that referenced
this pull request
Sep 12, 2016
…d, r=alexcrichton Work around pointer aliasing issue in Vec::extend_from_slice, extend_with_element Due to missing noalias annotations for &mut T in general (issue #31681), in larger programs extend_from_slice and extend_with_element may both compile very poorly. What is observed is that the .set_len() calls are not lifted out of the loop, even for `Vec<u8>`. Use a local length variable for the Vec length instead, and use a scope guard to write this value back to self.len when the scope ends or on panic. Then the alias analysis is easy. This affects extend_from_slice, extend_with_element, the vec![x; n] macro, Write impls for Vec<u8>, BufWriter, etc (but may / may not have triggered since inlining can be enough for the compiler to get it right). Fixes #32155 Fixes #33518 Closes #17844
mbrubeck
added a commit
to mbrubeck/rust-smallvec
that referenced
this pull request
Jan 4, 2019
This ensures that the length of the SmallVec is updated even if the iterator panics in `next`. This uses `SetLenOnDrop` rather than setting the length inside the loop, because otherwise this suffers from the same optimization issue as rust-lang/rust#36355. Fixes servo#136.
bors-servo
pushed a commit
to servo/rust-smallvec
that referenced
this pull request
Jan 4, 2019
Don't leak on panic in extend This ensures that the length of the SmallVec is updated even if the iterator panics in `next`. This uses `SetLenOnDrop` rather than setting the length inside the loop, because otherwise this suffers from the same optimization issue as rust-lang/rust#36355. Fixes #136. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-smallvec/137) <!-- Reviewable:end -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to missing noalias annotations for &mut T in general (issue #31681),
in larger programs extend_from_slice and extend_with_element may both
compile very poorly. What is observed is that the .set_len() calls are
not lifted out of the loop, even for
Vec<u8>
.Use a local length variable for the Vec length instead, and use a scope
guard to write this value back to self.len when the scope ends or on
panic. Then the alias analysis is easy.
This affects extend_from_slice, extend_with_element, the vec![x; n]
macro, Write impls for Vec, BufWriter, etc (but may / may not
have triggered since inlining can be enough for the compiler to get it right).
Fixes #32155
Fixes #33518
Closes #17844