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

tyencode: Make sure that projection bounds are handled in stable order. #34805

Merged
merged 1 commit into from Jul 14, 2016

Conversation

Projects
None yet
8 participants
@michaelwoerister
Copy link
Contributor

michaelwoerister commented Jul 13, 2016

Fixes #34796.

r? @alexcrichton

@michaelwoerister

This comment has been minimized.

Copy link
Contributor Author

michaelwoerister commented Jul 13, 2016

cc @eddyb

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Jul 13, 2016

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 13, 2016

📌 Commit 5ad5072 has been approved by eddyb

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 13, 2016

triage: beta-nominated

.iter()
.map(|b| (b.item_name().as_str(), b))
.collect();
projection_bounds.sort_by_key(|&(ref name, _)| name.clone());

This comment has been minimized.

@aravind-pg

aravind-pg Jul 13, 2016

Contributor

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.

This comment has been minimized.

@michaelwoerister

michaelwoerister Jul 13, 2016

Author Contributor

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.

This comment has been minimized.

@aravind-pg

aravind-pg Jul 13, 2016

Contributor

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

This comment has been minimized.

Copy link
Member

alexcrichton commented Jul 14, 2016

@bors: p=1

(fixing a regression)

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jul 14, 2016

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

bors added a commit that referenced this pull request Jul 14, 2016

Auto merge of #34805 - michaelwoerister:stable-bounds-encoding, r=eddyb
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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

brson added a commit that referenced this pull request Jul 26, 2016

@brson brson removed the beta-nominated 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
You can’t perform that action at this time.