-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
bors
merged 1 commit into
rust-lang:master
from
michaelwoerister:stable-bounds-encoding
Jul 14, 2016
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![crate_type = "lib"] | ||
pub trait Future { | ||
type Item; | ||
type Error; | ||
} | ||
|
||
impl Future for u32 { | ||
type Item = (); | ||
type Error = Box<()>; | ||
} | ||
|
||
fn foo() -> Box<Future<Item=(), Error=Box<()>>> { | ||
Box::new(0u32) | ||
} | ||
|
||
pub fn bar<F, A, B>(_s: F) | ||
where F: Fn(A) -> B, | ||
{ | ||
foo(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// This test case exposes conditions where the encoding of a trait object type | ||
// with projection predicates would differ between this crate and the upstream | ||
// crate, because the predicates were encoded in different order within each | ||
// crate. This led to different symbol hashes of functions using these type, | ||
// which in turn led to linker errors because the two crates would not agree on | ||
// the symbol name. | ||
// The fix was to make the order in which predicates get encoded stable. | ||
|
||
// aux-build:issue34796aux.rs | ||
extern crate issue34796aux; | ||
|
||
fn mk<T>() -> T { loop {} } | ||
|
||
struct Data<T, E> { | ||
data: T, | ||
error: E, | ||
} | ||
|
||
fn main() { | ||
issue34796aux::bar(|()| { | ||
Data::<(), std::io::Error> { | ||
data: mk(), | ||
error: mk(), | ||
} | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)?
Because then it seems we'd be able to keep the next line just
for tp in &projection_bounds { ... }
, avoiding the extra call tomap
.And even if we didn't do this the next line still seems like it could stay
for tp in &projection_bounds
withs/tp.0/tp.1.0
in the loop body.There was a problem hiding this comment.
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: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 thatb.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.
There was a problem hiding this comment.
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. tob.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 thatsort_by_key
returns unit, so your fix makes sense. Thanks for the explanation! Up to you what changes you want to make, if any.