mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-06 08:36:52 -04:00
Replace CodegenResults with CompiledModules
This is already CodegenResults without CrateInfo. The driver can calculate the CrateInfo and pass it by-ref to the backend. Using CompiledModules makes it a bit easier to move some other things out of the backend as will be necessary for moving LTO to the link phase.
This commit is contained in:
@@ -12,7 +12,7 @@ use cranelift_object::{ObjectBuilder, ObjectModule};
|
||||
use rustc_codegen_ssa::assert_module_sources::CguReuse;
|
||||
use rustc_codegen_ssa::back::write::produce_final_output_artifacts;
|
||||
use rustc_codegen_ssa::base::determine_cgu_reuse;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, CompiledModules, CrateInfo, ModuleKind};
|
||||
use rustc_codegen_ssa::{CompiledModule, CompiledModules, ModuleKind};
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::{IntoDynSyncSend, par_map};
|
||||
@@ -54,7 +54,6 @@ impl<HCX> HashStable<HCX> for OngoingModuleCodegen {
|
||||
pub(crate) struct OngoingCodegen {
|
||||
modules: Vec<OngoingModuleCodegen>,
|
||||
allocator_module: Option<CompiledModule>,
|
||||
crate_info: CrateInfo,
|
||||
concurrency_limiter: ConcurrencyLimiter,
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ impl OngoingCodegen {
|
||||
self,
|
||||
sess: &Session,
|
||||
outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
let mut work_products = FxIndexMap::default();
|
||||
let mut modules = vec![];
|
||||
let disable_incr_cache = disable_incr_cache();
|
||||
@@ -126,7 +125,7 @@ impl OngoingCodegen {
|
||||
|
||||
produce_final_output_artifacts(sess, &compiled_modules, outputs);
|
||||
|
||||
(CodegenResults { compiled_modules, crate_info: self.crate_info }, work_products)
|
||||
(compiled_modules, work_products)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,13 +474,6 @@ fn emit_allocator_module(tcx: TyCtxt<'_>) -> Option<CompiledModule> {
|
||||
}
|
||||
|
||||
pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
|
||||
// FIXME handle `-Ctarget-cpu=native`
|
||||
let target_cpu = match tcx.sess.opts.cg.target_cpu {
|
||||
Some(ref name) => name,
|
||||
None => tcx.sess.target.cpu.as_ref(),
|
||||
}
|
||||
.to_owned();
|
||||
|
||||
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
|
||||
|
||||
if tcx.dep_graph.is_fully_enabled() {
|
||||
@@ -541,7 +533,6 @@ pub(crate) fn run_aot(tcx: TyCtxt<'_>) -> Box<OngoingCodegen> {
|
||||
Box::new(OngoingCodegen {
|
||||
modules,
|
||||
allocator_module,
|
||||
crate_info: CrateInfo::new(tcx, target_cpu),
|
||||
concurrency_limiter: concurrency_limiter.0,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@ use crate::debuginfo::TypeDebugContext;
|
||||
use crate::prelude::*;
|
||||
use crate::unwind_module::UnwindModule;
|
||||
|
||||
fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, Option<DebugContext>) {
|
||||
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
|
||||
|
||||
fn create_jit_module(
|
||||
tcx: TyCtxt<'_>,
|
||||
crate_info: &CrateInfo,
|
||||
) -> (UnwindModule<JITModule>, Option<DebugContext>) {
|
||||
let isa = crate::build_isa(tcx.sess, true);
|
||||
let mut jit_builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
|
||||
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
|
||||
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info));
|
||||
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info.clone()));
|
||||
let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
|
||||
|
||||
let cx = DebugContext::new(tcx, jit_module.isa(), false, "dummy_cgu_name");
|
||||
@@ -32,14 +33,14 @@ fn create_jit_module(tcx: TyCtxt<'_>) -> (UnwindModule<JITModule>, Option<DebugC
|
||||
(jit_module, cx)
|
||||
}
|
||||
|
||||
pub(crate) fn run_jit(tcx: TyCtxt<'_>, jit_args: Vec<String>) -> ! {
|
||||
pub(crate) fn run_jit(tcx: TyCtxt<'_>, crate_info: &CrateInfo, jit_args: Vec<String>) -> ! {
|
||||
if !tcx.crate_types().contains(&rustc_session::config::CrateType::Executable) {
|
||||
tcx.dcx().fatal("can't jit non-executable crate");
|
||||
}
|
||||
|
||||
let output_filenames = tcx.output_filenames(());
|
||||
let should_write_ir = crate::pretty_clif::should_write_ir(tcx.sess);
|
||||
let (mut jit_module, mut debug_context) = create_jit_module(tcx);
|
||||
let (mut jit_module, mut debug_context) = create_jit_module(tcx, crate_info);
|
||||
let mut cached_context = Context::new();
|
||||
|
||||
let cgus = tcx.collect_and_partition_mono_items(()).codegen_units;
|
||||
|
||||
@@ -40,7 +40,7 @@ use std::sync::Arc;
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::settings::{self, Configurable};
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CodegenResults, TargetConfig};
|
||||
use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig};
|
||||
use rustc_log::tracing::info;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_session::Session;
|
||||
@@ -200,12 +200,21 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
println!("Cranelift version: {}", cranelift_codegen::VERSION);
|
||||
}
|
||||
|
||||
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
|
||||
fn target_cpu(&self, sess: &Session) -> String {
|
||||
// FIXME handle `-Ctarget-cpu=native`
|
||||
match sess.opts.cg.target_cpu {
|
||||
Some(ref name) => name,
|
||||
None => sess.target.cpu.as_ref(),
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
|
||||
fn codegen_crate(&self, tcx: TyCtxt<'_>, _crate_info: &CrateInfo) -> Box<dyn Any> {
|
||||
info!("codegen crate {}", tcx.crate_name(LOCAL_CRATE));
|
||||
let config = self.config.get().unwrap();
|
||||
if config.jit_mode {
|
||||
#[cfg(feature = "jit")]
|
||||
driver::jit::run_jit(tcx, config.jit_args.clone());
|
||||
driver::jit::run_jit(tcx, _crate_info, config.jit_args.clone());
|
||||
|
||||
#[cfg(not(feature = "jit"))]
|
||||
tcx.dcx().fatal("jit support was disabled when compiling rustc_codegen_cranelift");
|
||||
@@ -219,7 +228,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
sess: &Session,
|
||||
outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(sess, outputs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ use rustc_codegen_ssa::back::write::{
|
||||
use rustc_codegen_ssa::base::codegen_crate;
|
||||
use rustc_codegen_ssa::target_features::cfg_target_feature;
|
||||
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, WriteBackendMethods};
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen, TargetConfig};
|
||||
use rustc_codegen_ssa::{CompiledModule, CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
use rustc_data_structures::sync::IntoDynSyncSend;
|
||||
@@ -287,11 +287,12 @@ impl CodegenBackend for GccCodegenBackend {
|
||||
|tcx, ()| gcc_util::global_gcc_features(tcx.sess)
|
||||
}
|
||||
|
||||
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
|
||||
let target_cpu = target_cpu(tcx.sess);
|
||||
let res = codegen_crate(self.clone(), tcx, target_cpu.to_string());
|
||||
fn target_cpu(&self, sess: &Session) -> String {
|
||||
target_cpu(sess).to_owned()
|
||||
}
|
||||
|
||||
Box::new(res)
|
||||
fn codegen_crate(&self, tcx: TyCtxt<'_>, crate_info: &CrateInfo) -> Box<dyn Any> {
|
||||
Box::new(codegen_crate(self.clone(), tcx, crate_info))
|
||||
}
|
||||
|
||||
fn join_codegen(
|
||||
@@ -299,7 +300,7 @@ impl CodegenBackend for GccCodegenBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
sess: &Session,
|
||||
_outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
ongoing_codegen
|
||||
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<GccCodegenBackend>>()
|
||||
.expect("Expected GccCodegenBackend's OngoingCodegen, found Box<Any>")
|
||||
|
||||
@@ -33,9 +33,7 @@ use rustc_codegen_ssa::back::write::{
|
||||
TargetMachineFactoryFn,
|
||||
};
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc_codegen_ssa::{
|
||||
CodegenResults, CompiledModule, CompiledModules, CrateInfo, ModuleCodegen, TargetConfig,
|
||||
};
|
||||
use rustc_codegen_ssa::{CompiledModule, CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
use rustc_errors::{DiagCtxt, DiagCtxtHandle};
|
||||
@@ -362,12 +360,12 @@ impl CodegenBackend for LlvmCodegenBackend {
|
||||
will_not_use_fallback
|
||||
}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any> {
|
||||
Box::new(rustc_codegen_ssa::base::codegen_crate(
|
||||
LlvmCodegenBackend(()),
|
||||
tcx,
|
||||
crate::llvm_util::target_cpu(tcx.sess).to_string(),
|
||||
))
|
||||
fn target_cpu(&self, sess: &Session) -> String {
|
||||
crate::llvm_util::target_cpu(sess).to_string()
|
||||
}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>, crate_info: &CrateInfo) -> Box<dyn Any> {
|
||||
Box::new(rustc_codegen_ssa::base::codegen_crate(LlvmCodegenBackend(()), tcx, crate_info))
|
||||
}
|
||||
|
||||
fn join_codegen(
|
||||
@@ -375,8 +373,8 @@ impl CodegenBackend for LlvmCodegenBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
sess: &Session,
|
||||
outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
let (codegen_results, work_products) = ongoing_codegen
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
let (compiled_modules, work_products) = ongoing_codegen
|
||||
.downcast::<rustc_codegen_ssa::back::write::OngoingCodegen<LlvmCodegenBackend>>()
|
||||
.expect("Expected LlvmCodegenBackend's OngoingCodegen, found Box<Any>")
|
||||
.join(sess);
|
||||
@@ -388,7 +386,7 @@ impl CodegenBackend for LlvmCodegenBackend {
|
||||
});
|
||||
}
|
||||
|
||||
(codegen_results, work_products)
|
||||
(compiled_modules, work_products)
|
||||
}
|
||||
|
||||
fn link(
|
||||
|
||||
@@ -42,8 +42,8 @@ use crate::back::lto::check_lto_allowed;
|
||||
use crate::errors::ErrorCreatingRemarkDir;
|
||||
use crate::traits::*;
|
||||
use crate::{
|
||||
CachedModuleCodegen, CodegenResults, CompiledModule, CompiledModules, CrateInfo, ModuleCodegen,
|
||||
ModuleKind, errors,
|
||||
CachedModuleCodegen, CompiledModule, CompiledModules, CrateInfo, ModuleCodegen, ModuleKind,
|
||||
errors,
|
||||
};
|
||||
|
||||
const PRE_LTO_BC_EXT: &str = "pre-lto.bc";
|
||||
@@ -435,15 +435,13 @@ fn need_pre_lto_bitcode_for_incr_comp(sess: &Session) -> bool {
|
||||
pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
backend: B,
|
||||
tcx: TyCtxt<'_>,
|
||||
target_cpu: String,
|
||||
crate_info: &CrateInfo,
|
||||
allocator_module: Option<ModuleCodegen<B::Module>>,
|
||||
) -> OngoingCodegen<B> {
|
||||
let (coordinator_send, coordinator_receive) = channel();
|
||||
|
||||
let no_builtins = find_attr!(tcx, crate, NoBuiltins);
|
||||
|
||||
let crate_info = CrateInfo::new(tcx, target_cpu);
|
||||
|
||||
let regular_config = ModuleConfig::new(ModuleKind::Regular, tcx, no_builtins);
|
||||
let allocator_config = ModuleConfig::new(ModuleKind::Allocator, tcx, no_builtins);
|
||||
|
||||
@@ -453,7 +451,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
let coordinator_thread = start_executing_work(
|
||||
backend.clone(),
|
||||
tcx,
|
||||
&crate_info,
|
||||
crate_info,
|
||||
shared_emitter,
|
||||
codegen_worker_send,
|
||||
coordinator_receive,
|
||||
@@ -465,7 +463,6 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
||||
|
||||
OngoingCodegen {
|
||||
backend,
|
||||
crate_info,
|
||||
|
||||
codegen_worker_receive,
|
||||
shared_emitter_main,
|
||||
@@ -2131,7 +2128,6 @@ impl<B: ExtraBackendMethods> Drop for Coordinator<B> {
|
||||
|
||||
pub struct OngoingCodegen<B: ExtraBackendMethods> {
|
||||
pub backend: B,
|
||||
pub crate_info: CrateInfo,
|
||||
pub output_filenames: Arc<OutputFilenames>,
|
||||
// Field order below is intended to terminate the coordinator thread before two fields below
|
||||
// drop and prematurely close channels used by coordinator thread. See `Coordinator`'s
|
||||
@@ -2142,7 +2138,7 @@ pub struct OngoingCodegen<B: ExtraBackendMethods> {
|
||||
}
|
||||
|
||||
impl<B: ExtraBackendMethods> OngoingCodegen<B> {
|
||||
pub fn join(self, sess: &Session) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
pub fn join(self, sess: &Session) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
self.shared_emitter_main.check(sess, true);
|
||||
|
||||
let maybe_lto_modules = sess.time("join_worker_thread", || match self.coordinator.join() {
|
||||
@@ -2248,7 +2244,7 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
|
||||
self.backend.print_statistics()
|
||||
}
|
||||
|
||||
(CodegenResults { compiled_modules, crate_info: self.crate_info }, work_products)
|
||||
(compiled_modules, work_products)
|
||||
}
|
||||
|
||||
pub(crate) fn codegen_finished(&self, tcx: TyCtxt<'_>) {
|
||||
|
||||
@@ -681,7 +681,7 @@ pub fn allocator_shim_contents(tcx: TyCtxt<'_>, kind: AllocatorKind) -> Vec<Allo
|
||||
pub fn codegen_crate<B: ExtraBackendMethods>(
|
||||
backend: B,
|
||||
tcx: TyCtxt<'_>,
|
||||
target_cpu: String,
|
||||
crate_info: &CrateInfo,
|
||||
) -> OngoingCodegen<B> {
|
||||
if tcx.sess.target.need_explicit_cpu && tcx.sess.opts.cg.target_cpu.is_none() {
|
||||
// The target has no default cpu, but none is set explicitly
|
||||
@@ -719,7 +719,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
|
||||
None
|
||||
};
|
||||
|
||||
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, target_cpu, allocator_module);
|
||||
let ongoing_codegen = start_async_codegen(backend.clone(), tcx, crate_info, allocator_module);
|
||||
|
||||
// For better throughput during parallel processing by LLVM, we used to sort
|
||||
// CGUs largest to smallest. This would lead to better thread utilization
|
||||
|
||||
@@ -209,7 +209,8 @@ impl From<&cstore::NativeLib> for NativeLib {
|
||||
/// identifiers (`CrateNum`) to `CrateSource`. The other fields map `CrateNum` to the crate's own
|
||||
/// additional properties, so that effectively we can retrieve each dependent crate's `CrateSource`
|
||||
/// and the corresponding properties without referencing information outside of a `CrateInfo`.
|
||||
#[derive(Debug, Encodable, Decodable)]
|
||||
// rustc_codegen_cranelift needs a Clone impl for its jit mode, which isn't tested in rust CI
|
||||
#[derive(Clone, Debug, Encodable, Decodable)]
|
||||
pub struct CrateInfo {
|
||||
pub target_cpu: String,
|
||||
pub target_features: Vec<String>,
|
||||
@@ -250,12 +251,6 @@ pub struct TargetConfig {
|
||||
pub has_reliable_f128_math: bool,
|
||||
}
|
||||
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub struct CodegenResults {
|
||||
pub compiled_modules: CompiledModules,
|
||||
pub crate_info: CrateInfo,
|
||||
}
|
||||
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub struct CompiledModules {
|
||||
pub modules: Vec<CompiledModule>,
|
||||
@@ -298,11 +293,12 @@ pub fn looks_like_rust_object_file(filename: &str) -> bool {
|
||||
const RLINK_VERSION: u32 = 1;
|
||||
const RLINK_MAGIC: &[u8] = b"rustlink";
|
||||
|
||||
impl CodegenResults {
|
||||
impl CompiledModules {
|
||||
pub fn serialize_rlink(
|
||||
sess: &Session,
|
||||
rlink_file: &Path,
|
||||
codegen_results: &CodegenResults,
|
||||
compiled_modules: &CompiledModules,
|
||||
crate_info: &CrateInfo,
|
||||
metadata: &EncodedMetadata,
|
||||
outputs: &OutputFilenames,
|
||||
) -> Result<usize, io::Error> {
|
||||
@@ -312,7 +308,8 @@ impl CodegenResults {
|
||||
// Encoder's inner representation of `u32`.
|
||||
encoder.emit_raw_bytes(&RLINK_VERSION.to_be_bytes());
|
||||
encoder.emit_str(sess.cfg_version);
|
||||
Encodable::encode(codegen_results, &mut encoder);
|
||||
Encodable::encode(compiled_modules, &mut encoder);
|
||||
Encodable::encode(crate_info, &mut encoder);
|
||||
Encodable::encode(metadata, &mut encoder);
|
||||
Encodable::encode(outputs, &mut encoder);
|
||||
encoder.finish().map_err(|(_path, err)| err)
|
||||
@@ -321,7 +318,7 @@ impl CodegenResults {
|
||||
pub fn deserialize_rlink(
|
||||
sess: &Session,
|
||||
data: Vec<u8>,
|
||||
) -> Result<(Self, EncodedMetadata, OutputFilenames), CodegenErrors> {
|
||||
) -> Result<(Self, CrateInfo, EncodedMetadata, OutputFilenames), CodegenErrors> {
|
||||
// The Decodable machinery is not used here because it panics if the input data is invalid
|
||||
// and because its internal representation may change.
|
||||
if !data.starts_with(RLINK_MAGIC) {
|
||||
@@ -351,10 +348,11 @@ impl CodegenResults {
|
||||
});
|
||||
}
|
||||
|
||||
let codegen_results = CodegenResults::decode(&mut decoder);
|
||||
let compiled_modules = CompiledModules::decode(&mut decoder);
|
||||
let crate_info = CrateInfo::decode(&mut decoder);
|
||||
let metadata = EncodedMetadata::decode(&mut decoder);
|
||||
let outputs = OutputFilenames::decode(&mut decoder);
|
||||
Ok((codegen_results, metadata, outputs))
|
||||
Ok((compiled_modules, crate_info, metadata, outputs))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::write::WriteBackendMethods;
|
||||
use crate::back::archive::ArArchiveBuilderBuilder;
|
||||
use crate::back::link::link_binary;
|
||||
use crate::back::write::TargetMachineFactoryFn;
|
||||
use crate::{CodegenResults, CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
|
||||
use crate::{CompiledModules, CrateInfo, ModuleCodegen, TargetConfig};
|
||||
|
||||
pub trait BackendTypes {
|
||||
type Function: CodegenObject;
|
||||
@@ -103,7 +103,9 @@ pub trait CodegenBackend {
|
||||
|
||||
fn provide(&self, _providers: &mut Providers) {}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any>;
|
||||
fn target_cpu(&self, sess: &Session) -> String;
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>, crate_info: &CrateInfo) -> Box<dyn Any>;
|
||||
|
||||
/// This is called on the returned `Box<dyn Any>` from [`codegen_crate`](Self::codegen_crate)
|
||||
///
|
||||
@@ -115,9 +117,9 @@ pub trait CodegenBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
sess: &Session,
|
||||
outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>);
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>);
|
||||
|
||||
/// This is called on the returned [`CodegenResults`] from [`join_codegen`](Self::join_codegen).
|
||||
/// This is called on the returned [`CompiledModules`] from [`join_codegen`](Self::join_codegen).
|
||||
fn link(
|
||||
&self,
|
||||
sess: &Session,
|
||||
|
||||
@@ -28,7 +28,7 @@ use std::{env, str};
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CodegenErrors, CodegenResults};
|
||||
use rustc_codegen_ssa::{CodegenErrors, CompiledModules};
|
||||
use rustc_data_structures::profiling::{
|
||||
TimePassesFormat, get_resident_set_size, print_time_passes_entry,
|
||||
};
|
||||
@@ -556,9 +556,11 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
|
||||
let rlink_data = fs::read(file).unwrap_or_else(|err| {
|
||||
dcx.emit_fatal(RlinkUnableToRead { err });
|
||||
});
|
||||
let (codegen_results, metadata, outputs) =
|
||||
match CodegenResults::deserialize_rlink(sess, rlink_data) {
|
||||
Ok((codegen, metadata, outputs)) => (codegen, metadata, outputs),
|
||||
let (compiled_modules, crate_info, metadata, outputs) =
|
||||
match CompiledModules::deserialize_rlink(sess, rlink_data) {
|
||||
Ok((codegen, crate_info, metadata, outputs)) => {
|
||||
(codegen, crate_info, metadata, outputs)
|
||||
}
|
||||
Err(err) => {
|
||||
match err {
|
||||
CodegenErrors::WrongFileType => dcx.emit_fatal(RLinkWrongFileType),
|
||||
@@ -583,13 +585,7 @@ fn process_rlink(sess: &Session, compiler: &interface::Compiler) {
|
||||
};
|
||||
}
|
||||
};
|
||||
compiler.codegen_backend.link(
|
||||
sess,
|
||||
codegen_results.compiled_modules,
|
||||
codegen_results.crate_info,
|
||||
metadata,
|
||||
&outputs,
|
||||
);
|
||||
compiler.codegen_backend.link(sess, compiled_modules, crate_info, metadata, &outputs);
|
||||
} else {
|
||||
dcx.emit_fatal(RlinkNotAFile {});
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::{env, fs, iter};
|
||||
use rustc_ast::{self as ast, CRATE_NODE_ID};
|
||||
use rustc_attr_parsing::{AttributeParser, Early, ShouldEmit};
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModules, CrateInfo};
|
||||
use rustc_codegen_ssa::{CompiledModules, CrateInfo};
|
||||
use rustc_data_structures::indexmap::IndexMap;
|
||||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::sync::{AppendOnlyIndexVec, FreezeLock, WorkerLocal, par_fns};
|
||||
@@ -1194,7 +1194,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) {
|
||||
pub(crate) fn start_codegen<'tcx>(
|
||||
codegen_backend: &dyn CodegenBackend,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
) -> (Box<dyn Any>, EncodedMetadata) {
|
||||
) -> (Box<dyn Any>, CrateInfo, EncodedMetadata) {
|
||||
tcx.sess.timings.start_section(tcx.sess.dcx(), TimingSection::Codegen);
|
||||
|
||||
// Hook for tests.
|
||||
@@ -1221,18 +1221,17 @@ pub(crate) fn start_codegen<'tcx>(
|
||||
|
||||
let metadata = rustc_metadata::fs::encode_and_write_metadata(tcx);
|
||||
|
||||
let codegen = tcx.sess.time("codegen_crate", move || {
|
||||
let crate_info = CrateInfo::new(tcx, codegen_backend.target_cpu(tcx.sess));
|
||||
|
||||
let codegen = tcx.sess.time("codegen_crate", || {
|
||||
if tcx.sess.opts.unstable_opts.no_codegen || !tcx.sess.opts.output_types.should_codegen() {
|
||||
// Skip crate items and just output metadata in -Z no-codegen mode.
|
||||
tcx.sess.dcx().abort_if_errors();
|
||||
|
||||
// Linker::link will skip join_codegen in case of a CodegenResults Any value.
|
||||
Box::new(CodegenResults {
|
||||
compiled_modules: CompiledModules { modules: vec![], allocator_module: None },
|
||||
crate_info: CrateInfo::new(tcx, "<dummy cpu>".to_owned()),
|
||||
})
|
||||
Box::new(CompiledModules { modules: vec![], allocator_module: None })
|
||||
} else {
|
||||
codegen_backend.codegen_crate(tcx)
|
||||
codegen_backend.codegen_crate(tcx, &crate_info)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1244,7 +1243,7 @@ pub(crate) fn start_codegen<'tcx>(
|
||||
tcx.sess.code_stats.print_type_sizes();
|
||||
}
|
||||
|
||||
(codegen, metadata)
|
||||
(codegen, crate_info, metadata)
|
||||
}
|
||||
|
||||
/// Compute and validate the crate name.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rustc_codegen_ssa::CodegenResults;
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CompiledModules, CrateInfo};
|
||||
use rustc_data_structures::indexmap::IndexMap;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_errors::timings::TimingSection;
|
||||
@@ -21,6 +21,7 @@ pub struct Linker {
|
||||
output_filenames: Arc<OutputFilenames>,
|
||||
// Only present when incr. comp. is enabled.
|
||||
crate_hash: Option<Svh>,
|
||||
crate_info: CrateInfo,
|
||||
metadata: EncodedMetadata,
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
}
|
||||
@@ -30,7 +31,7 @@ impl Linker {
|
||||
tcx: TyCtxt<'_>,
|
||||
codegen_backend: &dyn CodegenBackend,
|
||||
) -> Linker {
|
||||
let (ongoing_codegen, metadata) = passes::start_codegen(codegen_backend, tcx);
|
||||
let (ongoing_codegen, crate_info, metadata) = passes::start_codegen(codegen_backend, tcx);
|
||||
|
||||
Linker {
|
||||
dep_graph: tcx.dep_graph.clone(),
|
||||
@@ -40,16 +41,17 @@ impl Linker {
|
||||
} else {
|
||||
None
|
||||
},
|
||||
crate_info,
|
||||
metadata,
|
||||
ongoing_codegen,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) {
|
||||
let (codegen_results, mut work_products) = sess.time("finish_ongoing_codegen", || {
|
||||
match self.ongoing_codegen.downcast::<CodegenResults>() {
|
||||
let (compiled_modules, mut work_products) = sess.time("finish_ongoing_codegen", || {
|
||||
match self.ongoing_codegen.downcast::<CompiledModules>() {
|
||||
// This was a check only build
|
||||
Ok(codegen_results) => (*codegen_results, IndexMap::default()),
|
||||
Ok(compiled_modules) => (*compiled_modules, IndexMap::default()),
|
||||
|
||||
Err(ongoing_codegen) => {
|
||||
codegen_backend.join_codegen(ongoing_codegen, sess, &self.output_filenames)
|
||||
@@ -97,10 +99,11 @@ impl Linker {
|
||||
|
||||
if sess.opts.unstable_opts.no_link {
|
||||
let rlink_file = self.output_filenames.with_extension(config::RLINK_EXT);
|
||||
CodegenResults::serialize_rlink(
|
||||
CompiledModules::serialize_rlink(
|
||||
sess,
|
||||
&rlink_file,
|
||||
&codegen_results,
|
||||
&compiled_modules,
|
||||
&self.crate_info,
|
||||
&self.metadata,
|
||||
&self.output_filenames,
|
||||
)
|
||||
@@ -114,8 +117,8 @@ impl Linker {
|
||||
let _timing = sess.timings.section_guard(sess.dcx(), TimingSection::Linking);
|
||||
codegen_backend.link(
|
||||
sess,
|
||||
codegen_results.compiled_modules,
|
||||
codegen_results.crate_info,
|
||||
compiled_modules,
|
||||
self.crate_info,
|
||||
self.metadata,
|
||||
&self.output_filenames,
|
||||
)
|
||||
|
||||
@@ -11,7 +11,7 @@ use rustc_codegen_ssa::back::archive::{ArArchiveBuilderBuilder, ArchiveBuilderBu
|
||||
use rustc_codegen_ssa::back::link::link_binary;
|
||||
use rustc_codegen_ssa::target_features::cfg_target_feature;
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModules, CrateInfo, TargetConfig};
|
||||
use rustc_codegen_ssa::{CompiledModules, CrateInfo, TargetConfig};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::jobserver::Proxy;
|
||||
use rustc_data_structures::sync;
|
||||
@@ -401,11 +401,12 @@ impl CodegenBackend for DummyCodegenBackend {
|
||||
vec![CrateType::Rlib, CrateType::Executable]
|
||||
}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any> {
|
||||
Box::new(CodegenResults {
|
||||
compiled_modules: CompiledModules { modules: vec![], allocator_module: None },
|
||||
crate_info: CrateInfo::new(tcx, String::new()),
|
||||
})
|
||||
fn target_cpu(&self, _sess: &Session) -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn codegen_crate<'tcx>(&self, _tcx: TyCtxt<'tcx>, _crate_info: &CrateInfo) -> Box<dyn Any> {
|
||||
Box::new(CompiledModules { modules: vec![], allocator_module: None })
|
||||
}
|
||||
|
||||
fn join_codegen(
|
||||
@@ -413,7 +414,7 @@ impl CodegenBackend for DummyCodegenBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
_sess: &Session,
|
||||
_outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
(*ongoing_codegen.downcast().unwrap(), FxIndexMap::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ extern crate rustc_target;
|
||||
use std::any::Any;
|
||||
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::{CodegenResults, CompiledModules, CrateInfo};
|
||||
use rustc_codegen_ssa::{CompiledModules, CrateInfo};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
@@ -33,11 +33,12 @@ impl CodegenBackend for TheBackend {
|
||||
"the-backend"
|
||||
}
|
||||
|
||||
fn codegen_crate(&self, tcx: TyCtxt<'_>) -> Box<dyn Any> {
|
||||
Box::new(CodegenResults {
|
||||
compiled_modules: CompiledModules { modules: vec![], allocator_module: None },
|
||||
crate_info: CrateInfo::new(tcx, "fake_target_cpu".to_string()),
|
||||
})
|
||||
fn target_cpu(&self, _sess: &Session) -> String {
|
||||
"fake_target_cpu".to_owned()
|
||||
}
|
||||
|
||||
fn codegen_crate(&self, _tcx: TyCtxt<'_>, _crate_info: &CrateInfo) -> Box<dyn Any> {
|
||||
Box::new(CompiledModules { modules: vec![], allocator_module: None })
|
||||
}
|
||||
|
||||
fn join_codegen(
|
||||
@@ -45,10 +46,10 @@ impl CodegenBackend for TheBackend {
|
||||
ongoing_codegen: Box<dyn Any>,
|
||||
_sess: &Session,
|
||||
_outputs: &OutputFilenames,
|
||||
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
) -> (CompiledModules, FxIndexMap<WorkProductId, WorkProduct>) {
|
||||
let codegen_results = ongoing_codegen
|
||||
.downcast::<CodegenResults>()
|
||||
.expect("in join_codegen: ongoing_codegen is not a CodegenResults");
|
||||
.downcast::<CompiledModules>()
|
||||
.expect("in join_codegen: ongoing_codegen is not a CompiledModules");
|
||||
(*codegen_results, FxIndexMap::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -10,4 +10,5 @@ fn main() {
|
||||
rmeta_meta::missing_optimized_mir();
|
||||
}
|
||||
|
||||
//~? ERROR crate `rmeta_meta` required to be available in rlib format, but was not found in this form
|
||||
//~? ERROR missing optimized MIR for `missing_optimized_mir` in the crate `rmeta_meta`
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
error: crate `rmeta_meta` required to be available in rlib format, but was not found in this form
|
||||
|
||||
error: missing optimized MIR for `missing_optimized_mir` in the crate `rmeta_meta`
|
||||
|
|
||||
note: missing optimized MIR for this item (was the crate `rmeta_meta` compiled with `--emit=metadata`?)
|
||||
@@ -6,5 +8,5 @@ note: missing optimized MIR for this item (was the crate `rmeta_meta` compiled w
|
||||
LL | pub fn missing_optimized_mir() {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user