Change collect_and_partition_mono_items
tuple return type to a struct
This commit is contained in:
parent
633a3fe36d
commit
b24f674520
9 changed files with 33 additions and 21 deletions
|
@ -676,7 +676,7 @@ pub(crate) fn run_aot(
|
||||||
.to_owned();
|
.to_owned();
|
||||||
|
|
||||||
let cgus = if tcx.sess.opts.output_types.should_codegen() {
|
let cgus = if tcx.sess.opts.output_types.should_codegen() {
|
||||||
tcx.collect_and_partition_mono_items(()).1
|
tcx.collect_and_partition_mono_items(()).codegen_units
|
||||||
} else {
|
} else {
|
||||||
// If only `--emit metadata` is used, we shouldn't perform any codegen.
|
// If only `--emit metadata` is used, we shouldn't perform any codegen.
|
||||||
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
|
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
|
||||||
|
|
|
@ -9,6 +9,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
|
||||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||||
use rustc_index::IndexVec;
|
use rustc_index::IndexVec;
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
|
use rustc_middle::mir::mono::MonoItemPartitions;
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
use rustc_session::RemapFileNameExt;
|
use rustc_session::RemapFileNameExt;
|
||||||
use rustc_session::config::RemapPathScopeComponents;
|
use rustc_session::config::RemapPathScopeComponents;
|
||||||
|
@ -297,12 +298,13 @@ struct UsageSets<'tcx> {
|
||||||
/// Prepare sets of definitions that are relevant to deciding whether something
|
/// Prepare sets of definitions that are relevant to deciding whether something
|
||||||
/// is an "unused function" for coverage purposes.
|
/// is an "unused function" for coverage purposes.
|
||||||
fn prepare_usage_sets<'tcx>(tcx: TyCtxt<'tcx>) -> UsageSets<'tcx> {
|
fn prepare_usage_sets<'tcx>(tcx: TyCtxt<'tcx>) -> UsageSets<'tcx> {
|
||||||
let (all_mono_items, cgus) = tcx.collect_and_partition_mono_items(());
|
let MonoItemPartitions { all_mono_items, codegen_units } =
|
||||||
|
tcx.collect_and_partition_mono_items(());
|
||||||
|
|
||||||
// Obtain a MIR body for each function participating in codegen, via an
|
// Obtain a MIR body for each function participating in codegen, via an
|
||||||
// arbitrary instance.
|
// arbitrary instance.
|
||||||
let mut def_ids_seen = FxHashSet::default();
|
let mut def_ids_seen = FxHashSet::default();
|
||||||
let def_and_mir_for_all_mono_fns = cgus
|
let def_and_mir_for_all_mono_fns = codegen_units
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|cgu| cgu.items().keys())
|
.flat_map(|cgu| cgu.items().keys())
|
||||||
.filter_map(|item| match item {
|
.filter_map(|item| match item {
|
||||||
|
|
|
@ -46,8 +46,12 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>, set_reuse: &dyn Fn(&mut CguReuseTr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let available_cgus =
|
let available_cgus = tcx
|
||||||
tcx.collect_and_partition_mono_items(()).1.iter().map(|cgu| cgu.name()).collect();
|
.collect_and_partition_mono_items(())
|
||||||
|
.codegen_units
|
||||||
|
.iter()
|
||||||
|
.map(|cgu| cgu.name())
|
||||||
|
.collect();
|
||||||
|
|
||||||
let mut ams = AssertModuleSource {
|
let mut ams = AssertModuleSource {
|
||||||
tcx,
|
tcx,
|
||||||
|
|
|
@ -293,7 +293,7 @@ fn exported_symbols_provider_local(
|
||||||
// external linkage is enough for monomorphization to be linked to.
|
// external linkage is enough for monomorphization to be linked to.
|
||||||
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
|
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
|
||||||
|
|
||||||
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
|
||||||
|
|
||||||
// The symbols created in this loop are sorted below it
|
// The symbols created in this loop are sorted below it
|
||||||
#[allow(rustc::potential_query_instability)]
|
#[allow(rustc::potential_query_instability)]
|
||||||
|
|
|
@ -619,7 +619,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
||||||
|
|
||||||
// Run the monomorphization collector and partition the collected items into
|
// Run the monomorphization collector and partition the collected items into
|
||||||
// codegen units.
|
// codegen units.
|
||||||
let codegen_units = tcx.collect_and_partition_mono_items(()).1;
|
let codegen_units = tcx.collect_and_partition_mono_items(()).codegen_units;
|
||||||
|
|
||||||
// Force all codegen_unit queries so they are already either red or green
|
// Force all codegen_unit queries so they are already either red or green
|
||||||
// when compile_codegen_unit accesses them. We are not able to re-execute
|
// when compile_codegen_unit accesses them. We are not able to re-execute
|
||||||
|
@ -1051,7 +1051,7 @@ pub(crate) fn provide(providers: &mut Providers) {
|
||||||
config::OptLevel::SizeMin => config::OptLevel::Default,
|
config::OptLevel::SizeMin => config::OptLevel::Default,
|
||||||
};
|
};
|
||||||
|
|
||||||
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
|
let defids = tcx.collect_and_partition_mono_items(cratenum).all_mono_items;
|
||||||
|
|
||||||
let any_for_speed = defids.items().any(|id| {
|
let any_for_speed = defids.items().any(|id| {
|
||||||
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
|
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_data_structures::fx::FxIndexMap;
|
||||||
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher, ToStableHashKey};
|
use rustc_data_structures::stable_hasher::{Hash128, HashStable, StableHasher, ToStableHashKey};
|
||||||
use rustc_data_structures::unord::UnordMap;
|
use rustc_data_structures::unord::UnordMap;
|
||||||
use rustc_hir::ItemId;
|
use rustc_hir::ItemId;
|
||||||
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LOCAL_CRATE};
|
||||||
use rustc_index::Idx;
|
use rustc_index::Idx;
|
||||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
||||||
use rustc_query_system::ich::StableHashingContext;
|
use rustc_query_system::ich::StableHashingContext;
|
||||||
|
@ -247,6 +247,12 @@ impl ToStableHashKey<StableHashingContext<'_>> for MonoItem<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, HashStable, Copy, Clone)]
|
||||||
|
pub struct MonoItemPartitions<'tcx> {
|
||||||
|
pub codegen_units: &'tcx [CodegenUnit<'tcx>],
|
||||||
|
pub all_mono_items: &'tcx DefIdSet,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, HashStable)]
|
#[derive(Debug, HashStable)]
|
||||||
pub struct CodegenUnit<'tcx> {
|
pub struct CodegenUnit<'tcx> {
|
||||||
/// A name for this CGU. Incremental compilation requires that
|
/// A name for this CGU. Incremental compilation requires that
|
||||||
|
|
|
@ -349,6 +349,7 @@ tcx_lifetime! {
|
||||||
rustc_middle::mir::interpret::GlobalId,
|
rustc_middle::mir::interpret::GlobalId,
|
||||||
rustc_middle::mir::interpret::LitToConstInput,
|
rustc_middle::mir::interpret::LitToConstInput,
|
||||||
rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
|
rustc_middle::mir::interpret::EvalStaticInitializerRawResult,
|
||||||
|
rustc_middle::mir::mono::MonoItemPartitions,
|
||||||
rustc_middle::traits::query::MethodAutoderefStepsResult,
|
rustc_middle::traits::query::MethodAutoderefStepsResult,
|
||||||
rustc_middle::traits::query::type_op::AscribeUserType,
|
rustc_middle::traits::query::type_op::AscribeUserType,
|
||||||
rustc_middle::traits::query::type_op::Eq,
|
rustc_middle::traits::query::type_op::Eq,
|
||||||
|
|
|
@ -23,7 +23,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||||
use rustc_errors::ErrorGuaranteed;
|
use rustc_errors::ErrorGuaranteed;
|
||||||
use rustc_hir::def::{DefKind, DocLinkResMap};
|
use rustc_hir::def::{DefKind, DocLinkResMap};
|
||||||
use rustc_hir::def_id::{
|
use rustc_hir::def_id::{
|
||||||
CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
|
CrateNum, DefId, DefIdMap, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
|
||||||
};
|
};
|
||||||
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
||||||
use rustc_hir::{Crate, ItemLocalId, ItemLocalMap, TraitCandidate};
|
use rustc_hir::{Crate, ItemLocalId, ItemLocalMap, TraitCandidate};
|
||||||
|
@ -58,7 +58,7 @@ use crate::mir::interpret::{
|
||||||
EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult,
|
EvalStaticInitializerRawResult, EvalToAllocationRawResult, EvalToConstValueResult,
|
||||||
EvalToValTreeResult, GlobalId, LitToConstInput,
|
EvalToValTreeResult, GlobalId, LitToConstInput,
|
||||||
};
|
};
|
||||||
use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem};
|
use crate::mir::mono::{CodegenUnit, CollectionMode, MonoItem, MonoItemPartitions};
|
||||||
use crate::query::erase::{Erase, erase, restore};
|
use crate::query::erase::{Erase, erase, restore};
|
||||||
use crate::query::plumbing::{
|
use crate::query::plumbing::{
|
||||||
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
|
CyclePlaceholder, DynamicQuery, query_ensure, query_ensure_error_guaranteed, query_get_at,
|
||||||
|
@ -2166,7 +2166,7 @@ rustc_queries! {
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
||||||
query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
|
query collect_and_partition_mono_items(_: ()) -> MonoItemPartitions<'tcx> {
|
||||||
eval_always
|
eval_always
|
||||||
desc { "collect_and_partition_mono_items" }
|
desc { "collect_and_partition_mono_items" }
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||||
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
|
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
|
||||||
use rustc_middle::mir::mono::{
|
use rustc_middle::mir::mono::{
|
||||||
CodegenUnit, CodegenUnitNameBuilder, InstantiationMode, Linkage, MonoItem, MonoItemData,
|
CodegenUnit, CodegenUnitNameBuilder, InstantiationMode, Linkage, MonoItem, MonoItemData,
|
||||||
Visibility,
|
MonoItemPartitions, Visibility,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::print::{characteristic_def_id_of_type, with_no_trimmed_paths};
|
use rustc_middle::ty::print::{characteristic_def_id_of_type, with_no_trimmed_paths};
|
||||||
use rustc_middle::ty::{self, InstanceKind, TyCtxt};
|
use rustc_middle::ty::{self, InstanceKind, TyCtxt};
|
||||||
|
@ -1114,7 +1114,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[CodegenUnit<'_>]) {
|
fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> MonoItemPartitions<'_> {
|
||||||
let collection_strategy = match tcx.sess.opts.unstable_opts.print_mono_items {
|
let collection_strategy = match tcx.sess.opts.unstable_opts.print_mono_items {
|
||||||
Some(ref s) => {
|
Some(ref s) => {
|
||||||
let mode = s.to_lowercase();
|
let mode = s.to_lowercase();
|
||||||
|
@ -1236,7 +1236,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(tcx.arena.alloc(mono_items), codegen_units)
|
MonoItemPartitions { all_mono_items: tcx.arena.alloc(mono_items), codegen_units }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Outputs stats about instantiation counts and estimated size, per `MonoItem`'s
|
/// Outputs stats about instantiation counts and estimated size, per `MonoItem`'s
|
||||||
|
@ -1319,14 +1319,13 @@ fn dump_mono_items_stats<'tcx>(
|
||||||
pub(crate) fn provide(providers: &mut Providers) {
|
pub(crate) fn provide(providers: &mut Providers) {
|
||||||
providers.collect_and_partition_mono_items = collect_and_partition_mono_items;
|
providers.collect_and_partition_mono_items = collect_and_partition_mono_items;
|
||||||
|
|
||||||
providers.is_codegened_item = |tcx, def_id| {
|
providers.is_codegened_item =
|
||||||
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(());
|
|tcx, def_id| tcx.collect_and_partition_mono_items(()).all_mono_items.contains(&def_id);
|
||||||
all_mono_items.contains(&def_id)
|
|
||||||
};
|
|
||||||
|
|
||||||
providers.codegen_unit = |tcx, name| {
|
providers.codegen_unit = |tcx, name| {
|
||||||
let (_, all) = tcx.collect_and_partition_mono_items(());
|
tcx.collect_and_partition_mono_items(())
|
||||||
all.iter()
|
.codegen_units
|
||||||
|
.iter()
|
||||||
.find(|cgu| cgu.name() == name)
|
.find(|cgu| cgu.name() == name)
|
||||||
.unwrap_or_else(|| panic!("failed to find cgu with name {name:?}"))
|
.unwrap_or_else(|| panic!("failed to find cgu with name {name:?}"))
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue