Skip to content

Remove mono item collection strategy override from -Zprint-mono-items #140842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ fn test_unstable_options_tracking_hash() {
untracked!(pre_link_args, vec![String::from("abc"), String::from("def")]);
untracked!(print_codegen_stats, true);
untracked!(print_llvm_passes, true);
untracked!(print_mono_items, Some(String::from("abc")));
untracked!(print_mono_items, true);
untracked!(print_type_sizes, true);
untracked!(proc_macro_backtrace, true);
untracked!(proc_macro_execution_strategy, ProcMacroExecutionStrategy::CrossThread);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_monomorphize/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ monomorphize_start_not_found = using `fn main` requires the standard library

monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined

monomorphize_unknown_cgu_collection_mode =
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode

monomorphize_wasm_c_abi_transition =
this function {$is_call ->
[true] call
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_monomorphize/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ pub(crate) struct EncounteredErrorWhileInstantiating {
#[help]
pub(crate) struct StartNotFound;

#[derive(Diagnostic)]
#[diag(monomorphize_unknown_cgu_collection_mode)]
pub(crate) struct UnknownCguCollectionMode<'a> {
pub mode: &'a str,
}

#[derive(Diagnostic)]
#[diag(monomorphize_abi_error_disabled_vector_type)]
#[help]
Expand Down
29 changes: 6 additions & 23 deletions compiler/rustc_monomorphize/src/partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ use rustc_target::spec::SymbolVisibility;
use tracing::debug;

use crate::collector::{self, MonoItemCollectionStrategy, UsageMap};
use crate::errors::{CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownCguCollectionMode};
use crate::errors::{CouldntDumpMonoStats, SymbolAlreadyDefined};

struct PartitioningCx<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -1127,27 +1127,10 @@ where
}

fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> MonoItemPartitions<'_> {
let collection_strategy = match tcx.sess.opts.unstable_opts.print_mono_items {
Some(ref s) => {
let mode = s.to_lowercase();
let mode = mode.trim();
if mode == "eager" {
MonoItemCollectionStrategy::Eager
} else {
if mode != "lazy" {
tcx.dcx().emit_warn(UnknownCguCollectionMode { mode });
}

MonoItemCollectionStrategy::Lazy
}
}
None => {
if tcx.sess.link_dead_code() {
MonoItemCollectionStrategy::Eager
} else {
MonoItemCollectionStrategy::Lazy
}
}
let collection_strategy = if tcx.sess.link_dead_code() {
MonoItemCollectionStrategy::Eager
} else {
MonoItemCollectionStrategy::Lazy
};

let (items, usage_map) = collector::collect_crate_mono_items(tcx, collection_strategy);
Expand Down Expand Up @@ -1209,7 +1192,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> MonoItemPartitio
}
}

