Uh oh!
There was an error while loading. Please reload this page.
Simplify manual ptr arithmetic in slice::Iter with ptr_sub - #106393
Conversation
rustbot
commented
Jan 3, 2023
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
scottmcm
commented
Jan 14, 2023
Oh, thanks! This was the original motivating example for #95837, but I didn't want to change something as critical as slice iterators in that PR. r=me assuming that this doesn't have some weird perf implication @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
bors
commented
Jan 14, 2023
⌛ Trying commit e7e9e477a4ffffe49e0ee4657626b18c71700026 with merge 018625f89e1b5bf3ce3585225ac9ca701f9bf0f1... |
bors
commented
Jan 14, 2023
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
rust-timer
commented
Jan 14, 2023
Finished benchmarking commit (018625f89e1b5bf3ce3585225ac9ca701f9bf0f1): comparison URL. Overall result: ❌ regressions - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
scottmcm
commented
Jan 14, 2023
Perf looks essentially neutral, the one change is because of the codegen schedule that appears to actually be shorter overall, despite the extra instructions. @bors rollup=maybe Still needs a rebase, though, @the8472. Feel free to r=me after that. |
the8472
commented
Jan 14, 2023
@bors r=scottmcm |
bors
commented
Jan 14, 2023
📌 Commit e31d73ca7ef44e855b3d55c9ab6749ba5f78be10 has been approved by It is now in the queue for this repository. |
bors
commented
Jan 15, 2023
☔ The latest upstream changes (presumably #106866) made this pull request unmergeable. Please resolve the merge conflicts. |
b91b493 to
3a3d2b4Comparethe8472
commented
Jan 15, 2023
@bors r=scottmcm |
bors
commented
Jan 15, 2023
📌 Commit 3a3d2b4c9c8469272278f8cf602de7c16d39b3fb has been approved by It is now in the queue for this repository. |
bors
commented
Jan 15, 2023
⌛ Testing commit 3a3d2b4c9c8469272278f8cf602de7c16d39b3fb with merge d1fc44b7b575d0f3dc7bcb492719fe7cf71d5aad... |
bors
commented
Jan 15, 2023
💔 Test failed - checks-actions |
the8472
commented
Jan 15, 2023
Ok, this probably isn't due to the llvm version then. I see that |
This comment has been minimized.
This comment has been minimized.
the8472
commented
Jan 15, 2023
@bors r=scottmcm |
bors
commented
Jan 15, 2023
bors
commented
Jan 15, 2023
bors
commented
Jan 15, 2023
☀️ Test successful - checks-actions |
rust-timer
commented
Jan 15, 2023
Finished benchmarking commit (9e75ddd): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
| // To get rid of some bounds checks (see `position`), we use ptr_sub instead of | ||
| // offset_from (Tested by `codegen/slice-position-bounds-check`.) | ||
| // SAFETY: by the type invariant pointers are aligned and `start <= end` | ||
| unsafe { $self.end.sub_ptr(start.as_ptr()) } |
There was a problem hiding this comment.
This safety comment is incomplete. sub_ptr (via the offset_from safety requirements) requires the pointers to point to the same allocation, and they must be dereferenceable, i.e., point to allocated memory. The latter is not currently always the case, though whether that is a bug in this function or a bug in whatever creates those dangling raw pointers is unclear.
See Zulip
| let size = size_from_ptr(start.as_ptr()); | ||
| if size == 0 { | ||
| // This _cannot_ use `unchecked_sub` because we depend on wrapping | ||
| if T::IS_ZST { |
There was a problem hiding this comment.
This is odd, where is T bound? Does this macro assume that there is a T in scope wherever it is used (violating hygiene)? That at least warrants a comment.
There was a problem hiding this comment.
The macro is only used in another macro (in the same file) which defines T
The old code was introduced in #61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes.
r? @scottmcm