Skip to content
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

Pass more Copy types by value. #72494

Merged
merged 4 commits into from
May 28, 2020
Merged

Pass more Copy types by value. #72494

merged 4 commits into from
May 28, 2020

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented May 23, 2020

There are a lot of locations where we pass &T where T: Copy by reference,
which should both be slightly less performant and less readable IMO.

This PR currently consists of three fairly self contained commits:

  • passes ty::Predicate by value and stops depending on AsRef<ty::Predicate>.
  • changes <&List<_>>::into_iter to iterate over the elements by value. This would break Lists
    of non copy types. But as the only list constructor requires T to be copy anyways, I think
    the improved readability is worth this potential future restriction.
  • passes mir::PlaceElem by value. Mir currently has quite a few copy types which are passed by reference, e.g. Local. As I don't have a lot of experience working with MIR, I mostly did this to get some feedback from people who use MIR more frequently
  • tries to reuse ty::Predicate in case it did not change in some places, which should hopefully
    fix the regression caused by Intern predicates #72055

r? @nikomatsakis for the first commit, which continues the work of #72055 and makes adding PredicateKind::ForAll slightly more pleasant. Feel free to reassign though

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2020
@@ -1034,7 +1034,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

Some(self.commit_if_ok(|snapshot| {
let (ty::SubtypePredicate { a_is_expected, a, b }, placeholder_map) =
self.replace_bound_vars_with_placeholders(predicate);
self.replace_bound_vars_with_placeholders(&predicate);
Copy link
Contributor Author

@lcnr lcnr May 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat related, I think it might be a good idea to change Binder to also require T: Copy and to move the reference inwards where this is not the case, i.e. &Binder(T) -> Binder(&T).

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes all seem reasonable to me. I guess cc @oli-obk or @eddyb on the final MIR commit, but it doesn't seem likely to be especially controversial. We've been slowly migrating over in the compiler to making more and more things Copy and, as we do, I think it makes sense to be shifting away from taking things via reference and towards taking them by value.

@lcnr
Copy link
Contributor Author

lcnr commented May 23, 2020

Added one more commit here which somewhat builds on the first one.

This hopefully fixes most of the regression introduces in #72055

@Dylan-DPC-zz
Copy link

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented May 23, 2020

⌛ Trying commit f15e4b3 with merge 493b2bfa42db10f469c41cd86a5a3dc9921299f2...

@bors
Copy link
Contributor

bors commented May 23, 2020

☀️ Try build successful - checks-azure
Build commit: 493b2bfa42db10f469c41cd86a5a3dc9921299f2 (493b2bfa42db10f469c41cd86a5a3dc9921299f2)

@rust-timer
Copy link
Collaborator

Queued 493b2bfa42db10f469c41cd86a5a3dc9921299f2 with parent 75b0a68, future comparison URL.

@eddyb
Copy link
Member

eddyb commented May 23, 2020

changes List::into_iter to iterate over the elements by value.

This makes sense to me, although it's impl IntoIterator for &List<T> not for List<T>, right?
So it's <&List<_>>::into_iter not List::into_iter.

Still, I can it see it being nicer overall.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 493b2bfa42db10f469c41cd86a5a3dc9921299f2, comparison URL.

@lcnr
Copy link
Contributor Author

lcnr commented May 24, 2020

The above comparison link does not work for me 😅

Tried to compare it to the current master, which should still be fairly representative: https://perf.rust-lang.org/compare.html?start=3137f8e2d141d7d7c65040a718a9193f50e1282e&end=493b2bfa42db10f469c41cd86a5a3dc9921299f2&stat=instructions%3Au

This fixes slightly less than a third of the previous regression :/

@lcnr
Copy link
Contributor Author

lcnr commented May 25, 2020

If I didn't miss something, this PR should be ready for merge.

@lcnr lcnr mentioned this pull request May 26, 2020
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 26, 2020

📌 Commit f15e4b3 has been approved by nikomatsakis

@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 26, 2020
@lcnr
Copy link
Contributor Author

lcnr commented May 26, 2020

@nikomatsakis This PR changes perf, so we probably should use @bors rollup=never here

@bors
Copy link
Contributor

bors commented May 26, 2020

@lcnr: 🔑 Insufficient privileges: not in try users

@nikomatsakis
Copy link
Contributor

@bors rollup=never

@Dylan-DPC-zz
Copy link

@bors p=1

@bors
Copy link
Contributor

bors commented May 28, 2020

⌛ Testing commit f15e4b3 with merge 4512721...

@bors
Copy link
Contributor

bors commented May 28, 2020

☀️ Test successful - checks-azure
Approved by: nikomatsakis
Pushing 4512721 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 28, 2020
@bors bors merged commit 4512721 into rust-lang:master May 28, 2020
@lcnr lcnr deleted the predicate-cleanup branch May 28, 2020 06:36
@nnethercote
Copy link
Contributor

Perf results from the landing show a small win. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

8 participants