if tcx.sess.opts.unstable_opts.print_mono_items.is_some() {
if tcx.sess.opts.unstable_opts.print_mono_items {
let mut item_to_cgus: UnordMap<_, Vec<_>> = Default::default();

for cgu in codegen_units {
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2408,10 +2408,8 @@ options! {
"print codegen statistics (default: no)"),
print_llvm_passes: bool = (false, parse_bool, [UNTRACKED],
"print the LLVM optimization passes being run (default: no)"),
print_mono_items: Option<String> = (None, parse_opt_string, [UNTRACKED],
"print the result of the monomorphization collection pass. \
Value `lazy` means to use normal collection; `eager` means to collect all items.
Note that this overwrites the effect `-Clink-dead-code` has on collection!"),
print_mono_items: bool = (false, parse_bool, [UNTRACKED],
"print the result of the monomorphization collection pass (default: no)"),
print_type_sizes: bool = (false, parse_bool, [UNTRACKED],
"print layout information for each type encountered (default: no)"),
proc_macro_backtrace: bool = (false, parse_bool, [UNTRACKED],
Expand Down
8 changes: 2 additions & 6 deletions src/doc/rustc-dev-guide/src/tests/compiletest.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,8 @@ The tests in [`tests/codegen-units`] test the
[monomorphization](../backend/monomorph.md) collector and CGU partitioning.

These tests work by running `rustc` with a flag to print the result of the
monomorphization collection pass, and then special annotations in the file are
used to compare against that.

Each test should be annotated with the `//@
compile-flags:-Zprint-mono-items=VAL` directive with the appropriate `VAL` to
instruct `rustc` to print the monomorphization information.
monomorphization collection pass, i.e., `-Zprint-mono-items`, and then special
annotations in the file are used to compare against that.

Then, the test should be annotated with comments of the form `//~ MONO_ITEM
name` where `name` is the monomorphized string printed by rustc like `fn <u32 as
Expand Down
5 changes: 4 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,7 +1583,10 @@ impl<'test> TestCx<'test> {
Crashes => {
set_mir_dump_dir(&mut rustc);
}
Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake | CodegenUnits | RustdocJs => {
CodegenUnits => {
rustc.arg("-Zprint-mono-items");
}
Pretty | DebugInfo | Rustdoc | RustdocJson | RunMake | RustdocJs => {
// do not use JSON output
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/asm-sym.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ needs-asm-support
//@ compile-flags: -Ccodegen-units=1 -Zprint-mono-items=lazy --crate-type=lib
//@ compile-flags: -Ccodegen-units=1 --crate-type=lib

#[inline(always)]
pub unsafe fn f() {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/closures.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ edition: 2021
//@ compile-flags: -Zprint-mono-items=eager --crate-type=lib
//@ compile-flags: -Clink-dead-code --crate-type=lib

//~ MONO_ITEM fn async_fn @@
//~ MONO_ITEM fn async_fn::{closure#0} @@
Expand Down
10 changes: 5 additions & 5 deletions tests/codegen-units/item-collection/cross-crate-closures.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// We need to disable MIR inlining in both this and its aux-build crate. The MIR inliner
// will just inline everything into our start function if we let it. As it should.
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![no_main]
Expand All @@ -11,12 +11,12 @@ extern crate cgu_extern_closures;
//~ MONO_ITEM fn main @@ cross_crate_closures-cgu.0[External]
#[no_mangle]
extern "C" fn main(_: core::ffi::c_int, _: *const *const u8) -> core::ffi::c_int {
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn @@ cross_crate_closures-cgu.0[Internal]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn::{closure#0} @@ cross_crate_closures-cgu.0[Internal]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn @@ cross_crate_closures-cgu.0[External]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn::{closure#0} @@ cross_crate_closures-cgu.0[External]
let _ = cgu_extern_closures::inlined_fn(1, 2);

//~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic::<i32> @@ cross_crate_closures-cgu.0[Internal]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic::<i32>::{closure#0} @@ cross_crate_closures-cgu.0[Internal]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic::<i32> @@ cross_crate_closures-cgu.0[External]
//~ MONO_ITEM fn cgu_extern_closures::inlined_fn_generic::<i32>::{closure#0} @@ cross_crate_closures-cgu.0[External]
let _ = cgu_extern_closures::inlined_fn_generic(3, 4, 5i32);

// Nothing should be generated for this call, we just link to the instance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no -Copt-level=0
//@ compile-flags:-Clink-dead-code -Zinline-mir=no -Copt-level=0

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/drop-glue-eager.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Ensure that we *eagerly* monomorphize drop instances for structs with lifetimes.

//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags:--crate-type=lib

//~ MONO_ITEM fn std::ptr::drop_in_place::<StructWithDrop> - shim(Some(StructWithDrop))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags:-Zinline-mir=no
//@ compile-flags: -O

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-drop-glue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags: -O

#![deny(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-functions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/generic-impl.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen-units/item-collection/implicit-panic-call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags:-Zprint-mono-items=lazy

// rust-lang/rust#90405
// Ensure implicit panic calls are collected

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zmir-opt-level=0
//@ compile-flags:-Clink-dead-code -Zmir-opt-level=0

#![deny(dead_code)]
#![crate_type = "lib"]
Expand All @@ -24,15 +24,15 @@ impl<T> Trait for Struct<T> {
pub fn start(_: isize, _: *const *const u8) -> isize {
let s1 = Struct { _a: 0u32 };

//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u32>> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal]
//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u32>> - shim(None) @@ instantiation_through_vtable-cgu.0[External]
//~ MONO_ITEM fn <Struct<u32> as Trait>::foo
//~ MONO_ITEM fn <Struct<u32> as Trait>::bar
let r1 = &s1 as &Trait;
r1.foo();
r1.bar();

let s1 = Struct { _a: 0u64 };
//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u64>> - shim(None) @@ instantiation_through_vtable-cgu.0[Internal]
//~ MONO_ITEM fn std::ptr::drop_in_place::<Struct<u64>> - shim(None) @@ instantiation_through_vtable-cgu.0[External]
//~ MONO_ITEM fn <Struct<u64> as Trait>::foo
//~ MONO_ITEM fn <Struct<u64> as Trait>::bar
let _ = &s1 as &Trait;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Copt-level=0
//@ compile-flags:-Clink-dead-code -Copt-level=0

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
24 changes: 12 additions & 12 deletions tests/codegen-units/item-collection/non-generic-closures.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]

//~ MONO_ITEM fn temporary @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn temporary @@ non_generic_closures-cgu.0[External]
fn temporary() {
//~ MONO_ITEM fn temporary::{closure#0} @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn temporary::{closure#0} @@ non_generic_closures-cgu.0[External]
(|a: u32| {
let _ = a;
})(4);
}

//~ MONO_ITEM fn assigned_to_variable_but_not_executed @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn assigned_to_variable_but_not_executed @@ non_generic_closures-cgu.0[External]
fn assigned_to_variable_but_not_executed() {
//~ MONO_ITEM fn assigned_to_variable_but_not_executed::{closure#0}
let _x = |a: i16| {
let _ = a + 1;
};
}

//~ MONO_ITEM fn assigned_to_variable_executed_indirectly @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn assigned_to_variable_executed_indirectly @@ non_generic_closures-cgu.0[External]
fn assigned_to_variable_executed_indirectly() {
//~ MONO_ITEM fn assigned_to_variable_executed_indirectly::{closure#0} @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim(vtable) @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn std::ptr::drop_in_place::<{closure@TEST_PATH:28:13: 28:21}> - shim(None) @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn assigned_to_variable_executed_indirectly::{closure#0} @@ non_generic_closures-cgu.0[External]
//~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim @@ non_generic_closures-cgu.0[External]
//~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim(vtable) @@ non_generic_closures-cgu.0[External]
//~ MONO_ITEM fn std::ptr::drop_in_place::<{closure@TEST_PATH:28:13: 28:21}> - shim(None) @@ non_generic_closures-cgu.0[External]
let f = |a: i32| {
let _ = a + 2;
};
run_closure(&f);
}

//~ MONO_ITEM fn assigned_to_variable_executed_directly @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn assigned_to_variable_executed_directly @@ non_generic_closures-cgu.0[External]
fn assigned_to_variable_executed_directly() {
//~ MONO_ITEM fn assigned_to_variable_executed_directly::{closure#0} @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn assigned_to_variable_executed_directly::{closure#0} @@ non_generic_closures-cgu.0[External]
let f = |a: i64| {
let _ = a + 3;
};
Expand All @@ -51,7 +51,7 @@ pub fn start(_: isize, _: *const *const u8) -> isize {
0
}

//~ MONO_ITEM fn run_closure @@ non_generic_closures-cgu.0[Internal]
//~ MONO_ITEM fn run_closure @@ non_generic_closures-cgu.0[External]
fn run_closure(f: &Fn(i32)) {
f(3);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags: -O

#![deny(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/static-init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/statics-and-consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager -Zinline-mir=no
//@ compile-flags:-Clink-dead-code -Zinline-mir=no

#![deny(dead_code)]
#![crate_type = "lib"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags: -O

#![deny(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-units/item-collection/tuple-drop-glue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code
//@ compile-flags: -O

#![deny(dead_code)]
Expand Down
2 changes: 0 additions & 2 deletions tests/codegen-units/item-collection/unreferenced-const-fn.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags:-Zprint-mono-items=lazy

#![deny(dead_code)]
#![crate_type = "rlib"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//@ compile-flags:-Zprint-mono-items=lazy

// N.B., we do not expect *any* monomorphization to be generated here.

#![deny(dead_code)]
Expand Down
1 change: 0 additions & 1 deletion tests/codegen-units/item-collection/unsizing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Zmir-opt-level=0

#![deny(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags:-Zprint-mono-items=eager
//@ compile-flags:-Clink-dead-code

#![crate_type = "lib"]
#![deny(dead_code)]
Expand Down
Loading
Loading