From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/codegen-units/item-collection/asm-sym.rs | 20 ++ .../auxiliary/cgu_export_trait_method.rs | 24 ++ .../auxiliary/cgu_extern_closures.rs | 23 ++ .../auxiliary/cgu_generic_function.rs | 26 ++ .../item-collection/cross-crate-closures.rs | 33 +++ .../cross-crate-generic-functions.rs | 24 ++ .../item-collection/cross-crate-trait-method.rs | 50 ++++ .../item-collection/drop_in_place_intrinsic.rs | 36 +++ .../item-collection/function-as-argument.rs | 40 +++ .../item-collection/generic-drop-glue.rs | 91 ++++++ .../item-collection/generic-functions.rs | 55 ++++ .../codegen-units/item-collection/generic-impl.rs | 71 +++++ .../impl-in-non-instantiated-generic.rs | 27 ++ .../item-collection/implicit-panic-call.rs | 58 ++++ .../instantiation-through-vtable.rs | 38 +++ .../item-collection/items-within-generic-items.rs | 35 +++ .../item-collection/non-generic-closures.rs | 60 ++++ .../item-collection/non-generic-drop-glue.rs | 49 ++++ .../item-collection/non-generic-functions.rs | 72 +++++ .../item-collection/overloaded-operators.rs | 59 ++++ tests/codegen-units/item-collection/static-init.rs | 16 + .../item-collection/statics-and-consts.rs | 54 ++++ .../item-collection/trait-implementations.rs | 73 +++++ .../item-collection/trait-method-as-argument.rs | 60 ++++ .../item-collection/trait-method-default-impl.rs | 61 ++++ .../item-collection/transitive-drop-glue.rs | 46 +++ .../item-collection/tuple-drop-glue.rs | 27 ++ .../item-collection/unreferenced-const-fn.rs | 9 + .../unreferenced-inline-function.rs | 11 + tests/codegen-units/item-collection/unsizing.rs | 79 +++++ .../item-collection/unused-traits-and-generics.rs | 77 +++++ .../auxiliary/cgu_explicit_inlining.rs | 10 + .../partitioning/auxiliary/cgu_extern_drop_glue.rs | 7 + .../partitioning/auxiliary/cgu_generic_function.rs | 26 ++ .../partitioning/auxiliary/shared_generics_aux.rs | 26 ++ .../codegen-units/partitioning/extern-drop-glue.rs | 36 +++ tests/codegen-units/partitioning/extern-generic.rs | 53 ++++ .../partitioning/incremental-merging.rs | 42 +++ .../partitioning/inlining-from-extern-crate.rs | 53 ++++ .../codegen-units/partitioning/local-drop-glue.rs | 46 +++ tests/codegen-units/partitioning/local-generic.rs | 45 +++ .../partitioning/local-inlining-but-not-all.rs | 45 +++ tests/codegen-units/partitioning/local-inlining.rs | 46 +++ .../partitioning/local-transitive-inlining.rs | 46 +++ .../partitioning/methods-are-with-self-type.rs | 79 +++++ .../codegen-units/partitioning/regular-modules.rs | 72 +++++ .../codegen-units/partitioning/shared-generics.rs | 28 ++ tests/codegen-units/partitioning/statics.rs | 38 +++ .../partitioning/vtable-through-const.rs | 94 ++++++ .../polymorphization/unused_type_parameters.rs | 322 +++++++++++++++++++++ 50 files changed, 2518 insertions(+) create mode 100644 tests/codegen-units/item-collection/asm-sym.rs create mode 100644 tests/codegen-units/item-collection/auxiliary/cgu_export_trait_method.rs create mode 100644 tests/codegen-units/item-collection/auxiliary/cgu_extern_closures.rs create mode 100644 tests/codegen-units/item-collection/auxiliary/cgu_generic_function.rs create mode 100644 tests/codegen-units/item-collection/cross-crate-closures.rs create mode 100644 tests/codegen-units/item-collection/cross-crate-generic-functions.rs create mode 100644 tests/codegen-units/item-collection/cross-crate-trait-method.rs create mode 100644 tests/codegen-units/item-collection/drop_in_place_intrinsic.rs create mode 100644 tests/codegen-units/item-collection/function-as-argument.rs create mode 100644 tests/codegen-units/item-collection/generic-drop-glue.rs create mode 100644 tests/codegen-units/item-collection/generic-functions.rs create mode 100644 tests/codegen-units/item-collection/generic-impl.rs create mode 100644 tests/codegen-units/item-collection/impl-in-non-instantiated-generic.rs create mode 100644 tests/codegen-units/item-collection/implicit-panic-call.rs create mode 100644 tests/codegen-units/item-collection/instantiation-through-vtable.rs create mode 100644 tests/codegen-units/item-collection/items-within-generic-items.rs create mode 100644 tests/codegen-units/item-collection/non-generic-closures.rs create mode 100644 tests/codegen-units/item-collection/non-generic-drop-glue.rs create mode 100644 tests/codegen-units/item-collection/non-generic-functions.rs create mode 100644 tests/codegen-units/item-collection/overloaded-operators.rs create mode 100644 tests/codegen-units/item-collection/static-init.rs create mode 100644 tests/codegen-units/item-collection/statics-and-consts.rs create mode 100644 tests/codegen-units/item-collection/trait-implementations.rs create mode 100644 tests/codegen-units/item-collection/trait-method-as-argument.rs create mode 100644 tests/codegen-units/item-collection/trait-method-default-impl.rs create mode 100644 tests/codegen-units/item-collection/transitive-drop-glue.rs create mode 100644 tests/codegen-units/item-collection/tuple-drop-glue.rs create mode 100644 tests/codegen-units/item-collection/unreferenced-const-fn.rs create mode 100644 tests/codegen-units/item-collection/unreferenced-inline-function.rs create mode 100644 tests/codegen-units/item-collection/unsizing.rs create mode 100644 tests/codegen-units/item-collection/unused-traits-and-generics.rs create mode 100644 tests/codegen-units/partitioning/auxiliary/cgu_explicit_inlining.rs create mode 100644 tests/codegen-units/partitioning/auxiliary/cgu_extern_drop_glue.rs create mode 100644 tests/codegen-units/partitioning/auxiliary/cgu_generic_function.rs create mode 100644 tests/codegen-units/partitioning/auxiliary/shared_generics_aux.rs create mode 100644 tests/codegen-units/partitioning/extern-drop-glue.rs create mode 100644 tests/codegen-units/partitioning/extern-generic.rs create mode 100644 tests/codegen-units/partitioning/incremental-merging.rs create mode 100644 tests/codegen-units/partitioning/inlining-from-extern-crate.rs create mode 100644 tests/codegen-units/partitioning/local-drop-glue.rs create mode 100644 tests/codegen-units/partitioning/local-generic.rs create mode 100644 tests/codegen-units/partitioning/local-inlining-but-not-all.rs create mode 100644 tests/codegen-units/partitioning/local-inlining.rs create mode 100644 tests/codegen-units/partitioning/local-transitive-inlining.rs create mode 100644 tests/codegen-units/partitioning/methods-are-with-self-type.rs create mode 100644 tests/codegen-units/partitioning/regular-modules.rs create mode 100644 tests/codegen-units/partitioning/shared-generics.rs create mode 100644 tests/codegen-units/partitioning/statics.rs create mode 100644 tests/codegen-units/partitioning/vtable-through-const.rs create mode 100644 tests/codegen-units/polymorphization/unused_type_parameters.rs (limited to 'tests/codegen-units') diff --git a/tests/codegen-units/item-collection/asm-sym.rs b/tests/codegen-units/item-collection/asm-sym.rs new file mode 100644 index 000000000..8bafb95bc --- /dev/null +++ b/tests/codegen-units/item-collection/asm-sym.rs @@ -0,0 +1,20 @@ +// needs-asm-support +// compile-flags: -Ccodegen-units=1 -Zprint-mono-items=lazy --crate-type=lib + +#[inline(always)] +pub unsafe fn f() { + //~ MONO_ITEM static f::S @@ asm_sym-cgu.0[External] + static S: usize = 1; + //~ MONO_ITEM fn f::fun @@ asm_sym-cgu.0[External] + fn fun() {} + core::arch::asm!("/* {0} {1} */", sym S, sym fun); +} + +//~ MONO_ITEM fn g @@ asm_sym-cgu.0[External] +pub unsafe fn g() { + //~ MONO_ITEM static g::S @@ asm_sym-cgu.0[Internal] + static S: usize = 2; + //~ MONO_ITEM fn g::fun @@ asm_sym-cgu.0[Internal] + fn fun() {} + core::arch::asm!("/* {0} {1} */", sym S, sym fun); +} diff --git a/tests/codegen-units/item-collection/auxiliary/cgu_export_trait_method.rs b/tests/codegen-units/item-collection/auxiliary/cgu_export_trait_method.rs new file mode 100644 index 000000000..ecea26dc4 --- /dev/null +++ b/tests/codegen-units/item-collection/auxiliary/cgu_export_trait_method.rs @@ -0,0 +1,24 @@ +#![crate_type = "lib"] + +pub trait Trait : Sized { + fn without_self() -> u32; + fn without_self_default() -> u32 { 0 } + + fn with_default_impl(self) -> Self { self } + fn with_default_impl_generic(self, x: T) -> (Self, T) { (self, x) } + + fn without_default_impl(x: u32) -> (Self, u32); + fn without_default_impl_generic(x: T) -> (Self, T); +} + +impl Trait for char { + fn without_self() -> u32 { 2 } + fn without_default_impl(x: u32) -> (Self, u32) { ('c', x) } + fn without_default_impl_generic(x: T) -> (Self, T) { ('c', x) } +} + +impl Trait for u32 { + fn without_self() -> u32 { 1 } + fn without_default_impl(x: u32) -> (Self, u32) { (0, x) } + fn without_default_impl_generic(x: T) -> (Self, T) { (0, x) } +} diff --git a/tests/codegen-units/item-collection/auxiliary/cgu_extern_closures.rs b/tests/codegen-units/item-collection/auxiliary/cgu_extern_closures.rs new file mode 100644 index 000000000..05ea0a89f --- /dev/null +++ b/tests/codegen-units/item-collection/auxiliary/cgu_extern_closures.rs @@ -0,0 +1,23 @@ +#![crate_type = "lib"] + +#[inline] +pub fn inlined_fn(x: i32, y: i32) -> i32 { + + let closure = |a, b| { a + b }; + + closure(x, y) +} + +pub fn inlined_fn_generic(x: i32, y: i32, z: T) -> (i32, T) { + + let closure = |a, b| { a + b }; + + (closure(x, y), z) +} + +pub fn non_inlined_fn(x: i32, y: i32) -> i32 { + + let closure = |a, b| { a + b }; + + closure(x, y) +} diff --git a/tests/codegen-units/item-collection/auxiliary/cgu_generic_function.rs b/tests/codegen-units/item-collection/auxiliary/cgu_generic_function.rs new file mode 100644 index 000000000..3926f2957 --- /dev/null +++ b/tests/codegen-units/item-collection/auxiliary/cgu_generic_function.rs @@ -0,0 +1,26 @@ +#![crate_type = "lib"] + +struct Struct(u32); + +#[inline(never)] +pub fn foo(x: T) -> (T, u32, i8) { + let (x, Struct(y)) = bar(x); + (x, y, 2) +} + +#[inline(never)] +fn bar(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/item-collection/cross-crate-closures.rs b/tests/codegen-units/item-collection/cross-crate-closures.rs new file mode 100644 index 000000000..6af344fab --- /dev/null +++ b/tests/codegen-units/item-collection/cross-crate-closures.rs @@ -0,0 +1,33 @@ +// In the current version of the collector that still has to support +// legacy-codegen, closures do not generate their own MonoItems, so we are +// ignoring this test until MIR codegen has taken over completely +// ignore-test + +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +// aux-build:cgu_extern_closures.rs +extern crate cgu_extern_closures; + +//~ MONO_ITEM fn cross_crate_closures::start[0] +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + + //~ MONO_ITEM fn cgu_extern_closures::inlined_fn[0] + //~ MONO_ITEM fn cgu_extern_closures::inlined_fn[0]::{{closure}}[0] + let _ = cgu_extern_closures::inlined_fn(1, 2); + + //~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic[0] + //~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic[0]::{{closure}}[0] + let _ = cgu_extern_closures::inlined_fn_generic(3, 4, 5i32); + + // Nothing should be generated for this call, we just link to the instance + // in the extern crate. + let _ = cgu_extern_closures::non_inlined_fn(6, 7); + + 0 +} + +//~ MONO_ITEM drop-glue i8 diff --git a/tests/codegen-units/item-collection/cross-crate-generic-functions.rs b/tests/codegen-units/item-collection/cross-crate-generic-functions.rs new file mode 100644 index 000000000..7289ceee9 --- /dev/null +++ b/tests/codegen-units/item-collection/cross-crate-generic-functions.rs @@ -0,0 +1,24 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +// aux-build:cgu_generic_function.rs +extern crate cgu_generic_function; + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn cgu_generic_function::bar:: + //~ MONO_ITEM fn cgu_generic_function::foo:: + let _ = cgu_generic_function::foo(1u32); + + //~ MONO_ITEM fn cgu_generic_function::bar:: + //~ MONO_ITEM fn cgu_generic_function::foo:: + let _ = cgu_generic_function::foo(2u64); + + // This should not introduce a codegen item + let _ = cgu_generic_function::exported_but_not_generic(3); + + 0 +} diff --git a/tests/codegen-units/item-collection/cross-crate-trait-method.rs b/tests/codegen-units/item-collection/cross-crate-trait-method.rs new file mode 100644 index 000000000..dc0984c8a --- /dev/null +++ b/tests/codegen-units/item-collection/cross-crate-trait-method.rs @@ -0,0 +1,50 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +// aux-build:cgu_export_trait_method.rs +extern crate cgu_export_trait_method; + +use cgu_export_trait_method::Trait; + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + // The object code of these methods is contained in the external crate, so + // calling them should *not* introduce codegen items in the current crate. + let _: (u32, u32) = Trait::without_default_impl(0); + let _: (char, u32) = Trait::without_default_impl(0); + + // Currently, no object code is generated for trait methods with default + // implementations, unless they are actually called from somewhere. Therefore + // we cannot import the implementations and have to create our own inline. + //~ MONO_ITEM fn ::with_default_impl + let _ = Trait::with_default_impl(0u32); + //~ MONO_ITEM fn ::with_default_impl + let _ = Trait::with_default_impl('c'); + + + + //~ MONO_ITEM fn ::with_default_impl_generic::<&str> + let _ = Trait::with_default_impl_generic(0u32, "abc"); + //~ MONO_ITEM fn ::with_default_impl_generic:: + let _ = Trait::with_default_impl_generic(0u32, false); + + //~ MONO_ITEM fn ::with_default_impl_generic:: + let _ = Trait::with_default_impl_generic('x', 1i16); + //~ MONO_ITEM fn ::with_default_impl_generic:: + let _ = Trait::with_default_impl_generic('y', 0i32); + + //~ MONO_ITEM fn ::without_default_impl_generic:: + let _: (u32, char) = Trait::without_default_impl_generic('c'); + //~ MONO_ITEM fn ::without_default_impl_generic:: + let _: (u32, bool) = Trait::without_default_impl_generic(false); + + //~ MONO_ITEM fn ::without_default_impl_generic:: + let _: (char, char) = Trait::without_default_impl_generic('c'); + //~ MONO_ITEM fn ::without_default_impl_generic:: + let _: (char, bool) = Trait::without_default_impl_generic(false); + + 0 +} diff --git a/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs b/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs new file mode 100644 index 000000000..a3f1fb5e7 --- /dev/null +++ b/tests/codegen-units/item-collection/drop_in_place_intrinsic.rs @@ -0,0 +1,36 @@ +// +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus + +#![feature(start)] + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(StructWithDtor)) @@ drop_in_place_intrinsic-cgu.0[Internal] +struct StructWithDtor(u32); + +impl Drop for StructWithDtor { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + + //~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor; 2]> - shim(Some([StructWithDtor; 2])) @@ drop_in_place_intrinsic-cgu.0[Internal] + let x = [StructWithDtor(0), StructWithDtor(1)]; + + drop_slice_in_place(&x); + + 0 +} + +//~ MONO_ITEM fn drop_slice_in_place +fn drop_slice_in_place(x: &[StructWithDtor]) { + unsafe { + // This is the interesting thing in this test case: Normally we would + // not have drop-glue for the unsized [StructWithDtor]. This has to be + // generated though when the drop_in_place() intrinsic is used. + //~ MONO_ITEM fn std::ptr::drop_in_place::<[StructWithDtor]> - shim(Some([StructWithDtor])) @@ drop_in_place_intrinsic-cgu.0[Internal] + ::std::ptr::drop_in_place(x as *const _ as *mut [StructWithDtor]); + } +} diff --git a/tests/codegen-units/item-collection/function-as-argument.rs b/tests/codegen-units/item-collection/function-as-argument.rs new file mode 100644 index 000000000..ea500c311 --- /dev/null +++ b/tests/codegen-units/item-collection/function-as-argument.rs @@ -0,0 +1,40 @@ +// +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +fn take_fn_once(f: F, x: T1, y: T2) { + (f)(x, y) +} + +fn function(_: T1, _: T2) {} + +fn take_fn_pointer(f: fn(T1, T2), x: T1, y: T2) { + (f)(x, y) +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + + //~ MONO_ITEM fn take_fn_once::}> + //~ MONO_ITEM fn function:: + //~ MONO_ITEM fn } as std::ops::FnOnce<(u32, &str)>>::call_once - shim(fn(u32, &str) {function::}) + take_fn_once(function, 0u32, "abc"); + + //~ MONO_ITEM fn take_fn_once::}> + //~ MONO_ITEM fn function:: + //~ MONO_ITEM fn } as std::ops::FnOnce<(char, f64)>>::call_once - shim(fn(char, f64) {function::}) + take_fn_once(function, 'c', 0f64); + + //~ MONO_ITEM fn take_fn_pointer:: + //~ MONO_ITEM fn function:: + take_fn_pointer(function, 0i32, ()); + + //~ MONO_ITEM fn take_fn_pointer:: + //~ MONO_ITEM fn function:: + take_fn_pointer(function, 0f32, 0i64); + + 0 +} diff --git a/tests/codegen-units/item-collection/generic-drop-glue.rs b/tests/codegen-units/item-collection/generic-drop-glue.rs new file mode 100644 index 000000000..6df4ff7e5 --- /dev/null +++ b/tests/codegen-units/item-collection/generic-drop-glue.rs @@ -0,0 +1,91 @@ +// +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus + +#![deny(dead_code)] +#![feature(start)] + +struct StructWithDrop { + x: T1, + y: T2, +} + +impl Drop for StructWithDrop { + fn drop(&mut self) {} +} + +struct StructNoDrop { + x: T1, + y: T2, +} + +enum EnumWithDrop { + A(T1), + B(T2) +} + +impl Drop for EnumWithDrop { + fn drop(&mut self) {} +} + +enum EnumNoDrop { + A(T1), + B(T2) +} + + +struct NonGenericNoDrop(#[allow(unused_tuple_struct_fields)] i32); + +struct NonGenericWithDrop(#[allow(unused_tuple_struct_fields)] i32); +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(NonGenericWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + +impl Drop for NonGenericWithDrop { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = StructWithDrop { x: 0i8, y: 'a' }.x; + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructWithDrop<&str, NonGenericNoDrop>)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = StructWithDrop { x: "&str", y: NonGenericNoDrop(0) }.y; + + // Should produce no drop glue + let _ = StructNoDrop { x: 'a', y: 0u32 }.x; + + // This is supposed to generate drop-glue because it contains a field that + // needs to be dropped. + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(StructNoDrop)) @@ generic_drop_glue-cgu.0[Internal] + let _ = StructNoDrop { x: NonGenericWithDrop(0), y: 0f64 }.y; + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = match EnumWithDrop::A::(0) { + EnumWithDrop::A(x) => x, + EnumWithDrop::B(x) => x as i32 + }; + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(EnumWithDrop)) @@ generic_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = match EnumWithDrop::B::(1.0) { + EnumWithDrop::A(x) => x, + EnumWithDrop::B(x) => x as f64 + }; + + let _ = match EnumNoDrop::A::(0) { + EnumNoDrop::A(x) => x, + EnumNoDrop::B(x) => x as i32 + }; + + let _ = match EnumNoDrop::B::(1.0) { + EnumNoDrop::A(x) => x, + EnumNoDrop::B(x) => x as f64 + }; + + 0 +} diff --git a/tests/codegen-units/item-collection/generic-functions.rs b/tests/codegen-units/item-collection/generic-functions.rs new file mode 100644 index 000000000..04383bb8e --- /dev/null +++ b/tests/codegen-units/item-collection/generic-functions.rs @@ -0,0 +1,55 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +fn foo1(a: T1) -> (T1, u32) { + (a, 1) +} + +fn foo2(a: T1, b: T2) -> (T1, T2) { + (a, b) +} + +fn foo3(a: T1, b: T2, c: T3) -> (T1, T2, T3) { + (a, b, c) +} + +// This function should be instantiated even if no used +//~ MONO_ITEM fn lifetime_only +pub fn lifetime_only<'a>(a: &'a u32) -> &'a u32 { + a +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn foo1:: + let _ = foo1(2i32); + //~ MONO_ITEM fn foo1:: + let _ = foo1(2i64); + //~ MONO_ITEM fn foo1::<&str> + let _ = foo1("abc"); + //~ MONO_ITEM fn foo1:: + let _ = foo1('v'); + + //~ MONO_ITEM fn foo2:: + let _ = foo2(2i32, 2i32); + //~ MONO_ITEM fn foo2:: + let _ = foo2(2i64, "abc"); + //~ MONO_ITEM fn foo2::<&str, usize> + let _ = foo2("a", 2usize); + //~ MONO_ITEM fn foo2:: + let _ = foo2('v', ()); + + //~ MONO_ITEM fn foo3:: + let _ = foo3(2i32, 2i32, 2i32); + //~ MONO_ITEM fn foo3:: + let _ = foo3(2i64, "abc", 'c'); + //~ MONO_ITEM fn foo3:: + let _ = foo3(0i16, "a", 2usize); + //~ MONO_ITEM fn foo3:: + let _ = foo3('v', (), ()); + + 0 +} diff --git a/tests/codegen-units/item-collection/generic-impl.rs b/tests/codegen-units/item-collection/generic-impl.rs new file mode 100644 index 000000000..4260230c2 --- /dev/null +++ b/tests/codegen-units/item-collection/generic-impl.rs @@ -0,0 +1,71 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +struct Struct { + x: T, + f: fn(x: T) -> T, +} + +fn id(x: T) -> T { x } + +impl Struct { + + fn new(x: T) -> Struct { + Struct { + x: x, + f: id + } + } + + fn get(self, x: T2) -> (T, T2) { + (self.x, x) + } +} + +pub struct LifeTimeOnly<'a> { + _a: &'a u32 +} + +impl<'a> LifeTimeOnly<'a> { + + //~ MONO_ITEM fn LifeTimeOnly::<'_>::foo + pub fn foo(&self) {} + //~ MONO_ITEM fn LifeTimeOnly::<'_>::bar + pub fn bar(&'a self) {} + //~ MONO_ITEM fn LifeTimeOnly::<'_>::baz + pub fn baz<'b>(&'b self) {} + + pub fn non_instantiated(&self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn Struct::::new + //~ MONO_ITEM fn id:: + //~ MONO_ITEM fn Struct::::get:: + let _ = Struct::new(0i32).get(0i16); + + //~ MONO_ITEM fn Struct::::new + //~ MONO_ITEM fn id:: + //~ MONO_ITEM fn Struct::::get:: + let _ = Struct::new(0i64).get(0i16); + + //~ MONO_ITEM fn Struct::::new + //~ MONO_ITEM fn id:: + //~ MONO_ITEM fn Struct::::get:: + let _ = Struct::new('c').get(0i16); + + //~ MONO_ITEM fn Struct::<&str>::new + //~ MONO_ITEM fn id::<&str> + //~ MONO_ITEM fn Struct::>::get:: + let _ = Struct::new(Struct::new("str")).get(0i16); + + //~ MONO_ITEM fn Struct::>::new + //~ MONO_ITEM fn id::> + let _ = (Struct::new(Struct::new("str")).f)(Struct::new("str")); + + 0 +} diff --git a/tests/codegen-units/item-collection/impl-in-non-instantiated-generic.rs b/tests/codegen-units/item-collection/impl-in-non-instantiated-generic.rs new file mode 100644 index 000000000..c01398eb2 --- /dev/null +++ b/tests/codegen-units/item-collection/impl-in-non-instantiated-generic.rs @@ -0,0 +1,27 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +trait SomeTrait { + fn foo(&self); +} + +// This function is never instantiated but the contained impl must still be +// discovered. +pub fn generic_function(x: T) -> (T, i32) { + impl SomeTrait for i64 { + //~ MONO_ITEM fn generic_function::::foo + fn foo(&self) {} + } + + (x, 0) +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + 0i64.foo(); + + 0 +} diff --git a/tests/codegen-units/item-collection/implicit-panic-call.rs b/tests/codegen-units/item-collection/implicit-panic-call.rs new file mode 100644 index 000000000..abec7ad50 --- /dev/null +++ b/tests/codegen-units/item-collection/implicit-panic-call.rs @@ -0,0 +1,58 @@ +// compile-flags:-Zprint-mono-items=lazy + +// rust-lang/rust#90405 +// Ensure implicit panic calls are collected + +#![feature(lang_items)] +#![feature(no_core)] +#![crate_type = "lib"] +#![no_core] +#![no_std] + +#[lang = "panic_location"] +struct Location<'a> { + _file: &'a str, + _line: u32, + _col: u32, +} + +#[lang = "panic"] +#[inline] +#[track_caller] +fn panic(_: &'static str) -> ! { + loop {} +} + +#[lang = "sized"] +trait Sized {} + +#[lang = "copy"] +trait Copy {} + +#[lang = "freeze"] +trait Freeze {} + +impl Copy for i32 {} + +#[lang = "div"] +trait Div { + type Output; + fn div(self, rhs: Rhs) -> Self::Output; +} + +impl Div for i32 { + type Output = i32; + fn div(self, rhs: i32) -> i32 { + self / rhs + } +} + +#[allow(unconditional_panic)] +pub fn foo() { + // This implicitly generates a panic call. + let _ = 1 / 0; +} + +//~ MONO_ITEM fn foo +//~ MONO_ITEM fn ::div +//~ MONO_ITEM fn panic diff --git a/tests/codegen-units/item-collection/instantiation-through-vtable.rs b/tests/codegen-units/item-collection/instantiation-through-vtable.rs new file mode 100644 index 000000000..e78226d40 --- /dev/null +++ b/tests/codegen-units/item-collection/instantiation-through-vtable.rs @@ -0,0 +1,38 @@ +// +// compile-flags:-Zprint-mono-items=eager -Zinline-in-all-cgus -Zmir-opt-level=0 + +#![deny(dead_code)] +#![feature(start)] + +trait Trait { + fn foo(&self) -> u32; + fn bar(&self); +} + +struct Struct { + _a: T +} + +impl Trait for Struct { + fn foo(&self) -> u32 { 0 } + fn bar(&self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + let s1 = Struct { _a: 0u32 }; + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal] + //~ MONO_ITEM fn as Trait>::foo + //~ MONO_ITEM fn as Trait>::bar + let _ = &s1 as &Trait; + + let s1 = Struct { _a: 0u64 }; + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal] + //~ MONO_ITEM fn as Trait>::foo + //~ MONO_ITEM fn as Trait>::bar + let _ = &s1 as &Trait; + + 0 +} diff --git a/tests/codegen-units/item-collection/items-within-generic-items.rs b/tests/codegen-units/item-collection/items-within-generic-items.rs new file mode 100644 index 000000000..d37d7f7d9 --- /dev/null +++ b/tests/codegen-units/item-collection/items-within-generic-items.rs @@ -0,0 +1,35 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +fn generic_fn(a: T) -> (T, i32) { + //~ MONO_ITEM fn generic_fn::nested_fn + fn nested_fn(a: i32) -> i32 { + a + 1 + } + + let x = { + //~ MONO_ITEM fn generic_fn::nested_fn + fn nested_fn(a: i32) -> i32 { + a + 2 + } + + 1 + nested_fn(1) + }; + + return (a, x + nested_fn(0)); +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn generic_fn:: + let _ = generic_fn(0i64); + //~ MONO_ITEM fn generic_fn:: + let _ = generic_fn(0u16); + //~ MONO_ITEM fn generic_fn:: + let _ = generic_fn(0i8); + + 0 +} diff --git a/tests/codegen-units/item-collection/non-generic-closures.rs b/tests/codegen-units/item-collection/non-generic-closures.rs new file mode 100644 index 000000000..379fbcf26 --- /dev/null +++ b/tests/codegen-units/item-collection/non-generic-closures.rs @@ -0,0 +1,60 @@ +// In the current version of the collector that still has to support +// legacy-codegen, closures do not generate their own MonoItems, so we are +// ignoring this test until MIR codegen has taken over completely +// ignore-test + +// +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +//~ MONO_ITEM fn non_generic_closures::temporary[0] +fn temporary() { + //~ MONO_ITEM fn non_generic_closures::temporary[0]::{{closure}}[0] + (|a: u32| { + let _ = a; + })(4); +} + +//~ MONO_ITEM fn non_generic_closures::assigned_to_variable_but_not_executed[0] +fn assigned_to_variable_but_not_executed() { + //~ MONO_ITEM fn non_generic_closures::assigned_to_variable_but_not_executed[0]::{{closure}}[0] + let _x = |a: i16| { + let _ = a + 1; + }; +} + +//~ MONO_ITEM fn non_generic_closures::assigned_to_variable_executed_directly[0] +fn assigned_to_variable_executed_indirectly() { + //~ MONO_ITEM fn non_generic_closures::assigned_to_variable_executed_directly[0]::{{closure}}[0] + let f = |a: i32| { + let _ = a + 2; + }; + run_closure(&f); +} + +//~ MONO_ITEM fn non_generic_closures::assigned_to_variable_executed_indirectly[0] +fn assigned_to_variable_executed_directly() { + //~ MONO_ITEM fn non_generic_closures::assigned_to_variable_executed_indirectly[0]::{{closure}}[0] + let f = |a: i64| { + let _ = a + 3; + }; + f(4); +} + +//~ MONO_ITEM fn non_generic_closures::start[0] +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + temporary(); + assigned_to_variable_but_not_executed(); + assigned_to_variable_executed_directly(); + assigned_to_variable_executed_indirectly(); + + 0 +} + +//~ MONO_ITEM fn non_generic_closures::run_closure[0] +fn run_closure(f: &Fn(i32)) { + f(3); +} diff --git a/tests/codegen-units/item-collection/non-generic-drop-glue.rs b/tests/codegen-units/item-collection/non-generic-drop-glue.rs new file mode 100644 index 000000000..06f76f7db --- /dev/null +++ b/tests/codegen-units/item-collection/non-generic-drop-glue.rs @@ -0,0 +1,49 @@ +// +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus + +#![deny(dead_code)] +#![feature(start)] + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(StructWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] +struct StructWithDrop { + x: i32 +} + +impl Drop for StructWithDrop { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +struct StructNoDrop { + x: i32 +} + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(EnumWithDrop)) @@ non_generic_drop_glue-cgu.0[Internal] +enum EnumWithDrop { + A(i32) +} + +impl Drop for EnumWithDrop { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +enum EnumNoDrop { + A(i32) +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + let _ = StructWithDrop { x: 0 }.x; + let _ = StructNoDrop { x: 0 }.x; + let _ = match EnumWithDrop::A(0) { + EnumWithDrop::A(x) => x + }; + let _ = match EnumNoDrop::A(0) { + EnumNoDrop::A(x) => x + }; + + 0 +} diff --git a/tests/codegen-units/item-collection/non-generic-functions.rs b/tests/codegen-units/item-collection/non-generic-functions.rs new file mode 100644 index 000000000..092e64562 --- /dev/null +++ b/tests/codegen-units/item-collection/non-generic-functions.rs @@ -0,0 +1,72 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +//~ MONO_ITEM fn foo +fn foo() { + { + //~ MONO_ITEM fn foo::foo + fn foo() {} + foo(); + } + + { + //~ MONO_ITEM fn foo::foo + fn foo() {} + foo(); + } +} + +//~ MONO_ITEM fn bar +fn bar() { + //~ MONO_ITEM fn bar::baz + fn baz() {} + baz(); +} + +struct Struct { _x: i32 } + +impl Struct { + //~ MONO_ITEM fn Struct::foo + fn foo() { + { + //~ MONO_ITEM fn Struct::foo::foo + fn foo() {} + foo(); + } + + { + //~ MONO_ITEM fn Struct::foo::foo + fn foo() {} + foo(); + } + } + + //~ MONO_ITEM fn Struct::bar + fn bar(&self) { + { + //~ MONO_ITEM fn Struct::bar::foo + fn foo() {} + foo(); + } + + { + //~ MONO_ITEM fn Struct::bar::foo + fn foo() {} + foo(); + } + } +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + foo(); + bar(); + Struct::foo(); + let x = Struct { _x: 0 }; + x.bar(); + + 0 +} diff --git a/tests/codegen-units/item-collection/overloaded-operators.rs b/tests/codegen-units/item-collection/overloaded-operators.rs new file mode 100644 index 000000000..2be7eba1d --- /dev/null +++ b/tests/codegen-units/item-collection/overloaded-operators.rs @@ -0,0 +1,59 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![crate_type="lib"] + +use std::ops::{Index, IndexMut, Add, Deref}; + +pub struct Indexable { + data: [u8; 3] +} + +impl Index for Indexable { + type Output = u8; + + //~ MONO_ITEM fn >::index + fn index(&self, index: usize) -> &Self::Output { + if index >= 3 { + &self.data[0] + } else { + &self.data[index] + } + } +} + +impl IndexMut for Indexable { + //~ MONO_ITEM fn >::index_mut + fn index_mut(&mut self, index: usize) -> &mut Self::Output { + if index >= 3 { + &mut self.data[0] + } else { + &mut self.data[index] + } + } +} + + +//~ MONO_ITEM fn ::eq +//~ MONO_ITEM fn ::ne +#[derive(PartialEq)] +pub struct Equatable(u32); + + +impl Add for Equatable { + type Output = u32; + + //~ MONO_ITEM fn >::add + fn add(self, rhs: u32) -> u32 { + self.0 + rhs + } +} + +impl Deref for Equatable { + type Target = u32; + + //~ MONO_ITEM fn ::deref + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/tests/codegen-units/item-collection/static-init.rs b/tests/codegen-units/item-collection/static-init.rs new file mode 100644 index 000000000..287ec8f24 --- /dev/null +++ b/tests/codegen-units/item-collection/static-init.rs @@ -0,0 +1,16 @@ +// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on + +#![feature(start)] + +pub static FN : fn() = foo::; + +pub fn foo() { } + +//~ MONO_ITEM fn foo:: +//~ MONO_ITEM static FN + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + 0 +} diff --git a/tests/codegen-units/item-collection/statics-and-consts.rs b/tests/codegen-units/item-collection/statics-and-consts.rs new file mode 100644 index 000000000..49a8d3dff --- /dev/null +++ b/tests/codegen-units/item-collection/statics-and-consts.rs @@ -0,0 +1,54 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +static STATIC1: i64 = { + const STATIC1_CONST1: i64 = 2; + 1 + CONST1 as i64 + STATIC1_CONST1 +}; + +const CONST1: i64 = { + const CONST1_1: i64 = { + const CONST1_1_1: i64 = 2; + CONST1_1_1 + 1 + }; + 1 + CONST1_1 as i64 +}; + +fn foo() { + let _ = { + const CONST2: i64 = 0; + static STATIC2: i64 = CONST2; + + let x = { + const CONST2: i64 = 1; + static STATIC2: i64 = CONST2; + STATIC2 + }; + + x + STATIC2 + }; + + let _ = { + const CONST2: i64 = 0; + static STATIC2: i64 = CONST2; + STATIC2 + }; +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + foo(); + let _ = STATIC1; + + 0 +} + +//~ MONO_ITEM static STATIC1 + +//~ MONO_ITEM fn foo +//~ MONO_ITEM static foo::STATIC2 +//~ MONO_ITEM static foo::STATIC2 +//~ MONO_ITEM static foo::STATIC2 diff --git a/tests/codegen-units/item-collection/trait-implementations.rs b/tests/codegen-units/item-collection/trait-implementations.rs new file mode 100644 index 000000000..a816cb032 --- /dev/null +++ b/tests/codegen-units/item-collection/trait-implementations.rs @@ -0,0 +1,73 @@ +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +pub trait SomeTrait { + fn foo(&self); + fn bar(&self, x: T); +} + +impl SomeTrait for i64 { + + //~ MONO_ITEM fn ::foo + fn foo(&self) {} + + fn bar(&self, _: T) {} +} + +impl SomeTrait for i32 { + + //~ MONO_ITEM fn ::foo + fn foo(&self) {} + + fn bar(&self, _: T) {} +} + +pub trait SomeGenericTrait { + fn foo(&self, x: T); + fn bar(&self, x: T, y: T2); +} + +// Concrete impl of generic trait +impl SomeGenericTrait for f64 { + + //~ MONO_ITEM fn >::foo + fn foo(&self, _: u32) {} + + fn bar(&self, _: u32, _: T2) {} +} + +// Generic impl of generic trait +impl SomeGenericTrait for f32 { + + fn foo(&self, _: T) {} + fn bar(&self, _: T, _: T2) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn ::bar:: + 0i32.bar('x'); + + //~ MONO_ITEM fn >::bar::<&str> + 0f64.bar(0u32, "&str"); + + //~ MONO_ITEM fn >::bar::<()> + 0f64.bar(0u32, ()); + + //~ MONO_ITEM fn >::foo + 0f32.foo('x'); + + //~ MONO_ITEM fn >::foo + 0f32.foo(-1i64); + + //~ MONO_ITEM fn >::bar::<()> + 0f32.bar(0u32, ()); + + //~ MONO_ITEM fn >::bar::<&str> + 0f32.bar("&str", "&str"); + + 0 +} diff --git a/tests/codegen-units/item-collection/trait-method-as-argument.rs b/tests/codegen-units/item-collection/trait-method-as-argument.rs new file mode 100644 index 000000000..235569728 --- /dev/null +++ b/tests/codegen-units/item-collection/trait-method-as-argument.rs @@ -0,0 +1,60 @@ +// +// compile-flags:-Zprint-mono-items=eager + +#![deny(dead_code)] +#![feature(start)] + +trait Trait : Sized { + fn foo(self) -> Self { self } +} + +impl Trait for u32 { + fn foo(self) -> u32 { self } +} + +impl Trait for char { +} + +fn take_foo_once T>(f: F, arg: T) -> T { + (f)(arg) +} + +fn take_foo T>(f: F, arg: T) -> T { + (f)(arg) +} + +fn take_foo_mut T>(mut f: F, arg: T) -> T { + (f)(arg) +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn take_foo_once:: u32 {::foo}> + //~ MONO_ITEM fn ::foo + //~ MONO_ITEM fn u32 {::foo} as std::ops::FnOnce<(u32,)>>::call_once - shim(fn(u32) -> u32 {::foo}) + take_foo_once(Trait::foo, 0u32); + + //~ MONO_ITEM fn take_foo_once:: char {::foo}> + //~ MONO_ITEM fn ::foo + //~ MONO_ITEM fn char {::foo} as std::ops::FnOnce<(char,)>>::call_once - shim(fn(char) -> char {::foo}) + take_foo_once(Trait::foo, 'c'); + + //~ MONO_ITEM fn take_foo:: u32 {::foo}> + //~ MONO_ITEM fn u32 {::foo} as std::ops::Fn<(u32,)>>::call - shim(fn(u32) -> u32 {::foo}) + take_foo(Trait::foo, 0u32); + + //~ MONO_ITEM fn take_foo:: char {::foo}> + //~ MONO_ITEM fn char {::foo} as std::ops::Fn<(char,)>>::call - shim(fn(char) -> char {::foo}) + take_foo(Trait::foo, 'c'); + + //~ MONO_ITEM fn take_foo_mut:: u32 {::foo}> + //~ MONO_ITEM fn u32 {::foo} as std::ops::FnMut<(u32,)>>::call_mut - shim(fn(u32) -> u32 {::foo}) + take_foo_mut(Trait::foo, 0u32); + + //~ MONO_ITEM fn take_foo_mut:: char {::foo}> + //~ MONO_ITEM fn char {::foo} as std::ops::FnMut<(char,)>>::call_mut - shim(fn(char) -> char {::foo}) + take_foo_mut(Trait::foo, 'c'); + + 0 +} diff --git a/tests/codegen-units/item-collection/trait-method-default-impl.rs b/tests/codegen-units/item-collection/trait-method-default-impl.rs new file mode 100644 index 000000000..bfcdb6fa1 --- /dev/null +++ b/tests/codegen-units/item-collection/trait-method-default-impl.rs @@ -0,0 +1,61 @@ +// compile-flags:-Zprint-mono-items=eager -Zpolymorphize=on + +#![deny(dead_code)] +#![feature(start)] + +trait SomeTrait { + fn foo(&self) { } + fn bar(&self, x: T) -> T { x } +} + +impl SomeTrait for i8 { + // take the default implementations + + // For the non-generic foo(), we should generate a codegen-item even if it + // is not called anywhere + //~ MONO_ITEM fn ::foo +} + +trait SomeGenericTrait { + fn foo(&self) { } + fn bar(&self, x: T1, y: T2) {} +} + +// Non-generic impl of generic trait +impl SomeGenericTrait for i32 { + // take the default implementations + + // For the non-generic foo(), we should generate a codegen-item even if it + // is not called anywhere + //~ MONO_ITEM fn >::foo +} + +// Non-generic impl of generic trait +impl SomeGenericTrait for u32 { + // take the default implementations + // since nothing is monomorphic here, nothing should be generated unless used somewhere. +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn ::bar:: + let _ = 1i8.bar('c'); + + //~ MONO_ITEM fn ::bar::<&str> + let _ = 2i8.bar("&str"); + + //~ MONO_ITEM fn >::bar:: + 0i32.bar(0u64, 'c'); + + //~ MONO_ITEM fn >::bar::<&str> + 0i32.bar(0u64, "&str"); + + //~ MONO_ITEM fn >::bar::<&[char; 1]> + 0u32.bar(0i8, &['c']); + + //~ MONO_ITEM fn >::bar::<()> + 0u32.bar(0i16, ()); + + 0 +} diff --git a/tests/codegen-units/item-collection/transitive-drop-glue.rs b/tests/codegen-units/item-collection/transitive-drop-glue.rs new file mode 100644 index 000000000..e286c800b --- /dev/null +++ b/tests/codegen-units/item-collection/transitive-drop-glue.rs @@ -0,0 +1,46 @@ +// +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus + +#![deny(dead_code)] +#![feature(start)] + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Root)) @@ transitive_drop_glue-cgu.0[Internal] +struct Root(#[allow(unused_tuple_struct_fields)] Intermediate); +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Intermediate)) @@ transitive_drop_glue-cgu.0[Internal] +struct Intermediate(#[allow(unused_tuple_struct_fields)] Leaf); +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Leaf)) @@ transitive_drop_glue-cgu.0[Internal] +struct Leaf; + +impl Drop for Leaf { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +struct RootGen(#[allow(unused_tuple_struct_fields)] IntermediateGen); +struct IntermediateGen(#[allow(unused_tuple_struct_fields)] LeafGen); +struct LeafGen(#[allow(unused_tuple_struct_fields)] T); + +impl Drop for LeafGen { + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + let _ = Root(Intermediate(Leaf)); + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = RootGen(IntermediateGen(LeafGen(0u32))); + + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(RootGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(IntermediateGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::> - shim(Some(LeafGen)) @@ transitive_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn as std::ops::Drop>::drop + let _ = RootGen(IntermediateGen(LeafGen(0i16))); + + 0 +} diff --git a/tests/codegen-units/item-collection/tuple-drop-glue.rs b/tests/codegen-units/item-collection/tuple-drop-glue.rs new file mode 100644 index 000000000..ae3b2e081 --- /dev/null +++ b/tests/codegen-units/item-collection/tuple-drop-glue.rs @@ -0,0 +1,27 @@ +// +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus + +#![deny(dead_code)] +#![feature(start)] + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(Some(Dropped)) @@ tuple_drop_glue-cgu.0[Internal] +struct Dropped; + +impl Drop for Dropped { + //~ MONO_ITEM fn ::drop + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn std::ptr::drop_in_place::<(u32, Dropped)> - shim(Some((u32, Dropped))) @@ tuple_drop_glue-cgu.0[Internal] + let x = (0u32, Dropped); + + //~ MONO_ITEM fn std::ptr::drop_in_place::<(i16, (Dropped, bool))> - shim(Some((i16, (Dropped, bool)))) @@ tuple_drop_glue-cgu.0[Internal] + //~ MONO_ITEM fn std::ptr::drop_in_place::<(Dropped, bool)> - shim(Some((Dropped, bool))) @@ tuple_drop_glue-cgu.0[Internal] + let x = (0i16, (Dropped, true)); + + 0 +} diff --git a/tests/codegen-units/item-collection/unreferenced-const-fn.rs b/tests/codegen-units/item-collection/unreferenced-const-fn.rs new file mode 100644 index 000000000..17b92eae0 --- /dev/null +++ b/tests/codegen-units/item-collection/unreferenced-const-fn.rs @@ -0,0 +1,9 @@ +// compile-flags:-Zprint-mono-items=lazy + +#![deny(dead_code)] +#![crate_type = "rlib"] + +//~ MONO_ITEM fn foo @@ unreferenced_const_fn-cgu.0[External] +pub const fn foo(x: u32) -> u32 { + x + 0xf00 +} diff --git a/tests/codegen-units/item-collection/unreferenced-inline-function.rs b/tests/codegen-units/item-collection/unreferenced-inline-function.rs new file mode 100644 index 000000000..4d095e4d6 --- /dev/null +++ b/tests/codegen-units/item-collection/unreferenced-inline-function.rs @@ -0,0 +1,11 @@ +// compile-flags:-Zprint-mono-items=lazy + +// N.B., we do not expect *any* monomorphization to be generated here. + +#![deny(dead_code)] +#![crate_type = "rlib"] + +#[inline] +pub fn foo() -> bool { + [1, 2] == [3, 4] +} diff --git a/tests/codegen-units/item-collection/unsizing.rs b/tests/codegen-units/item-collection/unsizing.rs new file mode 100644 index 000000000..111a72312 --- /dev/null +++ b/tests/codegen-units/item-collection/unsizing.rs @@ -0,0 +1,79 @@ +// compile-flags:-Zprint-mono-items=eager +// compile-flags:-Zinline-in-all-cgus +// compile-flags:-Zmir-opt-level=0 + +#![deny(dead_code)] +#![feature(coerce_unsized)] +#![feature(unsize)] +#![feature(start)] + +use std::marker::Unsize; +use std::ops::CoerceUnsized; + +trait Trait { + fn foo(&self); +} + +// Simple Case +impl Trait for bool { + fn foo(&self) {} +} + +impl Trait for char { + fn foo(&self) {} +} + +// Struct Field Case +struct Struct { + _a: u32, + _b: i32, + _c: T +} + +impl Trait for f64 { + fn foo(&self) {} +} + +// Custom Coercion Case +impl Trait for u32 { + fn foo(&self) {} +} + +#[derive(Clone, Copy)] +struct Wrapper(#[allow(unused_tuple_struct_fields)] *const T); + +impl, U: ?Sized> CoerceUnsized> for Wrapper {} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + // simple case + let bool_sized = &true; + //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(None) @@ unsizing-cgu.0[Internal] + //~ MONO_ITEM fn ::foo + let _bool_unsized = bool_sized as &Trait; + + let char_sized = &'a'; + + //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(None) @@ unsizing-cgu.0[Internal] + //~ MONO_ITEM fn ::foo + let _char_unsized = char_sized as &Trait; + + // struct field + let struct_sized = &Struct { + _a: 1, + _b: 2, + _c: 3.0f64 + }; + //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(None) @@ unsizing-cgu.0[Internal] + //~ MONO_ITEM fn ::foo + let _struct_unsized = struct_sized as &Struct; + + // custom coercion + let wrapper_sized = Wrapper(&0u32); + //~ MONO_ITEM fn std::ptr::drop_in_place:: - shim(None) @@ unsizing-cgu.0[Internal] + //~ MONO_ITEM fn ::foo + let _wrapper_sized = wrapper_sized as Wrapper; + + 0 +} diff --git a/tests/codegen-units/item-collection/unused-traits-and-generics.rs b/tests/codegen-units/item-collection/unused-traits-and-generics.rs new file mode 100644 index 000000000..561dc1a5c --- /dev/null +++ b/tests/codegen-units/item-collection/unused-traits-and-generics.rs @@ -0,0 +1,77 @@ +// compile-flags:-Zprint-mono-items=eager + +#![crate_type="lib"] +#![deny(dead_code)] + +// This test asserts that no codegen items are generated for generic items that +// are never instantiated in the local crate. + +pub trait Trait { + fn foo() {} + fn bar(&self) {} +} + +pub fn foo(x: T) -> (T, T) { + (x, x) +} + +pub struct Struct { + x: T +} + +impl Struct { + pub fn foo(self) -> T { + self.x + } + + pub fn bar() {} +} + +pub enum Enum { + A(T), + B { x: T } +} + +impl Enum { + pub fn foo(self) -> T { + match self { + Enum::A(x) => x, + Enum::B { x } => x, + } + } + + pub fn bar() {} +} + +pub struct TupleStruct(T); + +impl TupleStruct { + pub fn foo(self) -> T { + self.0 + } + + pub fn bar() {} +} + +pub type Pair = (T, T); + +pub struct NonGeneric { + x: i32 +} + +impl NonGeneric { + pub fn foo(self) -> i32 { + self.x + } + + pub fn generic_foo(&self, x: T) -> (T, i32) { + (x, self.x) + } + + pub fn generic_bar(x: T) -> (T, T) { + (x, x) + } +} + +// Only the non-generic methods should be instantiated: +//~ MONO_ITEM fn NonGeneric::foo 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(x: T) -> (T, u32, i8) { + let (x, Struct(y)) = bar(x); + (x, y, 2) +} + +#[inline(never)] +fn bar(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(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:: - 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:: - 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:: - 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:: - shim(Some(Struct)) @@ local_drop_glue-fallback.cgu[External] +struct Struct { + _a: u32, +} + +impl Drop for Struct { + //~ MONO_ITEM fn ::drop @@ local_drop_glue-fallback.cgu[External] + fn drop(&mut self) {} +} + +//~ MONO_ITEM fn std::ptr::drop_in_place:: - 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:: - 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:: @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic:: @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic:: @@ local_generic.volatile[External] +//~ MONO_ITEM fn generic::<&str> @@ local_generic.volatile[External] +pub fn generic(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); + +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 SomeGenericType { + 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 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] @@ 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] @@ 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.volatile[WeakODR] + type1::Struct.foo(); + //~ MONO_ITEM fn methods_are_with_self_type::{{impl}}[0]::foo[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.volatile[WeakODR] + type1::Struct.default(); + //~ MONO_ITEM fn methods_are_with_self_type::Trait[0]::default[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:: @@ 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 { + fn do_something(&self, x: T) -> T; + fn do_something_else(&self, x: T) -> T; + } + + impl Trait1Gen for u32 { + fn do_something(&self, x: T) -> T { x } + fn do_something_else(&self, x: T) -> T { x } + } + + //~ MONO_ITEM fn mod1::id:: @@ vtable_through_const-mod1.volatile[Internal] + fn id(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 = &0u32 as &Trait1Gen; + pub const ID_CHAR: fn(char) -> char = id::; + + + + pub trait Trait2 { + fn do_something(&self) {} + fn do_something_else(&self) {} + } + + //~ MONO_ITEM fn ::do_something @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn ::do_something_else @@ vtable_through_const-mod1.volatile[Internal] + impl Trait2 for u32 {} + + pub trait Trait2Gen { + fn do_something(&self, x: T) -> T; + fn do_something_else(&self, x: T) -> T; + } + + impl Trait2Gen 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 = &0u32 as &Trait2Gen; + pub const ID_I64: fn(i64) -> i64 = id::; +} + +//~ MONO_ITEM fn start +#[start] +fn start(_: isize, _: *const *const u8) -> isize { + //~ MONO_ITEM fn std::ptr::drop_in_place:: - 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 ::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 ::do_something @@ vtable_through_const-mod1.volatile[External] + mod1::TRAIT1_REF.do_something(); + + // Same as above + //~ MONO_ITEM fn >::do_something @@ vtable_through_const-mod1.volatile[External] + //~ MONO_ITEM fn >::do_something_else @@ vtable_through_const-mod1.volatile[External] + //~ MONO_ITEM fn >::do_something @@ vtable_through_const-mod1.volatile[Internal] + //~ MONO_ITEM fn >::do_something_else @@ vtable_through_const-mod1.volatile[Internal] + mod1::TRAIT1_GEN_REF.do_something(0u8); + + //~ MONO_ITEM fn mod1::id:: @@ vtable_through_const-mod1.volatile[External] + mod1::ID_CHAR('x'); + + 0 +} diff --git a/tests/codegen-units/polymorphization/unused_type_parameters.rs b/tests/codegen-units/polymorphization/unused_type_parameters.rs new file mode 100644 index 000000000..c2e06d067 --- /dev/null +++ b/tests/codegen-units/polymorphization/unused_type_parameters.rs @@ -0,0 +1,322 @@ +// compile-flags:-Zpolymorphize=on -Zprint-mono-items=lazy -Copt-level=1 + +#![crate_type = "rlib"] + +// This test checks that the polymorphization analysis correctly reduces the +// generated mono items. + +mod functions { + // Function doesn't have any type parameters to be unused. + pub fn no_parameters() {} + +//~ MONO_ITEM fn functions::no_parameters + + // Function has an unused type parameter. + pub fn unused() { + } + +//~ MONO_ITEM fn functions::unused:: + + // Function uses type parameter in value of a binding. + pub fn used_binding_value() { + let _: T = Default::default(); + } + +//~ MONO_ITEM fn functions::used_binding_value:: +//~ MONO_ITEM fn functions::used_binding_value:: + + // Function uses type parameter in type of a binding. + pub fn used_binding_type() { + let _: Option = None; + } + +//~ MONO_ITEM fn functions::used_binding_type:: +//~ MONO_ITEM fn functions::used_binding_type:: + + // Function uses type parameter in argument. + pub fn used_argument(_: T) { + } + +//~ MONO_ITEM fn functions::used_argument:: +//~ MONO_ITEM fn functions::used_argument:: +// + // Function uses type parameter in substitutions to another function. + pub fn used_substs() { + unused::() + } + +//~ MONO_ITEM fn functions::used_substs:: +//~ MONO_ITEM fn functions::used_substs:: +} + + +mod closures { + // Function doesn't have any type parameters to be unused. + pub fn no_parameters() { + let _ = || {}; + } + +//~ MONO_ITEM fn closures::no_parameters + + // Function has an unused type parameter in parent and closure. + pub fn unused() -> u32 { + let add_one = |x: u32| x + 1; + add_one(3) + } + +//~ MONO_ITEM fn closures::unused::::{closure#0} +//~ MONO_ITEM fn closures::unused:: + + // Function has an unused type parameter in closure, but not in parent. + pub fn used_parent() -> u32 { + let _: T = Default::default(); + let add_one = |x: u32| x + 1; + add_one(3) + } + +//~ MONO_ITEM fn closures::used_parent::::{closure#0} +//~ MONO_ITEM fn closures::used_parent:: +//~ MONO_ITEM fn closures::used_parent:: + + // Function uses type parameter in value of a binding in closure. + pub fn used_binding_value() -> T { + let x = || { + let y: T = Default::default(); + y + }; + + x() + } + +//~ MONO_ITEM fn closures::used_binding_value::::{closure#0} +//~ MONO_ITEM fn closures::used_binding_value::::{closure#0} +//~ MONO_ITEM fn closures::used_binding_value:: +//~ MONO_ITEM fn closures::used_binding_value:: + + // Function uses type parameter in type of a binding in closure. + pub fn used_binding_type() -> Option { + let x = || { + let y: Option = None; + y + }; + + x() + } + +//~ MONO_ITEM fn closures::used_binding_type::::{closure#0} +//~ MONO_ITEM fn closures::used_binding_type::::{closure#0} +//~ MONO_ITEM fn closures::used_binding_type:: +//~ MONO_ITEM fn closures::used_binding_type:: + + // Function and closure uses type parameter in argument. + pub fn used_argument(t: T) -> u32 { + let x = |_: T| 3; + x(t) + } + +//~ MONO_ITEM fn closures::used_argument::::{closure#0} +//~ MONO_ITEM fn closures::used_argument::::{closure#0} +//~ MONO_ITEM fn closures::used_argument:: +//~ MONO_ITEM fn closures::used_argument:: + + // Closure uses type parameter in argument. + pub fn used_argument_closure() -> u32 { + let t: T = Default::default(); + let x = |_: T| 3; + x(t) + } + +//~ MONO_ITEM fn closures::used_argument_closure::::{closure#0} +//~ MONO_ITEM fn closures::used_argument_closure::::{closure#0} +//~ MONO_ITEM fn closures::used_argument_closure:: +//~ MONO_ITEM fn closures::used_argument_closure:: + + // Closure uses type parameter as upvar. + pub fn used_upvar() -> T { + let x: T = Default::default(); + let y = || x; + y() + } + +//~ MONO_ITEM fn closures::used_upvar::::{closure#0} +//~ MONO_ITEM fn closures::used_upvar::::{closure#0} +//~ MONO_ITEM fn closures::used_upvar:: +//~ MONO_ITEM fn closures::used_upvar:: + + // Closure uses type parameter in substitutions to another function. + pub fn used_substs() { + let x = || super::functions::unused::(); + x() + } + +//~ MONO_ITEM fn closures::used_substs::::{closure#0} +//~ MONO_ITEM fn closures::used_substs::::{closure#0} +//~ MONO_ITEM fn closures::used_substs:: +//~ MONO_ITEM fn closures::used_substs:: +} + +mod methods { + pub struct Foo(F); + + impl Foo { + // Function has an unused type parameter from impl. + pub fn unused_impl() { + } + +//~ MONO_ITEM fn methods::Foo::::unused_impl + + // Function has an unused type parameter from impl and fn. + pub fn unused_both() { + } + +//~ MONO_ITEM fn methods::Foo::::unused_both:: + + // Function uses type parameter from impl. + pub fn used_impl() { + let _: F = Default::default(); + } + +//~ MONO_ITEM fn methods::Foo::::used_impl +//~ MONO_ITEM fn methods::Foo::::used_impl + + // Function uses type parameter from impl. + pub fn used_fn() { + let _: G = Default::default(); + } + +//~ MONO_ITEM fn methods::Foo::::used_fn:: +//~ MONO_ITEM fn methods::Foo::::used_fn:: + + // Function uses type parameter from impl. + pub fn used_both() { + let _: F = Default::default(); + let _: G = Default::default(); + } + +//~ MONO_ITEM fn methods::Foo::::used_both:: +//~ MONO_ITEM fn methods::Foo::::used_both:: + + // Function uses type parameter in substitutions to another function. + pub fn used_substs() { + super::functions::unused::() + } + +//~ MONO_ITEM fn methods::Foo::::used_substs +//~ MONO_ITEM fn methods::Foo::::used_substs + + // Function has an unused type parameter from impl and fn. + pub fn closure_unused_all() -> u32 { + let add_one = |x: u32| x + 1; + add_one(3) + } + +//~ MONO_ITEM fn methods::Foo::::closure_unused_all::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_unused_all:: + + // Function uses type parameter from impl and fn in closure. + pub fn closure_used_both() -> u32 { + let add_one = |x: u32| { + let _: F = Default::default(); + let _: G = Default::default(); + x + 1 + }; + + add_one(3) + } + +//~ MONO_ITEM fn methods::Foo::::closure_used_both::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_both::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_both:: +//~ MONO_ITEM fn methods::Foo::::closure_used_both:: + + // Function uses type parameter from fn in closure. + pub fn closure_used_fn() -> u32 { + let add_one = |x: u32| { + let _: G = Default::default(); + x + 1 + }; + + add_one(3) + } + +//~ MONO_ITEM fn methods::Foo::::closure_used_fn::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_fn::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_fn:: +//~ MONO_ITEM fn methods::Foo::::closure_used_fn:: + + // Function uses type parameter from impl in closure. + pub fn closure_used_impl() -> u32 { + let add_one = |x: u32| { + let _: F = Default::default(); + x + 1 + }; + + add_one(3) + } + +//~ MONO_ITEM fn methods::Foo::::closure_used_impl::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_impl::::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_impl:: +//~ MONO_ITEM fn methods::Foo::::closure_used_impl:: + + // Closure uses type parameter in substitutions to another function. + pub fn closure_used_substs() { + let x = || super::functions::unused::(); + x() + } + +//~ MONO_ITEM fn methods::Foo::::closure_used_substs::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_substs::{closure#0} +//~ MONO_ITEM fn methods::Foo::::closure_used_substs +//~ MONO_ITEM fn methods::Foo::::closure_used_substs + } +} + + + +fn dispatch() { + functions::no_parameters(); + functions::unused::(); + functions::used_binding_value::(); + functions::used_binding_type::(); + functions::used_argument::(Default::default()); + functions::used_substs::(); + + closures::no_parameters(); + let _ = closures::unused::(); + let _ = closures::used_parent::(); + let _ = closures::used_binding_value::(); + let _ = closures::used_binding_type::(); + let _ = closures::used_argument::(Default::default()); + let _ = closures::used_argument_closure::(); + let _ = closures::used_upvar::(); + let _ = closures::used_substs::(); + + methods::Foo::::unused_impl(); + methods::Foo::::unused_both::(); + methods::Foo::::used_impl(); + methods::Foo::::used_fn::(); + methods::Foo::::used_both::(); + methods::Foo::::used_substs(); + let _ = methods::Foo::::closure_unused_all::(); + let _ = methods::Foo::::closure_used_both::(); + let _ = methods::Foo::::closure_used_impl::(); + let _ = methods::Foo::::closure_used_fn::(); + let _ = methods::Foo::::closure_used_substs(); +} + +//~ MONO_ITEM fn dispatch:: +//~ MONO_ITEM fn dispatch:: + +pub fn foo() { + // Generate two copies of each function to check that where the type parameter is unused, + // there is only a single copy. + dispatch::(); + dispatch::(); +} + +//~ MONO_ITEM fn foo @@ unused_type_parameters-cgu.0[External] + +// These are all the items that aren't relevant to the test. +//~ MONO_ITEM fn ::default +//~ MONO_ITEM fn ::default -- cgit v1.2.3