Only borrow EncodedMetadata in codegen_crate

And move passing it to the linker to the driver code.
This commit is contained in:
bjorn3
2025-05-30 11:55:06 +00:00
parent c68032fd4c
commit badabab01f
12 changed files with 90 additions and 91 deletions

View File

@@ -5,6 +5,7 @@ use rustc_codegen_ssa::CodegenResults;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::svh::Svh;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::DepGraph;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
@@ -18,6 +19,7 @@ pub struct Linker {
output_filenames: Arc<OutputFilenames>,
// Only present when incr. comp. is enabled.
crate_hash: Option<Svh>,
metadata: EncodedMetadata,
ongoing_codegen: Box<dyn Any>,
}
@@ -26,7 +28,7 @@ impl Linker {
tcx: TyCtxt<'_>,
codegen_backend: &dyn CodegenBackend,
) -> Linker {
let ongoing_codegen = passes::start_codegen(codegen_backend, tcx);
let (ongoing_codegen, metadata) = passes::start_codegen(codegen_backend, tcx);
Linker {
dep_graph: tcx.dep_graph.clone(),
@@ -36,6 +38,7 @@ impl Linker {
} else {
None
},
metadata,
ongoing_codegen,
}
}
@@ -75,6 +78,7 @@ impl Linker {
sess,
&rlink_file,
&codegen_results,
&self.metadata,
&*self.output_filenames,
)
.unwrap_or_else(|error| {
@@ -84,6 +88,6 @@ impl Linker {
}
let _timer = sess.prof.verbose_generic_activity("link_crate");
codegen_backend.link(sess, codegen_results, &self.output_filenames)
codegen_backend.link(sess, codegen_results, self.metadata, &self.output_filenames)
}
}