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
|
@ -1303,7 +1303,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
|
|||
}
|
||||
}
|
||||
|
||||
let formats = tcx.dependency_formats(LOCAL_CRATE);
|
||||
let formats = tcx.dependency_formats(());
|
||||
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
|
||||
|
||||
for (index, dep_format) in deps.iter().enumerate() {
|
||||
|
|
|
@ -4,7 +4,7 @@ use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
|
|||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::Node;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
|
@ -60,7 +60,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
|||
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
|
||||
|
||||
let mut reachable_non_generics: DefIdMap<_> = tcx
|
||||
.reachable_set(LOCAL_CRATE)
|
||||
.reachable_set(())
|
||||
.iter()
|
||||
.filter_map(|&def_id| {
|
||||
// We want to ignore some FFI functions that are not exposed from
|
||||
|
@ -133,12 +133,12 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
|||
})
|
||||
.collect();
|
||||
|
||||
if let Some(id) = tcx.proc_macro_decls_static(LOCAL_CRATE) {
|
||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||
if let Some(id) = tcx.proc_macro_decls_static(()) {
|
||||
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
|
||||
}
|
||||
|
||||
if let Some(id) = tcx.plugin_registrar_fn(LOCAL_CRATE) {
|
||||
reachable_non_generics.insert(id, SymbolExportLevel::C);
|
||||
if let Some(id) = tcx.plugin_registrar_fn(()) {
|
||||
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
|
||||
}
|
||||
|
||||
reachable_non_generics
|
||||
|
@ -174,7 +174,7 @@ fn exported_symbols_provider_local(
|
|||
.map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level))
|
||||
.collect();
|
||||
|
||||
if tcx.entry_fn(LOCAL_CRATE).is_some() {
|
||||
if tcx.entry_fn(()).is_some() {
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
|
||||
|
||||
symbols.push((exported_symbol, SymbolExportLevel::C));
|
||||
|
@ -230,7 +230,7 @@ fn exported_symbols_provider_local(
|
|||
// external linkage is enough for monomorphization to be linked to.
|
||||
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
|
||||
|
||||
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
|
||||
let (_, cgus) = tcx.collect_and_partition_mono_items(());
|
||||
|
||||
for (mono_item, &(linkage, visibility)) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
|
||||
if linkage != Linkage::External {
|
||||
|
@ -275,11 +275,9 @@ fn exported_symbols_provider_local(
|
|||
|
||||
fn upstream_monomorphizations_provider(
|
||||
tcx: TyCtxt<'_>,
|
||||
cnum: CrateNum,
|
||||
(): (),
|
||||
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
|
||||
debug_assert!(cnum == LOCAL_CRATE);
|
||||
|
||||
let cnums = tcx.all_crate_nums(LOCAL_CRATE);
|
||||
let cnums = tcx.all_crate_nums(());
|
||||
|
||||
let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();
|
||||
|
||||
|
@ -341,7 +339,7 @@ fn upstream_monomorphizations_for_provider(
|
|||
def_id: DefId,
|
||||
) -> Option<&FxHashMap<SubstsRef<'_>, CrateNum>> {
|
||||
debug_assert!(!def_id.is_local());
|
||||
tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id)
|
||||
tcx.upstream_monomorphizations(()).get(&def_id)
|
||||
}
|
||||
|
||||
fn upstream_drop_glue_for_provider<'tcx>(
|
||||
|
@ -355,12 +353,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
!tcx.reachable_set(LOCAL_CRATE).contains(&def_id)
|
||||
} else {
|
||||
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
|
||||
}
|
||||
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
!tcx.reachable_set(()).contains(&def_id)
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
|
|
|
@ -482,7 +482,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
|
|||
codegen_worker_receive,
|
||||
shared_emitter_main,
|
||||
future: coordinator_thread,
|
||||
output_filenames: tcx.output_filenames(LOCAL_CRATE),
|
||||
output_filenames: tcx.output_filenames(()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1042,7 +1042,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
|||
// If we know that we won’t be doing codegen, create target machines without optimisation.
|
||||
config::OptLevel::No
|
||||
} else {
|
||||
tcx.backend_optimization_level(LOCAL_CRATE)
|
||||
tcx.backend_optimization_level(())
|
||||
};
|
||||
let cgcx = CodegenContext::<B> {
|
||||
backend: backend.clone(),
|
||||
|
@ -1061,7 +1061,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
|
|||
cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(),
|
||||
coordinator_send,
|
||||
diag_emitter: shared_emitter.clone(),
|
||||
output_filenames: tcx.output_filenames(LOCAL_CRATE),
|
||||
output_filenames: tcx.output_filenames(()),
|
||||
regular_module_config: regular_config,
|
||||
metadata_module_config: metadata_config,
|
||||
allocator_module_config: allocator_config,
|
||||
|
|
|
@ -347,7 +347,7 @@ pub fn codegen_instance<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
cx: &'a Bx::CodegenCx,
|
||||
) -> Option<Bx::Function> {
|
||||
let main_def_id = cx.tcx().entry_fn(LOCAL_CRATE).map(|(def_id, _)| def_id)?;
|
||||
let (main_def_id, entry_type) = cx.tcx().entry_fn(())?;
|
||||
let main_is_local = main_def_id.is_local();
|
||||
let instance = Instance::mono(cx.tcx(), main_def_id);
|
||||
|
||||
|
@ -364,10 +364,9 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
|||
|
||||
let main_llfn = cx.get_fn_addr(instance);
|
||||
|
||||
return cx.tcx().entry_fn(LOCAL_CRATE).map(|(_, et)| {
|
||||
let use_start_lang_item = EntryFnType::Start != et;
|
||||
create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item)
|
||||
});
|
||||
let use_start_lang_item = EntryFnType::Start != entry_type;
|
||||
let entry_fn = create_entry_fn::<Bx>(cx, main_llfn, main_def_id, use_start_lang_item);
|
||||
return Some(entry_fn);
|
||||
|
||||
fn create_entry_fn<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
|
||||
cx: &'a Bx::CodegenCx,
|
||||
|
@ -487,7 +486,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
|||
|
||||
// Run the monomorphization collector and partition the collected items into
|
||||
// codegen units.
|
||||
let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1;
|
||||
let codegen_units = tcx.collect_and_partition_mono_items(()).1;
|
||||
|
||||
// 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
|
||||
|
@ -512,7 +511,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
|||
// linkage, then it's already got an allocator shim and we'll be using that
|
||||
// one instead. If nothing exists then it's our job to generate the
|
||||
// allocator!
|
||||
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| {
|
||||
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
|
||||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
|
||||
});
|
||||
|
@ -769,7 +768,7 @@ impl CrateInfo {
|
|||
used_crate_source: Default::default(),
|
||||
lang_item_to_crate: Default::default(),
|
||||
missing_lang_items: Default::default(),
|
||||
dependency_formats: tcx.dependency_formats(LOCAL_CRATE),
|
||||
dependency_formats: tcx.dependency_formats(()),
|
||||
};
|
||||
let lang_items = tcx.lang_items();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue