Skip to content

Conversation

scottmcm
Copy link
Member

r? @RalfJung

I've included a codegen test that fails without this change as a demonstration of usefulness.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 16, 2019
@rust-highfive

This comment has been minimized.

@scottmcm scottmcm force-pushed the slice-iter-len-opt branch from be3ca63 to af0e35e Compare June 16, 2019 04:15
@hanna-kruppe
Copy link
Contributor

Nice! r=me unless you want more eyes on this first.

@RalfJung
Copy link
Member

Yes this looks great!

Do we have tests in src/liballoc that exhibit this? Would be nice to make sure Miri runs this code in a couple of situations, just to be sure.

@RalfJung
Copy link
Member

Oh also, should we see if this has any perf influence?

@RalfJung
Copy link
Member

Well let's get a try build.

@bors try

@bors
Copy link
Collaborator

bors commented Jun 16, 2019

⌛ Trying commit af0e35e with merge 9dd34620937c9854a002172599a6217be05f6520...

@bors
Copy link
Collaborator

bors commented Jun 16, 2019

☀️ Try build successful - checks-travis
Build commit: 9dd34620937c9854a002172599a6217be05f6520

@RalfJung
Copy link
Member

@rust-timer build 9dd34620937c9854a002172599a6217be05f6520

@rust-timer
Copy link
Collaborator

Success: Queued 9dd34620937c9854a002172599a6217be05f6520 with parent 6865502, comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 9dd34620937c9854a002172599a6217be05f6520, comparison URL.

@scottmcm
Copy link
Member Author

scottmcm commented Jun 17, 2019

Looks like just noise in the perf run, which doesn't surprise me. (Anyone using is_empty is unaffected by this, since it's overridden separately, and it's a tiny change anyway.)

Would be nice to make sure Miri runs this code in a couple of situations, just to be sure.

Hmm, looks like I get an

error[E0080]: Miri evaluation error: unimplemented intrinsic: unchecked_sub

on the playground. I guess I should make a MIRI PR before this goes in?

Edit: I should have looked, seems like you're already on it rust-lang/miri#776 ❤️

@RalfJung
Copy link
Member

I can't find any explicit tests for the slice iterator length method, but running miri-test-libstd on this PR shows that the code path does get hit, e.g. through slice::to_vec.

@RalfJung
Copy link
Member

Ah, and this macro also gets used in nth and position and try_fold and more, so I think we are good in terms of coverage.

@bors r=rkruppe,RalfJung

@bors
Copy link
Collaborator

bors commented Jun 17, 2019

📌 Commit af0e35e has been approved by rkruppe,RalfJung

@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 Jun 17, 2019
Centril added a commit to Centril/rust that referenced this pull request Jun 17, 2019
…ppe,RalfJung

Help LLVM better optimize slice::Iter(Mut)::len

r? @RalfJung

I've included a codegen test that fails without this change as a demonstration of usefulness.
bors added a commit that referenced this pull request Jun 17, 2019
Rollup of 5 pull requests

Successful merges:

 - #61702 (test more variants of enum-int-casting)
 - #61836 (Replace some uses of NodeId with HirId)
 - #61885 (Help LLVM better optimize slice::Iter(Mut)::len)
 - #61893 (make `Weak::ptr_eq`s into methods)
 - #61908 (don't ICE on large files)

Failed merges:

r? @ghost
@bors bors merged commit af0e35e into rust-lang:master Jun 18, 2019
@scottmcm scottmcm deleted the slice-iter-len-opt branch June 18, 2019 03:47
@RalfJung RalfJung mentioned this pull request Jun 18, 2019
bors added a commit that referenced this pull request Jun 18, 2019
update miri

Tests fail since #61885, this should fix that.

r? @oli-obk
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2023
Simplify manual ptr arithmetic in slice::Iter with ptr_sub

The old code was introduced in rust-lang#61885, which predates the ptr_sub method and underlying intrinsic. The codegen test still passes.

r? `@scottmcm`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants