Skip to content

Conversation

michaelwoerister
Copy link
Member

Fixes #34796.

r? @alexcrichton

@michaelwoerister
Copy link
Member Author

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Jul 13, 2016

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 13, 2016

📌 Commit 5ad5072 has been approved by eddyb

@alexcrichton
Copy link
Member

triage: beta-nominated

@rust-highfive rust-highfive added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 13, 2016
@alexcrichton alexcrichton added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 13, 2016
.iter()
.map(|b| (b.item_name().as_str(), b))
.collect();
projection_bounds.sort_by_key(|&(ref name, _)| name.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

Newbie question (and total nit): why couldn't this basically be the following (or something close to it)?

let mut projection_bounds = bs.projection_bounds
                              .clone()
                              .sort_by_key(|&b| b.item_name().as_str());

Because then it seems we'd be able to keep the next line just for tp in &projection_bounds { ... }, avoiding the extra call to map.

And even if we didn't do this the next line still seems like it could stay for tp in &projection_bounds with s/tp.0/tp.1.0 in the loop body.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since sort_by_key() returns nothing, projection_bounds with be the unit value (). It would have to look at least like:

let mut projection_bounds = bs.projection_bounds.clone();
projection_bounds.sort_by_key(|&b| b.item_name().as_str());

And why didn't I do it like the above? In order to avoid that b.item_name().as_str() gets called more than once per item. Although, I somehow mistakenly assumed that b.item_name().as_str() would need to hash the string each time when looking it up in the interner, which it doesn't, so this "optimization" is even more premature than I thought :)

So, your version, when fixed as indicated, would actually be nicer than mine.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, because sort_by_key would make basically O(n log n) calls to its closure, i.e. to b.item_name().as_str()? Makes much more sense now (notwithstanding the question of whether it's a premature optimization :). And yeah I overlooked the fact that sort_by_key returns unit, so your fix makes sense. Thanks for the explanation! Up to you what changes you want to make, if any.

@alexcrichton
Copy link
Member

alexcrichton commented Jul 14, 2016

@bors: p=1

(fixing a regression)

@bors
Copy link
Collaborator

bors commented Jul 14, 2016

⌛ Testing commit 5ad5072 with merge 3c85f41...

bors added a commit that referenced this pull request Jul 14, 2016
tyencode: Make sure that projection bounds are handled in stable order.

Fixes #34796.

r? @alexcrichton
@bors bors merged commit 5ad5072 into rust-lang:master Jul 14, 2016
@pnkfelix pnkfelix added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Jul 21, 2016
brson added a commit that referenced this pull request Jul 26, 2016
@brson brson removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 26, 2016
pmatos pushed a commit to LinkiTools/rust that referenced this pull request Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-accepted Accepted for backporting to the compiler in the beta channel. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants