rust/tests/codegen-units/partitioning/inlining-from-extern-crate.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.6 KiB
Rust
Raw Normal View History

//
// We specify incremental here because we want to test the partitioning for
// incremental compilation
// incremental
// compile-flags:-Zprint-mono-items=lazy
rustc: Don't inline in CGUs at -O0 This commit tweaks the behavior of inlining functions into multiple codegen units when rustc is compiling in debug mode. Today rustc will unconditionally treat `#[inline]` functions by translating them into all codegen units that they're needed within, marking the linkage as `internal`. This commit changes the behavior so that in debug mode (compiling at `-O0`) rustc will instead only translate `#[inline]` functions into *one* codegen unit, forcing all other codegen units to reference this one copy. The goal here is to improve debug compile times by reducing the amount of translation that happens on behalf of multiple codegen units. It was discovered in #44941 that increasing the number of codegen units had the adverse side effect of increasing the overal work done by the compiler, and the suspicion here was that the compiler was inlining, translating, and codegen'ing more functions with more codegen units (for example `String` would be basically inlined into all codegen units if used). The strategy in this commit should reduce the cost of `#[inline]` functions to being equivalent to one codegen unit, which is only translating and codegen'ing inline functions once. Collected [data] shows that this does indeed improve the situation from [before] as the overall cpu-clock time increases at a much slower rate and when pinned to one core rustc does not consume significantly more wall clock time than with one codegen unit. One caveat of this commit is that the symbol names for inlined functions that are only translated once needed some slight tweaking. These inline functions could be translated into multiple crates and we need to make sure the symbols don't collideA so the crate name/disambiguator is mixed in to the symbol name hash in these situations. [data]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334880911 [before]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334583384
2017-10-06 16:59:33 -05:00
// 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();
2018-05-08 08:10:16 -05:00
// does not generate a monomorphization in this crate
cgu_explicit_inlining::never_inlined();
}
2017-10-27 07:31:18 -05:00
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();
2018-05-08 08:10:16 -05:00
// does not generate a monomorphization in this crate
cgu_explicit_inlining::never_inlined();
}
}
2017-10-27 07:31:18 -05:00
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();
2018-05-08 08:10:16 -05:00
// does not generate a monomorphization in this crate
cgu_explicit_inlining::never_inlined();
}
}