Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
instance: polymorphize upvar closures/generators
This commit modifies how instances are polymorphized so that closures and generators have any closures or generators captured within their upvars also polymorphized - this avoids symbol clashes with the new symbol mangling scheme. Signed-off-by: David Wood <david@davidtw.co>
- Loading branch information
Showing
5 changed files
with
222 additions
and
20 deletions.
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,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(()); | ||
|
||
// 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 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 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 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(); | ||
} |