Skip to content

Commit 0bde3b1

Browse files
committed
Use () for codegen queries.
1 parent 4e8d4bd commit 0bde3b1

File tree

15 files changed

+40
-56
lines changed

15 files changed

+40
-56
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/driver/aot.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn emit_module(
4141

4242
unwind_context.emit(&mut product);
4343

44-
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name));
44+
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
4545
let obj = product.object.write().unwrap();
4646
if let Err(err) = std::fs::write(&tmp_file, obj) {
4747
tcx.sess.fatal(&format!("error writing object file: {}", err));
@@ -73,7 +73,7 @@ fn reuse_workproduct_for_cgu(
7373
let work_product = cgu.work_product(tcx);
7474
if let Some(saved_file) = &work_product.saved_file {
7575
let obj_out = tcx
76-
.output_filenames(LOCAL_CRATE)
76+
.output_filenames(())
7777
.temp_path(OutputType::Object, Some(&cgu.name().as_str()));
7878
object = Some(obj_out.clone());
7979
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
@@ -179,7 +179,7 @@ pub(crate) fn run_aot(
179179
let mut work_products = FxHashMap::default();
180180

181181
let cgus = if tcx.sess.opts.output_types.should_codegen() {
182-
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
182+
tcx.collect_and_partition_mono_items(()).1
183183
} else {
184184
// If only `--emit metadata` is used, we shouldn't perform any codegen.
185185
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
@@ -265,7 +265,7 @@ pub(crate) fn run_aot(
265265
.to_string();
266266

267267
let tmp_file = tcx
268-
.output_filenames(LOCAL_CRATE)
268+
.output_filenames(())
269269
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
270270

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

344344
let output_object_file =
345-
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name));
345+
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
346346

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

Diff for: compiler/rustc_codegen_cranelift/src/driver/jit.rs

+1-2
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())

Diff for: compiler/rustc_codegen_cranelift/src/pretty_clif.rs

+1-1
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(()) => {}

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+2-4
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

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-2
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;
@@ -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) {

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+5-7
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.0.to_string_lossy();
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
];

Diff for: compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn exported_symbols_provider_local(
230230
// external linkage is enough for monomorphization to be linked to.
231231
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
232232

233-
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
233+
let (_, cgus) = tcx.collect_and_partition_mono_items(());
234234

235235
for (mono_item, &(linkage, visibility)) in cgus.iter().flat_map(|cgu| cgu.items().iter()) {
236236
if linkage != Linkage::External {
@@ -275,10 +275,8 @@ fn exported_symbols_provider_local(
275275

276276
fn upstream_monomorphizations_provider(
277277
tcx: TyCtxt<'_>,
278-
cnum: CrateNum,
278+
(): (),
279279
) -> DefIdMap<FxHashMap<SubstsRef<'_>, CrateNum>> {
280-
debug_assert!(cnum == LOCAL_CRATE);
281-
282280
let cnums = tcx.all_crate_nums(());
283281

284282
let mut instances: DefIdMap<FxHashMap<_, _>> = Default::default();
@@ -341,7 +339,7 @@ fn upstream_monomorphizations_for_provider(
341339
def_id: DefId,
342340
) -> Option<&FxHashMap<SubstsRef<'_>, CrateNum>> {
343341
debug_assert!(!def_id.is_local());
344-
tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id)
342+
tcx.upstream_monomorphizations(()).get(&def_id)
345343
}
346344

347345
fn upstream_drop_glue_for_provider<'tcx>(

Diff for: compiler/rustc_codegen_ssa/src/back/write.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
482482
codegen_worker_receive,
483483
shared_emitter_main,
484484
future: coordinator_thread,
485-
output_filenames: tcx.output_filenames(LOCAL_CRATE),
485+
output_filenames: tcx.output_filenames(()),
486486
}
487487
}
488488

@@ -1042,7 +1042,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
10421042
// If we know that we won’t be doing codegen, create target machines without optimisation.
10431043
config::OptLevel::No
10441044
} else {
1045-
tcx.backend_optimization_level(LOCAL_CRATE)
1045+
tcx.backend_optimization_level(())
10461046
};
10471047
let cgcx = CodegenContext::<B> {
10481048
backend: backend.clone(),
@@ -1061,7 +1061,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
10611061
cgu_reuse_tracker: sess.cgu_reuse_tracker.clone(),
10621062
coordinator_send,
10631063
diag_emitter: shared_emitter.clone(),
1064-
output_filenames: tcx.output_filenames(LOCAL_CRATE),
1064+
output_filenames: tcx.output_filenames(()),
10651065
regular_module_config: regular_config,
10661066
metadata_module_config: metadata_config,
10671067
allocator_module_config: allocator_config,

Diff for: compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
485485

486486
// Run the monomorphization collector and partition the collected items into
487487
// codegen units.
488-
let codegen_units = tcx.collect_and_partition_mono_items(LOCAL_CRATE).1;
488+
let codegen_units = tcx.collect_and_partition_mono_items(()).1;
489489

490490
// Force all codegen_unit queries so they are already either red or green
491491
// when compile_codegen_unit accesses them. We are not able to re-execute

Diff for: compiler/rustc_incremental/src/assert_module_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub fn assert_module_sources(tcx: TyCtxt<'_>) {
3636
}
3737

3838
let available_cgus = tcx
39-
.collect_and_partition_mono_items(LOCAL_CRATE)
39+
.collect_and_partition_mono_items(())
4040
.1
4141
.iter()
4242
.map(|cgu| cgu.name().to_string())

Diff for: compiler/rustc_middle/src/query/mod.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,9 @@ rustc_queries! {
11501150
/// added or removed in any upstream crate. Instead use the narrower
11511151
/// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
11521152
/// better, `Instance::upstream_monomorphization()`.
1153-
query upstream_monomorphizations(
1154-
k: CrateNum
1155-
) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
1153+
query upstream_monomorphizations(_: ()) -> DefIdMap<FxHashMap<SubstsRef<'tcx>, CrateNum>> {
11561154
storage(ArenaCacheSelector<'tcx>)
1157-
desc { "collecting available upstream monomorphizations `{:?}`", k }
1155+
desc { "collecting available upstream monomorphizations" }
11581156
}
11591157

11601158
/// Returns the set of upstream monomorphizations available for the
@@ -1434,8 +1432,7 @@ rustc_queries! {
14341432
desc { "exported_symbols" }
14351433
}
14361434

1437-
query collect_and_partition_mono_items(_: CrateNum)
1438-
-> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
1435+
query collect_and_partition_mono_items(_: ()) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
14391436
eval_always
14401437
desc { "collect_and_partition_mono_items" }
14411438
}
@@ -1444,8 +1441,7 @@ rustc_queries! {
14441441
}
14451442

14461443
/// All items participating in code generation together with items inlined into them.
1447-
query codegened_and_inlined_items(_: CrateNum)
1448-
-> &'tcx DefIdSet {
1444+
query codegened_and_inlined_items(_: ()) -> &'tcx DefIdSet {
14491445
eval_always
14501446
desc { "codegened_and_inlined_items" }
14511447
}
@@ -1460,11 +1456,11 @@ rustc_queries! {
14601456
tcx.def_path_str(key)
14611457
}
14621458
}
1463-
query backend_optimization_level(_: CrateNum) -> OptLevel {
1459+
query backend_optimization_level(_: ()) -> OptLevel {
14641460
desc { "optimization level used by backend" }
14651461
}
14661462

1467-
query output_filenames(_: CrateNum) -> Arc<OutputFilenames> {
1463+
query output_filenames(_: ()) -> Arc<OutputFilenames> {
14681464
eval_always
14691465
desc { "output_filenames" }
14701466
}

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -2816,10 +2816,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
28162816
};
28172817
providers.extern_mod_stmt_cnum = |tcx, id| tcx.extern_crate_map.get(&id).cloned();
28182818
providers.all_crate_nums = |tcx, ()| tcx.arena.alloc_slice(&tcx.cstore.crates_untracked());
2819-
providers.output_filenames = |tcx, cnum| {
2820-
assert_eq!(cnum, LOCAL_CRATE);
2821-
tcx.output_filenames.clone()
2822-
};
2819+
providers.output_filenames = |tcx, ()| tcx.output_filenames.clone();
28232820
providers.features_query = |tcx, ()| tcx.sess.features_untracked();
28242821
providers.is_panic_runtime = |tcx, cnum| {
28252822
assert_eq!(cnum, LOCAL_CRATE);

Diff for: compiler/rustc_mir/src/monomorphize/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
184184
use rustc_data_structures::sync::{par_iter, MTLock, MTRef, ParallelIterator};
185185
use rustc_errors::{ErrorReported, FatalError};
186186
use rustc_hir as hir;
187-
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
187+
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
188188
use rustc_hir::itemlikevisit::ItemLikeVisitor;
189189
use rustc_hir::lang_items::LangItem;
190190
use rustc_index::bit_set::GrowableBitSet;
@@ -452,7 +452,7 @@ fn shrunk_instance_name(
452452
after = &s[positions().rev().nth(after).unwrap_or(0)..],
453453
);
454454

455-
let path = tcx.output_filenames(LOCAL_CRATE).temp_path_ext("long-type.txt", None);
455+
let path = tcx.output_filenames(()).temp_path_ext("long-type.txt", None);
456456
let written_to_path = std::fs::write(&path, s).ok().map(|_| path);
457457

458458
(shrunk, written_to_path)

Diff for: compiler/rustc_mir/src/monomorphize/partitioning/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod merging;
9797

9898
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
9999
use rustc_data_structures::sync;
100-
use rustc_hir::def_id::{CrateNum, DefIdSet, LOCAL_CRATE};
100+
use rustc_hir::def_id::DefIdSet;
101101
use rustc_middle::mir::mono::MonoItem;
102102
use rustc_middle::mir::mono::{CodegenUnit, Linkage};
103103
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -311,10 +311,8 @@ where
311311

312312
fn collect_and_partition_mono_items<'tcx>(
313313
tcx: TyCtxt<'tcx>,
314-
cnum: CrateNum,
314+
(): (),
315315
) -> (&'tcx DefIdSet, &'tcx [CodegenUnit<'tcx>]) {
316-
assert_eq!(cnum, LOCAL_CRATE);
317-
318316
let collection_mode = match tcx.sess.opts.debugging_opts.print_mono_items {
319317
Some(ref s) => {
320318
let mode_string = s.to_lowercase();
@@ -426,8 +424,8 @@ fn collect_and_partition_mono_items<'tcx>(
426424
(tcx.arena.alloc(mono_items), codegen_units)
427425
}
428426

429-
fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, cnum: CrateNum) -> &'tcx DefIdSet {
430-
let (items, cgus) = tcx.collect_and_partition_mono_items(cnum);
427+
fn codegened_and_inlined_items<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> &'tcx DefIdSet {
428+
let (items, cgus) = tcx.collect_and_partition_mono_items(());
431429
let mut visited = DefIdSet::default();
432430
let mut result = items.clone();
433431

@@ -455,12 +453,12 @@ pub fn provide(providers: &mut Providers) {
455453
providers.codegened_and_inlined_items = codegened_and_inlined_items;
456454

457455
providers.is_codegened_item = |tcx, def_id| {
458-
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
456+
let (all_mono_items, _) = tcx.collect_and_partition_mono_items(());
459457
all_mono_items.contains(&def_id)
460458
};
461459

462460
providers.codegen_unit = |tcx, name| {
463-
let (_, all) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
461+
let (_, all) = tcx.collect_and_partition_mono_items(());
464462
all.iter()
465463
.find(|cgu| cgu.name() == name)
466464
.unwrap_or_else(|| panic!("failed to find cgu with name {:?}", name))

Diff for: compiler/rustc_save_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'tcx> SaveContext<'tcx> {
9595
let sess = &self.tcx.sess;
9696
// Save-analysis is emitted per whole session, not per each crate type
9797
let crate_type = sess.crate_types()[0];
98-
let outputs = &*self.tcx.output_filenames(LOCAL_CRATE);
98+
let outputs = &*self.tcx.output_filenames(());
9999

100100
if outputs.outputs.contains_key(&OutputType::Metadata) {
101101
filename_for_metadata(sess, crate_name, outputs)

0 commit comments

Comments
 (0)