Skip to content

Commit 3396a38

Browse files
committed
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.
2 parents a55748f + 1ebf6d1 commit 3396a38

File tree

70 files changed

+280
-403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+280
-403
lines changed

compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn codegen(
1313
module: &mut impl Module,
1414
unwind_context: &mut UnwindContext,
1515
) -> bool {
16-
let any_dynamic_crate = tcx.dependency_formats(LOCAL_CRATE).iter().any(|(_, list)| {
16+
let any_dynamic_crate = tcx.dependency_formats(()).iter().any(|(_, list)| {
1717
use rustc_middle::middle::dependency_format::Linkage;
1818
list.iter().any(|&linkage| linkage == Linkage::Dynamic)
1919
});

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn emit_module(
4242

4343
unwind_context.emit(&mut product);
4444

45-
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name));
45+
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
4646
let obj = product.object.write().unwrap();
4747
if let Err(err) = std::fs::write(&tmp_file, obj) {
4848
tcx.sess.fatal(&format!("error writing object file: {}", err));
@@ -74,7 +74,7 @@ fn reuse_workproduct_for_cgu(
7474
let work_product = cgu.work_product(tcx);
7575
if let Some(saved_file) = &work_product.saved_file {
7676
let obj_out = tcx
77-
.output_filenames(LOCAL_CRATE)
77+
.output_filenames(())
7878
.temp_path(OutputType::Object, Some(&cgu.name().as_str()));
7979
object = Some(obj_out.clone());
8080
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
@@ -190,7 +190,7 @@ pub(crate) fn run_aot(
190190
let mut work_products = FxHashMap::default();
191191

192192
let cgus = if tcx.sess.opts.output_types.should_codegen() {
193-
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
193+
tcx.collect_and_partition_mono_items(()).1
194194
} else {
195195
// If only `--emit metadata` is used, we shouldn't perform any codegen.
196196
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
@@ -276,7 +276,7 @@ pub(crate) fn run_aot(
276276
.to_string();
277277

278278
let tmp_file = tcx
279-
.output_filenames(LOCAL_CRATE)
279+
.output_filenames(())
280280
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
281281

282282
let obj = crate::backend::with_object(tcx.sess, &metadata_cgu_name, |object| {
@@ -353,7 +353,7 @@ fn codegen_global_asm(tcx: TyCtxt<'_>, cgu_name: &str, global_asm: &str) {
353353
.join("\n");
354354

355355
let output_object_file =
356-
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name));
356+
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
357357

358358
// Assemble `global_asm`
359359
let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm");

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::os::raw::{c_char, c_int};
88
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
99
use rustc_codegen_ssa::CrateInfo;
1010
use rustc_middle::mir::mono::MonoItem;
11-
use rustc_session::config::EntryFnType;
1211

1312
use cranelift_jit::{JITBuilder, JITModule};
1413

@@ -66,7 +65,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
6665
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
6766
);
6867

69-
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
68+
let (_, cgus) = tcx.collect_and_partition_mono_items(());
7069
let mono_items = cgus
7170
.iter()
7271
.map(|cgu| cgu.items_in_deterministic_order(tcx).into_iter())
@@ -179,7 +178,7 @@ fn load_imported_symbols_for_jit(tcx: TyCtxt<'_>) -> Vec<(String, *const u8)> {
179178
let mut dylib_paths = Vec::new();
180179

181180
let crate_info = CrateInfo::new(tcx);
182-
let formats = tcx.dependency_formats(LOCAL_CRATE);
181+
let formats = tcx.dependency_formats(());
183182
let data = &formats
184183
.iter()
185184
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)

compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) fn maybe_create_entry_wrapper(
1515
unwind_context: &mut UnwindContext,
1616
is_jit: bool,
1717
) {
18-
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
18+
let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
1919
Some((def_id, entry_ty)) => (
2020
def_id,
2121
match entry_ty {

compiler/rustc_codegen_cranelift/src/pretty_clif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ pub(crate) fn write_ir_file(
214214
return;
215215
}
216216

217-
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
217+
let clif_output_dir = tcx.output_filenames(()).with_extension("clif");
218218

219219
match std::fs::create_dir(&clif_output_dir) {
220220
Ok(()) => {}

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
2020
use rustc_data_structures::small_c_str::SmallCStr;
2121
use rustc_errors::{FatalError, Handler, Level};
2222
use rustc_fs_util::{link_or_copy, path_to_c_string};
23-
use rustc_hir::def_id::LOCAL_CRATE;
2423
use rustc_middle::bug;
2524
use rustc_middle::ty::TyCtxt;
2625
use rustc_session::config::{self, Lto, OutputType, Passes, SwitchWithOptPath};
@@ -92,13 +91,12 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
9291

9392
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
9493
let split_dwarf_file = if tcx.sess.target_can_use_split_dwarf() {
95-
tcx.output_filenames(LOCAL_CRATE)
96-
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name))
94+
tcx.output_filenames(()).split_dwarf_path(tcx.sess.split_debuginfo(), Some(mod_name))
9795
} else {
9896
None
9997
};
10098
let config = TargetMachineFactoryConfig { split_dwarf_file };
101-
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(LOCAL_CRATE))(config)
99+
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(()))(config)
102100
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
103101
}
104102

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use llvm::coverageinfo::CounterMappingRegion;
66
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
77
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
88
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
9-
use rustc_hir::def_id::{DefId, DefIdSet, LOCAL_CRATE};
9+
use rustc_hir::def_id::{DefId, DefIdSet};
1010
use rustc_llvm::RustString;
1111
use rustc_middle::mir::coverage::CodeRegion;
1212
use rustc_span::Symbol;
@@ -265,7 +265,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
265265
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
266266

267267
let all_def_ids: DefIdSet = tcx
268-
.mir_keys(LOCAL_CRATE)
268+
.mir_keys(())
269269
.iter()
270270
.filter_map(|local_def_id| {
271271
let def_id = local_def_id.to_def_id();
@@ -276,7 +276,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
276276
})
277277
.collect();
278278

279-
let codegenned_def_ids = tcx.codegened_and_inlined_items(LOCAL_CRATE);
279+
let codegenned_def_ids = tcx.codegened_and_inlined_items(());
280280

281281
let mut unused_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
282282
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,10 @@ pub fn compile_unit_metadata(
995995
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
996996
let work_dir = tcx.sess.working_dir.to_string_lossy(false);
997997
let flags = "\0";
998-
let out_dir = &tcx.output_filenames(LOCAL_CRATE).out_directory;
998+
let output_filenames = tcx.output_filenames(());
999+
let out_dir = &output_filenames.out_directory;
9991000
let split_name = if tcx.sess.target_can_use_split_dwarf() {
1000-
tcx.output_filenames(LOCAL_CRATE)
1001+
output_filenames
10011002
.split_dwarf_path(tcx.sess.split_debuginfo(), Some(codegen_unit_name))
10021003
.map(|f| out_dir.join(f))
10031004
} else {
@@ -1058,15 +1059,12 @@ pub fn compile_unit_metadata(
10581059
if tcx.sess.opts.debugging_opts.profile {
10591060
let cu_desc_metadata =
10601061
llvm::LLVMRustMetadataAsValue(debug_context.llcontext, unit_metadata);
1061-
let default_gcda_path = &tcx.output_filenames(LOCAL_CRATE).with_extension("gcda");
1062+
let default_gcda_path = &output_filenames.with_extension("gcda");
10621063
let gcda_path =
10631064
tcx.sess.opts.debugging_opts.profile_emit.as_ref().unwrap_or(default_gcda_path);
10641065

10651066
let gcov_cu_info = [
1066-
path_to_mdstring(
1067-
debug_context.llcontext,
1068-
&tcx.output_filenames(LOCAL_CRATE).with_extension("gcno"),
1069-
),
1067+
path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")),
10701068
path_to_mdstring(debug_context.llcontext, &gcda_path),
10711069
cu_desc_metadata,
10721070
];

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_codegen_ssa::mir::debuginfo::{DebugScope, FunctionDebugContext, Variab
2323
use rustc_codegen_ssa::traits::*;
2424
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2525
use rustc_data_structures::sync::Lrc;
26-
use rustc_hir::def_id::{DefId, DefIdMap, LOCAL_CRATE};
26+
use rustc_hir::def_id::{DefId, DefIdMap};
2727
use rustc_index::vec::IndexVec;
2828
use rustc_middle::mir;
2929
use rustc_middle::ty::layout::HasTyCtxt;
@@ -343,7 +343,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
343343
if self.sess().opts.optimize != config::OptLevel::No {
344344
spflags |= DISPFlags::SPFlagOptimized;
345345
}
346-
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
346+
if let Some((id, _)) = self.tcx.entry_fn(()) {
347347
if id == def_id {
348348
spflags |= DISPFlags::SPFlagMainSubprogram;
349349
}

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
13031303
}
13041304
}
13051305

1306-
let formats = tcx.dependency_formats(LOCAL_CRATE);
1306+
let formats = tcx.dependency_formats(());
13071307
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
13081308

13091309
for (index, dep_format) in deps.iter().enumerate() {

0 commit comments

Comments
 (0)