-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix Instance::resolve()
incorrectly returning specialized instances
#67662
Merged
bors
merged 1 commit into
rust-lang:master
from
wesleywiser:optimizations_handle_specialization
Dec 30, 2019
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
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
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
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,48 @@ | ||
#![feature(specialization)] | ||
|
||
fn main() { | ||
let x = <Vec::<()> as Foo>::bar(); | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
trait Foo { | ||
fn bar() -> u32; | ||
} | ||
|
||
impl<T> Foo for Vec<T> { | ||
#[inline(always)] | ||
default fn bar() -> u32 { 123 } | ||
} | ||
|
||
// END RUST SOURCE | ||
// START rustc.main.Inline.before.mir | ||
// let mut _0: (); | ||
// let _1: u32; | ||
// scope 1 { | ||
// debug x => _1; | ||
// } | ||
// bb0: { | ||
// StorageLive(_1); | ||
// _1 = const <std::vec::Vec<()> as Foo>::bar() -> bb1; | ||
// } | ||
// bb1: { | ||
// _0 = (); | ||
// StorageDead(_1); | ||
// return; | ||
// } | ||
// END rustc.main.Inline.before.mir | ||
// START rustc.main.Inline.after.mir | ||
// let mut _0: (); | ||
// let _1: u32; | ||
// scope 1 { | ||
// debug x => _1; | ||
// } | ||
// scope 2 { | ||
// } | ||
// bb0: { | ||
// StorageLive(_1); | ||
// _1 = const 123u32; | ||
// _0 = (); | ||
// StorageDead(_1); | ||
// return; | ||
// } | ||
// END rustc.main.Inline.after.mir |
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,65 @@ | ||
// ignore-wasm32-bare which doesn't support `std::process:exit()` | ||
// compile-flags: -Zmir-opt-level=2 | ||
// run-pass | ||
|
||
// Tests that specialization does not cause optimizations running on polymorphic MIR to resolve | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// to a `default` implementation. | ||
|
||
#![feature(specialization)] | ||
|
||
trait Marker {} | ||
|
||
trait SpecializedTrait { | ||
const CONST_BOOL: bool; | ||
const CONST_STR: &'static str; | ||
fn method() -> &'static str; | ||
} | ||
impl <T> SpecializedTrait for T { | ||
wesleywiser marked this conversation as resolved.
Show resolved
Hide resolved
|
||
default const CONST_BOOL: bool = false; | ||
default const CONST_STR: &'static str = "in default impl"; | ||
#[inline(always)] | ||
default fn method() -> &'static str { | ||
"in default impl" | ||
} | ||
} | ||
impl <T: Marker> SpecializedTrait for T { | ||
const CONST_BOOL: bool = true; | ||
const CONST_STR: &'static str = "in specialized impl"; | ||
fn method() -> &'static str { | ||
"in specialized impl" | ||
} | ||
} | ||
|
||
fn const_bool<T>() -> &'static str { | ||
if <T as SpecializedTrait>::CONST_BOOL { | ||
"in specialized impl" | ||
} else { | ||
"in default impl" | ||
} | ||
} | ||
fn const_str<T>() -> &'static str { | ||
<T as SpecializedTrait>::CONST_STR | ||
} | ||
fn run_method<T>() -> &'static str { | ||
<T as SpecializedTrait>::method() | ||
} | ||
|
||
struct TypeA; | ||
impl Marker for TypeA {} | ||
struct TypeB; | ||
|
||
#[inline(never)] | ||
fn exit_if_not_eq(left: &str, right: &str) { | ||
if left != right { | ||
std::process::exit(1); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
exit_if_not_eq("in specialized impl", const_bool::<TypeA>()); | ||
exit_if_not_eq("in default impl", const_bool::<TypeB>()); | ||
exit_if_not_eq("in specialized impl", const_str::<TypeA>()); | ||
exit_if_not_eq("in default impl", const_str::<TypeB>()); | ||
exit_if_not_eq("in specialized impl", run_method::<TypeA>()); | ||
exit_if_not_eq("in default impl", run_method::<TypeB>()); | ||
} |
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
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.
You might want an assert that
!trait_ref.needs_infer()
.