Add sub_ptr
on pointers (the usize
version of offset_from
) by scottmcm · Pull Request #95837 · rust-lang/rust (original) (raw)
Conversation
This file contains hidden or 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
[ Show hidden characters]({{ revealButtonHref }})
rustbot added the T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
label
scottmcm added T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Relevant to the library team, which will review and decide on the PR/issue.
labels
bors added S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
labels
Like we have add
/sub
which are the usize
version of offset
, this adds the usize
equivalent of offset_from
. Like how .add(d)
replaced a whole bunch of .offset(d as isize)
, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and wants a usize
, not an isize
.
As a bonus, this can do sub nuw
+udiv exact
, rather than sub
+sdiv exact
, which can be optimized slightly better because it doesn't have to worry about negatives. That's why the slice iterators weren't using offset_from
, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.
This is an intrinsic, like offset_from
, so that it can eventually be allowed in CTFE. It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
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
This was referenced
May 12, 2022
scottmcm deleted the ptr-offset-from-unsigned branch
bors mentioned this pull request
celinval added a commit to celinval/kani-dev that referenced this pull request
celinval added a commit to model-checking/kani that referenced this pull request
- Update rust toolchain to 2022-05-17
Status: Compilation succeeds but regression fails due to new intrinsic.
Relevant changes:
- Implement new intrinsic ptr_offset_from_unsigned
This new intrinsic is used in many different places in the standard library and it was failing some tests for vectors.
- Apply suggestions from code review
Co-authored-by: Adrian Palacios 73246657+adpaco-aws@users.noreply.github.com
- Address PR comments
- Fix order of checks.
- Improve error message.
- Add comments to the new tests.
Co-authored-by: Adrian Palacios 73246657+adpaco-aws@users.noreply.github.com
bors added a commit to rust-lang-ci/rust that referenced this pull request
…, r=Mark-Simulacrum
Add a codegen test for slice::from_ptr_range
I noticed back in rust-lang#95579 that this didn't optimize as well as it should.
It's better now, after rust-lang#95837 changed the code in from_ptr_range
and llvm/llvm-project#54824 was fixed in LLVM 15.
So here's a test to keep it generating the good version.