diff options
Diffstat (limited to 'tests/codegen-units/partitioning')
18 files changed, 792 insertions, 0 deletions
diff --git a/tests/codegen-units/partitioning/auxiliary/cgu_explicit_inlining.rs b/tests/codegen-units/partitioning/auxiliary/cgu_explicit_inlining.rs new file mode 100644 index 000000000..4a3a63cc1 --- /dev/null +++ b/tests/codegen-units/partitioning/auxiliary/cgu_explicit_inlining.rs @@ -0,0 +1,10 @@ +#![crate_type = "lib"] + +#[inline] +pub fn inlined() {} + +#[inline(always)] +pub fn always_inlined() {} + +#[inline(never)] +pub fn never_inlined() {} diff --git a/tests/codegen-units/partitioning/auxiliary/cgu_extern_drop_glue.rs b/tests/codegen-units/partitioning/auxiliary/cgu_extern_drop_glue.rs new file mode 100644 index 000000000..b5fec2337 --- /dev/null +++ b/tests/codegen-units/partitioning/auxiliary/cgu_extern_drop_glue.rs @@ -0,0 +1,7 @@ +#![crate_type = "lib"] + +pub struct Struct(pub u32); + +impl Drop for Struct { + fn drop(&mut self) {} +} diff --git a/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs b/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs new file mode 100644 index 000000000..3926f2957 --- /dev/null +++ b/tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs @@ -0,0 +1,26 @@ +#![crate_type = "lib"] + +struct Struct(u32); + +#[inline(never)] +pub fn foo<T>(x: T) -> (T, u32, i8) { + let (x, Struct(y)) = bar(x); + (x, y, 2) +} + +#[inline(never)] +fn bar<T>(x: T) -> (T, Struct) { + let _ = not_exported_and_not_generic(0); + (x, Struct(1)) +} + +// These should not contribute to the codegen items of other crates. +#[inline(never)] +pub fn exported_but_not_generic(x: i32) -> i64 { + x as i64 +} + +#[inline(never)] +fn not_exported_and_not_generic(x: u32) -> u64 { + x as u64 +} diff --git a/tests/codegen-units/partitioning/auxiliary/shared_generics_aux.rs b/tests/codegen-units/partitioning/auxiliary/shared_generics_aux.rs new file mode 100644 index 000000000..ffbd0dc54 --- /dev/null +++ b/tests/codegen-units/partitioning/auxiliary/shared_generics_aux.rs @@ -0,0 +1,26 @@ +// 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"] + +pub fn generic_fn<T>(x: T, y: T) -> (T, T) { + (x, y) +} + +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"); + } +} diff --git a/tests/codegen-units/partitioning/extern-drop-glue.rs b/tests/codegen-units/partitioning/extern-drop-glue.rs new file mode 100644 index 000000000..c73d2a10a --- /dev/null +++ b/tests/codegen-units/partitioning/extern-drop-glue.rs @@ -0,0 +1,36 @@ +// + +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// We specify opt-level=0 because `drop_in_place` is `Internal` when optimizing +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus -Copt-level=0 + +#![allow(dead_code)] +#![crate_type = "rlib"] + +// aux-build:cgu_extern_drop_glue.rs +extern crate cgu_extern_drop_glue; + +//~ MONO_ITEM fn std::ptr::drop_in_place::<cgu_extern_drop_glue::Struct> - shim(Some(cgu_extern_drop_glue::Struct)) @@ extern_drop_glue-fallback.cgu[External] + +struct LocalStruct(cgu_extern_drop_glue::Struct); + +//~ MONO_ITEM fn user @@ extern_drop_glue[External] +pub fn user() { + //~ MONO_ITEM fn std::ptr::drop_in_place::<LocalStruct> - shim(Some(LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] + let _ = LocalStruct(cgu_extern_drop_glue::Struct(0)); +} + +pub mod mod1 { + use cgu_extern_drop_glue; + + struct LocalStruct(cgu_extern_drop_glue::Struct); + + //~ MONO_ITEM fn mod1::user @@ extern_drop_glue-mod1[External] + pub fn user() { + //~ MONO_ITEM fn std::ptr::drop_in_place::<mod1::LocalStruct> - shim(Some(mod1::LocalStruct)) @@ extern_drop_glue-fallback.cgu[External] + let _ = LocalStruct(cgu_extern_drop_glue::Struct(0)); + } +} diff --git a/tests/codegen-units/partitioning/extern-generic.rs b/tests/codegen-units/partitioning/extern-generic.rs new file mode 100644 index 000000000..638ec079a --- /dev/null +++ b/tests/codegen-units/partitioning/extern-generic.rs @@ -0,0 +1,53 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=eager -Zshare-generics=y + +#![allow(dead_code)] +#![crate_type="lib"] + +// aux-build:cgu_generic_function.rs +extern crate cgu_generic_function; + +//~ MONO_ITEM fn user @@ extern_generic[Internal] +fn user() { + let _ = cgu_generic_function::foo("abc"); +} + +mod mod1 { + use cgu_generic_function; + + //~ MONO_ITEM fn mod1::user @@ extern_generic-mod1[Internal] + fn user() { + let _ = cgu_generic_function::foo("abc"); + } + + mod mod1 { + use cgu_generic_function; + + //~ MONO_ITEM fn mod1::mod1::user @@ extern_generic-mod1-mod1[Internal] + fn user() { + let _ = cgu_generic_function::foo("abc"); + } + } +} + +mod mod2 { + use cgu_generic_function; + + //~ MONO_ITEM fn mod2::user @@ extern_generic-mod2[Internal] + fn user() { + let _ = cgu_generic_function::foo("abc"); + } +} + +mod mod3 { + //~ MONO_ITEM fn mod3::non_user @@ extern_generic-mod3[Internal] + fn non_user() {} +} + +// Make sure the two generic functions from the extern crate get instantiated +// once for the current crate +//~ MONO_ITEM fn cgu_generic_function::foo::<&str> @@ cgu_generic_function-in-extern_generic.volatile[External] +//~ MONO_ITEM fn cgu_generic_function::bar::<&str> @@ cgu_generic_function-in-extern_generic.volatile[External] diff --git a/tests/codegen-units/partitioning/incremental-merging.rs b/tests/codegen-units/partitioning/incremental-merging.rs new file mode 100644 index 000000000..118b7bdf4 --- /dev/null +++ b/tests/codegen-units/partitioning/incremental-merging.rs @@ -0,0 +1,42 @@ +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Ccodegen-units=3 + +#![crate_type = "rlib"] + +// This test makes sure that merging of CGUs works together with incremental +// compilation but at the same time does not modify names of CGUs that were not +// affected by merging. +// +// We expect CGUs `aaa` and `bbb` to be merged (because they are the smallest), +// while `ccc` and `ddd` are supposed to stay untouched. + +pub mod aaa { + //~ MONO_ITEM fn aaa::foo @@ incremental_merging-aaa--incremental_merging-bbb[External] + pub fn foo(a: u64) -> u64 { + a + 1 + } +} + +pub mod bbb { + //~ MONO_ITEM fn bbb::foo @@ incremental_merging-aaa--incremental_merging-bbb[External] + pub fn foo(a: u64, b: u64) -> u64 { + a + b + 1 + } +} + +pub mod ccc { + //~ MONO_ITEM fn ccc::foo @@ incremental_merging-ccc[External] + pub fn foo(a: u64, b: u64, c: u64) -> u64 { + a + b + c + 1 + } +} + +pub mod ddd { + //~ MONO_ITEM fn ddd::foo @@ incremental_merging-ddd[External] + pub fn foo(a: u64, b: u64, c: u64, d: u64) -> u64 { + a + b + c + d + 1 + } +} diff --git a/tests/codegen-units/partitioning/inlining-from-extern-crate.rs b/tests/codegen-units/partitioning/inlining-from-extern-crate.rs new file mode 100644 index 000000000..1cc21632e --- /dev/null +++ b/tests/codegen-units/partitioning/inlining-from-extern-crate.rs @@ -0,0 +1,53 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus + +#![crate_type="lib"] + +// aux-build:cgu_explicit_inlining.rs +extern crate cgu_explicit_inlining; + +// This test makes sure that items inlined from external crates are privately +// instantiated in every codegen unit they are used in. + +//~ MONO_ITEM fn cgu_explicit_inlining::inlined @@ inlining_from_extern_crate[Internal] inlining_from_extern_crate-mod1[Internal] +//~ MONO_ITEM fn cgu_explicit_inlining::always_inlined @@ inlining_from_extern_crate[Internal] inlining_from_extern_crate-mod2[Internal] + +//~ MONO_ITEM fn user @@ inlining_from_extern_crate[External] +pub fn user() +{ + cgu_explicit_inlining::inlined(); + cgu_explicit_inlining::always_inlined(); + + // does not generate a monomorphization in this crate + cgu_explicit_inlining::never_inlined(); +} + +pub mod mod1 { + use cgu_explicit_inlining; + + //~ MONO_ITEM fn mod1::user @@ inlining_from_extern_crate-mod1[External] + pub fn user() + { + cgu_explicit_inlining::inlined(); + + // does not generate a monomorphization in this crate + cgu_explicit_inlining::never_inlined(); + } +} + +pub mod mod2 { + use cgu_explicit_inlining; + + //~ MONO_ITEM fn mod2::user @@ inlining_from_extern_crate-mod2[External] + pub fn user() + { + cgu_explicit_inlining::always_inlined(); + + // does not generate a monomorphization in this crate + cgu_explicit_inlining::never_inlined(); + } +} diff --git a/tests/codegen-units/partitioning/local-drop-glue.rs b/tests/codegen-units/partitioning/local-drop-glue.rs new file mode 100644 index 000000000..2fd853a44 --- /dev/null +++ b/tests/codegen-units/partitioning/local-drop-glue.rs @@ -0,0 +1,46 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// We specify opt-level=0 because `drop_in_place` is `Internal` when optimizing +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus -Copt-level=0 + +#![allow(dead_code)] +#![crate_type = "rlib"] + +//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct> - shim(Some(Struct)) @@ local_drop_glue-fallback.cgu[External] +struct Struct { + _a: u32, +} + +impl Drop for Struct { + //~ MONO_ITEM fn <Struct as std::ops::Drop>::drop @@ local_drop_glue-fallback.cgu[External] + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn std::ptr::drop_in_place::<Outer> - shim(Some(Outer)) @@ local_drop_glue-fallback.cgu[External] +struct Outer { + _a: Struct, +} + +//~ MONO_ITEM fn user @@ local_drop_glue[External] +pub fn user() { + let _ = Outer { _a: Struct { _a: 0 } }; +} + +pub mod mod1 { + use super::Struct; + + //~ MONO_ITEM fn std::ptr::drop_in_place::<mod1::Struct2> - shim(Some(mod1::Struct2)) @@ local_drop_glue-fallback.cgu[External] + struct Struct2 { + _a: Struct, + //~ MONO_ITEM fn std::ptr::drop_in_place::<(u32, Struct)> - shim(Some((u32, Struct))) @@ local_drop_glue-fallback.cgu[Internal] + _b: (u32, Struct), + } + + //~ MONO_ITEM fn mod1::user @@ local_drop_glue-mod1[External] + pub fn user() { + let _ = Struct2 { _a: Struct { _a: 0 }, _b: (0, Struct { _a: 0 }) }; + } +} diff --git a/tests/codegen-units/partitioning/local-generic.rs b/tests/codegen-units/partitioning/local-generic.rs new file mode 100644 index 000000000..38aec7291 --- /dev/null +++ b/tests/codegen-units/partitioning/local-generic.rs @@ -0,0 +1,45 @@ +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=eager + +#![allow(dead_code)] +#![crate_type="lib"] + +//~ MONO_ITEM fn generic::<u32> @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic::<u64> @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic::<char> @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic::<&str> @@ local_generic.volatile[External] +pub fn generic<T>(x: T) -> T { x } + +//~ MONO_ITEM fn user @@ local_generic[Internal] +fn user() { + let _ = generic(0u32); +} + +mod mod1 { + pub use super::generic; + + //~ MONO_ITEM fn mod1::user @@ local_generic-mod1[Internal] + fn user() { + let _ = generic(0u64); + } + + mod mod1 { + use super::generic; + + //~ MONO_ITEM fn mod1::mod1::user @@ local_generic-mod1-mod1[Internal] + fn user() { + let _ = generic('c'); + } + } +} + +mod mod2 { + use super::generic; + + //~ MONO_ITEM fn mod2::user @@ local_generic-mod2[Internal] + fn user() { + let _ = generic("abc"); + } +} diff --git a/tests/codegen-units/partitioning/local-inlining-but-not-all.rs b/tests/codegen-units/partitioning/local-inlining-but-not-all.rs new file mode 100644 index 000000000..318f0c28a --- /dev/null +++ b/tests/codegen-units/partitioning/local-inlining-but-not-all.rs @@ -0,0 +1,45 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus=no + +#![allow(dead_code)] +#![crate_type="lib"] + +mod inline { + + //~ MONO_ITEM fn inline::inlined_function @@ local_inlining_but_not_all-inline[External] + #[inline] + pub fn inlined_function() + { + + } +} + +pub mod user1 { + use super::inline; + + //~ MONO_ITEM fn user1::foo @@ local_inlining_but_not_all-user1[External] + pub fn foo() { + inline::inlined_function(); + } +} + +pub mod user2 { + use super::inline; + + //~ MONO_ITEM fn user2::bar @@ local_inlining_but_not_all-user2[External] + pub fn bar() { + inline::inlined_function(); + } +} + +pub mod non_user { + + //~ MONO_ITEM fn non_user::baz @@ local_inlining_but_not_all-non_user[External] + pub fn baz() { + + } +} diff --git a/tests/codegen-units/partitioning/local-inlining.rs b/tests/codegen-units/partitioning/local-inlining.rs new file mode 100644 index 000000000..841a428e9 --- /dev/null +++ b/tests/codegen-units/partitioning/local-inlining.rs @@ -0,0 +1,46 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus + +#![allow(dead_code)] +#![crate_type="lib"] + +mod inline { + + // Important: This function should show up in all codegen units where it is inlined + //~ MONO_ITEM fn inline::inlined_function @@ local_inlining-user1[Internal] local_inlining-user2[Internal] + #[inline(always)] + pub fn inlined_function() + { + + } +} + +pub mod user1 { + use super::inline; + + //~ MONO_ITEM fn user1::foo @@ local_inlining-user1[External] + pub fn foo() { + inline::inlined_function(); + } +} + +pub mod user2 { + use super::inline; + + //~ MONO_ITEM fn user2::bar @@ local_inlining-user2[External] + pub fn bar() { + inline::inlined_function(); + } +} + +pub mod non_user { + + //~ MONO_ITEM fn non_user::baz @@ local_inlining-non_user[External] + pub fn baz() { + + } +} diff --git a/tests/codegen-units/partitioning/local-transitive-inlining.rs b/tests/codegen-units/partitioning/local-transitive-inlining.rs new file mode 100644 index 000000000..03c37954d --- /dev/null +++ b/tests/codegen-units/partitioning/local-transitive-inlining.rs @@ -0,0 +1,46 @@ +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus + +#![allow(dead_code)] +#![crate_type="rlib"] + +mod inline { + + //~ MONO_ITEM fn inline::inlined_function @@ local_transitive_inlining-indirect_user[Internal] + #[inline(always)] + pub fn inlined_function() + { + + } +} + +mod direct_user { + use super::inline; + + //~ MONO_ITEM fn direct_user::foo @@ local_transitive_inlining-indirect_user[Internal] + #[inline(always)] + pub fn foo() { + inline::inlined_function(); + } +} + +pub mod indirect_user { + use super::direct_user; + + //~ MONO_ITEM fn indirect_user::bar @@ local_transitive_inlining-indirect_user[External] + pub fn bar() { + direct_user::foo(); + } +} + +pub mod non_user { + + //~ MONO_ITEM fn non_user::baz @@ local_transitive_inlining-non_user[External] + pub fn baz() { + + } +} diff --git a/tests/codegen-units/partitioning/methods-are-with-self-type.rs b/tests/codegen-units/partitioning/methods-are-with-self-type.rs new file mode 100644 index 000000000..8220dc12e --- /dev/null +++ b/tests/codegen-units/partitioning/methods-are-with-self-type.rs @@ -0,0 +1,79 @@ +// Currently, all generic functions are instantiated in each codegen unit that +// uses them, even those not marked with #[inline], so this test does not make +// much sense at the moment. +// ignore-test + +// +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy + +#![allow(dead_code)] +#![feature(start)] + +struct SomeType; + +struct SomeGenericType<T1, T2>(T1, T2); + +mod mod1 { + use super::{SomeType, SomeGenericType}; + + // Even though the impl is in `mod1`, the methods should end up in the + // parent module, since that is where their self-type is. + impl SomeType { + //~ MONO_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[0]::method[0] @@ methods_are_with_self_type[External] + fn method(&self) {} + + //~ MONO_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[0]::associated_fn[0] @@ methods_are_with_self_type[External] + fn associated_fn() {} + } + + impl<T1, T2> SomeGenericType<T1, T2> { + pub fn method(&self) {} + pub fn associated_fn(_: T1, _: T2) {} + } +} + +trait Trait { + fn foo(&self); + fn default(&self) {} +} + +// We provide an implementation of `Trait` for all types. The corresponding +// monomorphizations should end up in whichever module the concrete `T` is. +impl<T> Trait for T +{ + fn foo(&self) {} +} + +mod type1 { + pub struct Struct; +} + +mod type2 { + pub struct Struct; +} + +//~ MONO_ITEM fn methods_are_with_self_type::start[0] +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[1]::method[0]<u32, u64> @@ methods_are_with_self_type.volatile[WeakODR] + SomeGenericType(0u32, 0u64).method(); + //~ MONO_ITEM fn methods_are_with_self_type::mod1[0]::{{impl}}[1]::associated_fn[0]<char, &str> @@ methods_are_with_self_type.volatile[WeakODR] + SomeGenericType::associated_fn('c', "&str"); + + //~ MONO_ITEM fn methods_are_with_self_type::{{impl}}[0]::foo[0]<methods_are_with_self_type::type1[0]::Struct[0]> @@ methods_are_with_self_type-type1.volatile[WeakODR] + type1::Struct.foo(); + //~ MONO_ITEM fn methods_are_with_self_type::{{impl}}[0]::foo[0]<methods_are_with_self_type::type2[0]::Struct[0]> @@ methods_are_with_self_type-type2.volatile[WeakODR] + type2::Struct.foo(); + + //~ MONO_ITEM fn methods_are_with_self_type::Trait[0]::default[0]<methods_are_with_self_type::type1[0]::Struct[0]> @@ methods_are_with_self_type-type1.volatile[WeakODR] + type1::Struct.default(); + //~ MONO_ITEM fn methods_are_with_self_type::Trait[0]::default[0]<methods_are_with_self_type::type2[0]::Struct[0]> @@ methods_are_with_self_type-type2.volatile[WeakODR] + type2::Struct.default(); + + 0 +} + +//~ MONO_ITEM drop-glue i8 diff --git a/tests/codegen-units/partitioning/regular-modules.rs b/tests/codegen-units/partitioning/regular-modules.rs new file mode 100644 index 000000000..ce7fe9c3a --- /dev/null +++ b/tests/codegen-units/partitioning/regular-modules.rs @@ -0,0 +1,72 @@ +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=eager + +#![allow(dead_code)] +#![crate_type="lib"] + +//~ MONO_ITEM fn foo @@ regular_modules[Internal] +fn foo() {} + +//~ MONO_ITEM fn bar @@ regular_modules[Internal] +fn bar() {} + +//~ MONO_ITEM static BAZ @@ regular_modules[Internal] +static BAZ: u64 = 0; + +mod mod1 { + + //~ MONO_ITEM fn mod1::foo @@ regular_modules-mod1[Internal] + fn foo() {} + //~ MONO_ITEM fn mod1::bar @@ regular_modules-mod1[Internal] + fn bar() {} + //~ MONO_ITEM static mod1::BAZ @@ regular_modules-mod1[Internal] + static BAZ: u64 = 0; + + mod mod1 { + //~ MONO_ITEM fn mod1::mod1::foo @@ regular_modules-mod1-mod1[Internal] + fn foo() {} + //~ MONO_ITEM fn mod1::mod1::bar @@ regular_modules-mod1-mod1[Internal] + fn bar() {} + //~ MONO_ITEM static mod1::mod1::BAZ @@ regular_modules-mod1-mod1[Internal] + static BAZ: u64 = 0; + } + + mod mod2 { + //~ MONO_ITEM fn mod1::mod2::foo @@ regular_modules-mod1-mod2[Internal] + fn foo() {} + //~ MONO_ITEM fn mod1::mod2::bar @@ regular_modules-mod1-mod2[Internal] + fn bar() {} + //~ MONO_ITEM static mod1::mod2::BAZ @@ regular_modules-mod1-mod2[Internal] + static BAZ: u64 = 0; + } +} + +mod mod2 { + + //~ MONO_ITEM fn mod2::foo @@ regular_modules-mod2[Internal] + fn foo() {} + //~ MONO_ITEM fn mod2::bar @@ regular_modules-mod2[Internal] + fn bar() {} + //~ MONO_ITEM static mod2::BAZ @@ regular_modules-mod2[Internal] + static BAZ: u64 = 0; + + mod mod1 { + //~ MONO_ITEM fn mod2::mod1::foo @@ regular_modules-mod2-mod1[Internal] + fn foo() {} + //~ MONO_ITEM fn mod2::mod1::bar @@ regular_modules-mod2-mod1[Internal] + fn bar() {} + //~ MONO_ITEM static mod2::mod1::BAZ @@ regular_modules-mod2-mod1[Internal] + static BAZ: u64 = 0; + } + + mod mod2 { + //~ MONO_ITEM fn mod2::mod2::foo @@ regular_modules-mod2-mod2[Internal] + fn foo() {} + //~ MONO_ITEM fn mod2::mod2::bar @@ regular_modules-mod2-mod2[Internal] + fn bar() {} + //~ MONO_ITEM static mod2::mod2::BAZ @@ regular_modules-mod2-mod2[Internal] + static BAZ: u64 = 0; + } +} diff --git a/tests/codegen-units/partitioning/shared-generics.rs b/tests/codegen-units/partitioning/shared-generics.rs new file mode 100644 index 000000000..ebe96bfb7 --- /dev/null +++ b/tests/codegen-units/partitioning/shared-generics.rs @@ -0,0 +1,28 @@ +// +// no-prefer-dynamic +// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels +// prevent drop-glue from participating in share-generics. +// incremental +// compile-flags:-Zprint-mono-items=eager -Zshare-generics=yes -Copt-level=0 + +#![crate_type="rlib"] + +// aux-build:shared_generics_aux.rs +extern crate shared_generics_aux; + +//~ MONO_ITEM fn foo +pub fn foo() { + + //~ MONO_ITEM fn shared_generics_aux::generic_fn::<u16> @@ shared_generics_aux-in-shared_generics.volatile[External] + let _ = shared_generics_aux::generic_fn(0u16, 1u16); + + // 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); + + // 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); +} diff --git a/tests/codegen-units/partitioning/statics.rs b/tests/codegen-units/partitioning/statics.rs new file mode 100644 index 000000000..b11d6696d --- /dev/null +++ b/tests/codegen-units/partitioning/statics.rs @@ -0,0 +1,38 @@ +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy + +#![crate_type="rlib"] + +//~ MONO_ITEM static FOO @@ statics[Internal] +static FOO: u32 = 0; + +//~ MONO_ITEM static BAR @@ statics[Internal] +static BAR: u32 = 0; + +//~ MONO_ITEM fn function @@ statics[External] +pub fn function() { + //~ MONO_ITEM static function::FOO @@ statics[Internal] + static FOO: u32 = 0; + + //~ MONO_ITEM static function::BAR @@ statics[Internal] + static BAR: u32 = 0; +} + +pub mod mod1 { + //~ MONO_ITEM static mod1::FOO @@ statics-mod1[Internal] + static FOO: u32 = 0; + + //~ MONO_ITEM static mod1::BAR @@ statics-mod1[Internal] + static BAR: u32 = 0; + + //~ MONO_ITEM fn mod1::function @@ statics-mod1[External] + pub fn function() { + //~ MONO_ITEM static mod1::function::FOO @@ statics-mod1[Internal] + static FOO: u32 = 0; + + //~ MONO_ITEM static mod1::function::BAR @@ statics-mod1[Internal] + static BAR: u32 = 0; + } +} diff --git a/tests/codegen-units/partitioning/vtable-through-const.rs b/tests/codegen-units/partitioning/vtable-through-const.rs new file mode 100644 index 000000000..cedcca804 --- /dev/null +++ b/tests/codegen-units/partitioning/vtable-through-const.rs @@ -0,0 +1,94 @@ +// + +// We specify incremental here because we want to test the partitioning for +// incremental compilation +// incremental +// compile-flags:-Zprint-mono-items=lazy +// compile-flags:-Zinline-in-all-cgus + +// This test case makes sure, that references made through constants are +// recorded properly in the InliningMap. + +#![feature(start)] + +mod mod1 { + pub trait Trait1 { + fn do_something(&self) {} + fn do_something_else(&self) {} + } + + impl Trait1 for u32 {} + + pub trait Trait1Gen<T> { + fn do_something(&self, x: T) -> T; + fn do_something_else(&self, x: T) -> T; + } + + impl<T> Trait1Gen<T> for u32 { + fn do_something(&self, x: T) -> T { x } + fn do_something_else(&self, x: T) -> T { x } + } + + //~ MONO_ITEM fn mod1::id::<i64> @@ vtable_through_const-mod1.volatile[Internal] + fn id<T>(x: T) -> T { x } + + // These are referenced, so they produce mono-items (see start()) + pub const TRAIT1_REF: &'static Trait1 = &0u32 as &Trait1; + pub const TRAIT1_GEN_REF: &'static Trait1Gen<u8> = &0u32 as &Trait1Gen<u8>; + pub const ID_CHAR: fn(char) -> char = id::<char>; + + + + pub trait Trait2 { + fn do_something(&self) {} + fn do_something_else(&self) {} + } + + //~ MONO_ITEM fn <u32 as mod1::Trait2>::do_something @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn <u32 as mod1::Trait2>::do_something_else @@ vtable_through_const-mod1.volatile[Internal] + impl Trait2 for u32 {} + + pub trait Trait2Gen<T> { + fn do_something(&self, x: T) -> T; + fn do_something_else(&self, x: T) -> T; + } + + impl<T> Trait2Gen<T> for u32 { + fn do_something(&self, x: T) -> T { x } + fn do_something_else(&self, x: T) -> T { x } + } + + // These are not referenced, so they do not produce mono-items + pub const TRAIT2_REF: &'static Trait2 = &0u32 as &Trait2; + pub const TRAIT2_GEN_REF: &'static Trait2Gen<u8> = &0u32 as &Trait2Gen<u8>; + pub const ID_I64: fn(i64) -> i64 = id::<i64>; +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn std::ptr::drop_in_place::<u32> - shim(None) @@ vtable_through_const[Internal] + + // Since Trait1::do_something() is instantiated via its default implementation, + // it is considered a generic and is instantiated here only because it is + // referenced in this module. + //~ MONO_ITEM fn <u32 as mod1::Trait1>::do_something_else @@ vtable_through_const-mod1.volatile[External] + + // Although it is never used, Trait1::do_something_else() has to be + // instantiated locally here too, otherwise the <&u32 as &Trait1> vtable + // could not be fully constructed. + //~ MONO_ITEM fn <u32 as mod1::Trait1>::do_something @@ vtable_through_const-mod1.volatile[External] + mod1::TRAIT1_REF.do_something(); + + // Same as above + //~ MONO_ITEM fn <u32 as mod1::Trait1Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[External] + //~ MONO_ITEM fn <u32 as mod1::Trait1Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[External] + //~ MONO_ITEM fn <u32 as mod1::Trait2Gen<u8>>::do_something @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn <u32 as mod1::Trait2Gen<u8>>::do_something_else @@ vtable_through_const-mod1.volatile[Internal] + mod1::TRAIT1_GEN_REF.do_something(0u8); + + //~ MONO_ITEM fn mod1::id::<char> @@ vtable_through_const-mod1.volatile[External] + mod1::ID_CHAR('x'); + + 0 +} |