Make drop-glue take advantage of -Zshare-generics.

This commit is contained in:
Michael Woerister 2020-01-20 16:38:42 +01:00
parent 190f0c0b0b
commit 2ceb92bc53
5 changed files with 52 additions and 16 deletions

View file

@ -1,4 +1,6 @@
// compile-flags:-Zshare-generics=yes
// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels
// prevent drop-glue from participating in share-generics.
// compile-flags:-Zshare-generics=yes -Copt-level=0
// no-prefer-dynamic
#![crate_type="rlib"]
@ -8,5 +10,17 @@ pub fn generic_fn<T>(x: T, y: T) -> (T, T) {
}
pub fn use_generic_fn_f32() -> (f32, f32) {
// This line causes drop glue for Foo to be instantiated. We want to make
// sure that this crate exports an instance to be re-used by share-generics.
let _ = Foo(0);
generic_fn(0.0f32, 1.0f32)
}
pub struct Foo(pub u32);
impl Drop for Foo {
fn drop(&mut self) {
println!("foo");
}
}

View file

@ -1,6 +1,8 @@
// ignore-tidy-linelength
// no-prefer-dynamic
// compile-flags:-Zprint-mono-items=eager -Zshare-generics=yes -Zincremental=tmp/partitioning-tests/shared-generics-exe
// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels
// prevent drop-glue from participating in share-generics.
// compile-flags:-Zprint-mono-items=eager -Zshare-generics=yes -Zincremental=tmp/partitioning-tests/shared-generics-exe -Copt-level=0
#![crate_type="rlib"]
@ -16,6 +18,10 @@ pub fn foo() {
// This should not generate a monomorphization because it's already
// available in `shared_generics_aux`.
let _ = shared_generics_aux::generic_fn(0.0f32, 3.0f32);
}
// MONO_ITEM drop-glue i8
// The following line will drop an instance of `Foo`, generating a call to
// Foo's drop-glue function. However, share-generics should take care of
// reusing the drop-glue from the upstream crate, so we do not expect a
// mono item for the drop-glue
let _ = shared_generics_aux::Foo(1);
}