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:
bors 2021-05-17 01:42:03 +00:00
commit 3c53005949
5 changed files with 10 additions and 11 deletions

View File

@ -13,7 +13,7 @@ pub(crate) fn codegen(
module: &mut impl Module,
unwind_context: &mut UnwindContext,
) -> bool {
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)
});

View File

@ -42,7 +42,7 @@ fn emit_module(
unwind_context.emit(&mut product);
let tmp_file = tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(&name));
let tmp_file = tcx.output_filenames(()).temp_path(OutputType::Object, Some(&name));
let obj = product.object.write().unwrap();
if let Err(err) = std::fs::write(&tmp_file, obj) {
tcx.sess.fatal(&format!("error writing object file: {}", err));
@ -74,7 +74,7 @@ fn reuse_workproduct_for_cgu(
let work_product = cgu.work_product(tcx);
if let Some(saved_file) = &work_product.saved_file {
let obj_out = tcx
.output_filenames(LOCAL_CRATE)
.output_filenames(())
.temp_path(OutputType::Object, Some(&cgu.name().as_str()));
object = Some(obj_out.clone());
let source_file = rustc_incremental::in_incr_comp_dir(&incr_comp_session_dir, &saved_file);
@ -190,7 +190,7 @@ pub(crate) fn run_aot(
let mut work_products = FxHashMap::default();
let cgus = if tcx.sess.opts.output_types.should_codegen() {
tcx.collect_and_partition_mono_items(LOCAL_CRATE).1
tcx.collect_and_partition_mono_items(()).1
} else {
// If only `--emit metadata` is used, we shouldn't perform any codegen.
// Also `tcx.collect_and_partition_mono_items` may panic in that case.
@ -276,7 +276,7 @@ pub(crate) fn run_aot(
.to_string();
let tmp_file = tcx
.output_filenames(LOCAL_CRATE)
.output_filenames(())
.temp_path(OutputType::Metadata, Some(&metadata_cgu_name));
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) {
.join("\n");
let output_object_file =
tcx.output_filenames(LOCAL_CRATE).temp_path(OutputType::Object, Some(cgu_name));
tcx.output_filenames(()).temp_path(OutputType::Object, Some(cgu_name));
// Assemble `global_asm`
let global_asm_object_file = add_file_stem_postfix(output_object_file.clone(), ".asm");

View File

@ -8,7 +8,6 @@ use std::os::raw::{c_char, c_int};
use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
use rustc_codegen_ssa::CrateInfo;
use rustc_middle::mir::mono::MonoItem;
use rustc_session::config::EntryFnType;
use cranelift_jit::{JITBuilder, JITModule};
@ -66,7 +65,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
matches!(backend_config.codegen_mode, CodegenMode::JitLazy),
);
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
let (_, cgus) = tcx.collect_and_partition_mono_items(());
let mono_items = cgus
.iter()
.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)> {
let mut dylib_paths = Vec::new();
let crate_info = CrateInfo::new(tcx);
let formats = tcx.dependency_formats(LOCAL_CRATE);
let formats = tcx.dependency_formats(());
let data = &formats
.iter()
.find(|(crate_type, _data)| *crate_type == rustc_session::config::CrateType::Executable)

View File

@ -15,7 +15,7 @@ pub(crate) fn maybe_create_entry_wrapper(
unwind_context: &mut UnwindContext,
is_jit: bool,
) {
let (main_def_id, is_main_fn) = match tcx.entry_fn(LOCAL_CRATE) {
let (main_def_id, is_main_fn) = match tcx.entry_fn(()) {
Some((def_id, entry_ty)) => (
def_id,
match entry_ty {

View File

@ -214,7 +214,7 @@ pub(crate) fn write_ir_file(
return;
}
let clif_output_dir = tcx.output_filenames(LOCAL_CRATE).with_extension("clif");
let clif_output_dir = tcx.output_filenames(()).with_extension("clif");
match std::fs::create_dir(&clif_output_dir) {
Ok(()) => {}