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 }})

scottmcm

@rustbot rustbot added the T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

label

Apr 9, 2022

@scottmcm scottmcm added T-libs-api

Relevant to the library API team, which will review and decide on the PR/issue.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Apr 9, 2022

RalfJung

@bors 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

May 11, 2022

@scottmcm

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.

@scottmcm

@scottmcm

@scottmcm

@bors 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

May 12, 2022

This was referenced

May 12, 2022

@scottmcm scottmcm deleted the ptr-offset-from-unsigned branch

May 12, 2022 05:25

@bors bors mentioned this pull request

May 12, 2022

celinval added a commit to celinval/kani-dev that referenced this pull request

May 19, 2022

@celinval

celinval added a commit to model-checking/kani that referenced this pull request

May 25, 2022

@celinval @adpaco-aws

Status: Compilation succeeds but regression fails due to new intrinsic.

Relevant changes:

This new intrinsic is used in many different places in the standard library and it was failing some tests for vectors.

Co-authored-by: Adrian Palacios 73246657+adpaco-aws@users.noreply.github.com

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

Sep 18, 2022

@bors

…, 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.