-
Notifications
You must be signed in to change notification settings - Fork 13.4k
instance: polymorphize upvar closures/generators #75255
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
Merged
bors
merged 5 commits into
rust-lang:master
from
davidtwco:polymorphisation-symbol-mangling-v0-upvar-closures
Aug 7, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d9deced
instance: polymorphize upvar closures/generators
davidtwco 0d9924a
instance: always polymorphize substs
davidtwco 5827b5a
ty: add `MAY_POLYMORPHIZE` flag
davidtwco 4ccaf6f
instance: avoid unnecessary `mk_` calls
davidtwco ac50d61
instance: polymorphize `FnDef` substs
davidtwco 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
// compile-flags:-Zpolymorphize=on -Zprint-mono-items=lazy -Copt-level=1 | ||
// ignore-tidy-linelength | ||
|
||
#![crate_type = "rlib"] | ||
|
||
// Test that only one copy of `Iter::map` and `iter::repeat` are generated. | ||
|
||
fn unused<T>() -> u64 { | ||
42 | ||
} | ||
|
||
fn foo<T>() { | ||
let x = [1, 2, 3, std::mem::size_of::<T>()]; | ||
x.iter().map(|_| ()); | ||
} | ||
|
||
//~ MONO_ITEM fn core::iter[0]::adapters[0]::{{impl}}[29]::new[0]<core::slice[0]::Iter[0]<usize>, pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.0[External] | ||
//~ MONO_ITEM fn core::iter[0]::traits[0]::iterator[0]::Iterator[0]::map[0]<core::slice[0]::Iter[0]<usize>, (), pr_75255::foo[0]::{{closure}}[0]<T>> @@ pr_75255-cgu.1[Internal] | ||
|
||
fn bar<T>() { | ||
std::iter::repeat(unused::<T>); | ||
} | ||
|
||
//~ MONO_ITEM fn core::iter[0]::sources[0]::repeat[0]<fn() -> u64> @@ pr_75255-cgu.1[Internal] | ||
|
||
pub fn dispatch() { | ||
foo::<String>(); | ||
foo::<Vec<String>>(); | ||
|
||
bar::<String>(); | ||
bar::<Vec<String>>(); | ||
} | ||
|
||
// These are all the items that aren't relevant to the test. | ||
//~ MONO_ITEM fn core::mem[0]::size_of[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::mem[0]::size_of[0]<alloc::vec[0]::Vec[0]<alloc::string[0]::String[0]>> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::mem[0]::size_of[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::const_ptr[0]::{{impl}}[0]::add[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::const_ptr[0]::{{impl}}[0]::is_null[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::const_ptr[0]::{{impl}}[0]::offset[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::const_ptr[0]::{{impl}}[0]::wrapping_add[0]<u8> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::const_ptr[0]::{{impl}}[0]::wrapping_offset[0]<u8> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::non_null[0]::{{impl}}[3]::new_unchecked[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::ptr[0]::null[0]<u8> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::slice[0]::{{impl}}[0]::as_ptr[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::slice[0]::{{impl}}[0]::iter[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn core::slice[0]::{{impl}}[0]::len[0]<usize> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn pr_75255::dispatch[0] @@ pr_75255-cgu.1[External] | ||
//~ MONO_ITEM fn pr_75255::foo[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn pr_75255::foo[0]<alloc::vec[0]::Vec[0]<alloc::string[0]::String[0]>> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn pr_75255::bar[0]<alloc::string[0]::String[0]> @@ pr_75255-cgu.1[Internal] | ||
//~ MONO_ITEM fn pr_75255::bar[0]<alloc::vec[0]::Vec[0]<alloc::string[0]::String[0]>> @@ pr_75255-cgu.1[Internal] |
This file contains hidden or 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,29 @@ | ||
// build-pass | ||
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0 | ||
|
||
fn foo(f: impl Fn()) { | ||
let x = |_: ()| (); | ||
|
||
// Don't use `f` in `y`, but refer to `x` so that the closure substs contain a reference to | ||
// `x` that will differ for each instantiation despite polymorphisation of the varying | ||
// argument. | ||
let y = || x(()); | ||
lcnr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Consider `f` used in `foo`. | ||
f(); | ||
// Use `y` so that it is visited in monomorphisation collection. | ||
y(); | ||
} | ||
|
||
fn entry_a() { | ||
foo(|| ()); | ||
} | ||
|
||
fn entry_b() { | ||
foo(|| ()); | ||
} | ||
|
||
fn main() { | ||
entry_a(); | ||
entry_b(); | ||
} |
This file contains hidden or 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,34 @@ | ||
// build-pass | ||
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0 | ||
|
||
fn foo(f: impl Fn()) { | ||
// Mutate an upvar from `x` so that it implements `FnMut`. | ||
let mut outer = 3; | ||
let mut x = |_: ()| { | ||
outer = 4; | ||
() | ||
}; | ||
|
||
// Don't use `f` in `y`, but refer to `x` so that the closure substs contain a reference to | ||
// `x` that will differ for each instantiation despite polymorphisation of the varying | ||
// argument. | ||
let mut y = || x(()); | ||
|
||
// Consider `f` used in `foo`. | ||
f(); | ||
// Use `y` so that it is visited in monomorphisation collection. | ||
y(); | ||
} | ||
|
||
fn entry_a() { | ||
foo(|| ()); | ||
} | ||
|
||
fn entry_b() { | ||
foo(|| ()); | ||
} | ||
|
||
fn main() { | ||
entry_a(); | ||
entry_b(); | ||
} |
This file contains hidden or 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,34 @@ | ||
// build-pass | ||
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0 | ||
|
||
fn foo(f: impl Fn()) { | ||
// Move a non-copy type into `x` so that it implements `FnOnce`. | ||
let outer = Vec::<u32>::new(); | ||
let x = move |_: ()| { | ||
let inner = outer; | ||
() | ||
}; | ||
|
||
// Don't use `f` in `y`, but refer to `x` so that the closure substs contain a reference to | ||
// `x` that will differ for each instantiation despite polymorphisation of the varying | ||
// argument. | ||
let y = || x(()); | ||
|
||
// Consider `f` used in `foo`. | ||
f(); | ||
// Use `y` so that it is visited in monomorphisation collection. | ||
y(); | ||
} | ||
|
||
fn entry_a() { | ||
foo(|| ()); | ||
} | ||
|
||
fn entry_b() { | ||
foo(|| ()); | ||
} | ||
|
||
fn main() { | ||
entry_a(); | ||
entry_b(); | ||
} |
This file contains hidden or 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,38 @@ | ||
// build-pass | ||
// compile-flags:-Zpolymorphize=on -Zsymbol-mangling-version=v0 | ||
|
||
fn y_uses_f(f: impl Fn()) { | ||
let x = |_: ()| (); | ||
|
||
let y = || { | ||
f(); | ||
x(()); | ||
}; | ||
|
||
f(); | ||
y(); | ||
} | ||
|
||
fn x_uses_f(f: impl Fn()) { | ||
let x = |_: ()| { f(); }; | ||
|
||
let y = || x(()); | ||
|
||
f(); | ||
y(); | ||
} | ||
|
||
fn entry_a() { | ||
x_uses_f(|| ()); | ||
y_uses_f(|| ()); | ||
} | ||
|
||
fn entry_b() { | ||
x_uses_f(|| ()); | ||
y_uses_f(|| ()); | ||
} | ||
|
||
fn main() { | ||
entry_a(); | ||
entry_b(); | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.