Auto merge of #85178 - cjgillot:local-crate, r=oli-obk
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
This commit is contained in:
commit
3396a383bb
70 changed files with 281 additions and 404 deletions
|
@ -184,7 +184,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
|
||||
use rustc_errors::{ErrorReported, FatalError};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
|
@ -322,7 +322,7 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
|
|||
let mut roots = Vec::new();
|
||||
|
||||
{
|
||||
let entry_fn = tcx.entry_fn(LOCAL_CRATE);
|
||||
let entry_fn = tcx.entry_fn(());
|
||||
|
||||
debug!("collect_roots: entry_fn = {:?}", entry_fn);
|
||||
|
||||
|
@ -468,7 +468,7 @@ fn shrunk_instance_name(
|
|||
after = &s[positions().rev().nth(after).unwrap_or(0)..],
|
||||
);
|
||||
|
||||
let path = tcx.output_filenames(LOCAL_CRATE).temp_path_ext("long-type.txt", None);
|
||||
let path = tcx.output_filenames(()).temp_path_ext("long-type.txt", None);
|
||||
let written_to_path = std::fs::write(&path, s).ok().map(|_| path);
|
||||
|
||||
(shrunk, written_to_path)
|
||||
|
|
|
@ -451,7 +451,9 @@ fn mono_item_visibility(
|
|||
let is_generic = instance.substs.non_erasable_generics().next().is_some();
|
||||
|
||||
// Upstream `DefId` instances get different handling than local ones.
|
||||
if !def_id.is_local() {
|
||||
let def_id = if let Some(def_id) = def_id.as_local() {
|
||||
def_id
|
||||
} else {
|
||||
return if export_generics && is_generic {
|
||||
// If it is a upstream monomorphization and we export generics, we must make
|
||||
// it available to downstream crates.
|
||||
|
@ -460,7 +462,7 @@ fn mono_item_visibility(
|
|||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
if is_generic {
|
||||
if export_generics {
|
||||
|
@ -470,7 +472,7 @@ fn mono_item_visibility(
|
|||
} else {
|
||||
// This instance might be useful in a downstream crate.
|
||||
*can_be_internalized = false;
|
||||
default_visibility(tcx, def_id, true)
|
||||
default_visibility(tcx, def_id.to_def_id(), true)
|
||||
}
|
||||
} else {
|
||||
// We are not exporting generics or the definition is not reachable
|
||||
|
@ -481,10 +483,10 @@ fn mono_item_visibility(
|
|||
// If this isn't a generic function then we mark this a `Default` if
|
||||
// this is a reachable item, meaning that it's a symbol other crates may
|
||||
// access when they link to us.
|
||||
if tcx.is_reachable_non_generic(def_id) {
|
||||
if tcx.is_reachable_non_generic(def_id.to_def_id()) {
|
||||
*can_be_internalized = false;
|
||||
debug_assert!(!is_generic);
|
||||
return default_visibility(tcx, def_id, false);
|
||||
return default_visibility(tcx, def_id.to_def_id(), false);
|
||||
}
|
||||
|
||||
// If this isn't reachable then we're gonna tag this with `Hidden`
|
||||
|
|
|
@ -97,7 +97,7 @@ mod merging;
|
|||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::sync;
|
||||
use rustc_hir::def_id::{CrateNum, DefIdSet, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::DefIdSet;
|
||||
use rustc_middle::mir::mono::MonoItem;
|
||||
use rustc_middle::mir::mono::{CodegenUnit, Linkage};
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
|
@ -311,10 +311,8 @@ where
|
|||
|
||||
fn collect_and_partition_mono_items<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cnum: CrateNum,
|
||||
(): (),
|
||||
) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
|
||||
Some(ref s) => {
|
||||
let mode_string = s.to_lowercase();
|
||||
|
@ -426,8 +424,8 @@ fn collect_and_partition_mono_items<'tcx>(
|
|||
(tcx.arena.alloc(mono_items), codegen_units)
|
||||
}
|
||||
|
||||
fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx DefIdSet {
|
||||
let (items, cgus) = tcx.collect_and_partition_mono_items(cnum);
|
||||
fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx DefIdSet {
|
||||
let (items, cgus) = tcx.collect_and_partition_mono_items(());
|
||||
let mut visited = DefIdSet::default();
|
||||
let mut result = items.clone();
|
||||
|
||||
|
@ -455,12 +453,12 @@ pub fn provide(providers: &mut Providers) {
|
|||
providers.codegened_and_inlined_items = codegened_and_inlined_items;
|
||||
|
||||
providers.is_codegened_item = |tcx, def_id| {
|
||||
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
|
||||
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(());
|
||||
all_mono_items.contains(&def_id)
|
||||
};
|
||||
|
||||
providers.codegen_unit = |tcx, name| {
|
||||
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
|
||||
let (_, all) = tcx.collect_and_partition_mono_items(());
|
||||
all.iter()
|
||||
.find(|cgu| cgu.name() == name)
|
||||
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))
|
||||
|
|
|
@ -3,7 +3,7 @@ use required_consts::RequiredConstsVisitor;
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::mir::visit::Visitor as _;
|
||||
|
@ -98,14 +98,13 @@ pub(crate) fn provide(providers: &mut Providers) {
|
|||
}
|
||||
|
||||
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
tcx.mir_keys(def_id.krate).contains(&def_id.expect_local())
|
||||
let def_id = def_id.expect_local();
|
||||
tcx.mir_keys(()).contains(&def_id)
|
||||
}
|
||||
|
||||
/// Finds the full set of `DefId`s within the current crate that have
|
||||
/// MIR associated with them.
|
||||
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> {
|
||||
assert_eq!(krate, LOCAL_CRATE);
|
||||
|
||||
fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
|
||||
let mut set = FxHashSet::default();
|
||||
|
||||
// All body-owners have MIR associated with them.
|
||||
|
|
|
@ -10,7 +10,7 @@ use super::spanview::write_mir_fn_spanview;
|
|||
use crate::transform::MirSource;
|
||||
use either::Either;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::mir::interpret::{
|
||||
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer,
|
||||
|
@ -1020,6 +1020,6 @@ pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
|
|||
if let Some(i) = single {
|
||||
vec![i]
|
||||
} else {
|
||||
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect()
|
||||
tcx.mir_keys(()).iter().map(|def_id| def_id.to_def_id()).collect()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue