Save metadata among work products.

This commit is contained in:
Camille GILLOT 2023-08-09 17:47:20 +00:00
parent 556d20a834
commit c7ee3a5e3f
2 changed files with 34 additions and 4 deletions

View file

@ -45,11 +45,24 @@ impl Linker {
}
pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) {
let (codegen_results, work_products) = sess.time("finish_ongoing_codegen", || {
let (codegen_results, mut work_products) = sess.time("finish_ongoing_codegen", || {
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames)
});
sess.timings.end_section(sess.dcx(), TimingSection::Codegen);
if sess.opts.incremental.is_some()
&& let Some(path) = self.metadata.path()
&& let Some((id, product)) =
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
sess,
"metadata",
&[("rmeta", path)],
&[],
)
{
work_products.insert(id, product);
}
sess.dcx().abort_if_errors();
let _timer = sess.timer("link");

View file

@ -2307,6 +2307,8 @@ pub struct EncodedMetadata {
// This is an optional stub metadata containing only the crate header.
// The header should be very small, so we load it directly into memory.
stub_metadata: Option<Vec<u8>>,
// The path containing the metadata, to record as work product.
path: Option<Box<Path>>,
// We need to carry MaybeTempDir to avoid deleting the temporary
// directory while accessing the Mmap.
_temp_dir: Option<MaybeTempDir>,
@ -2322,14 +2324,24 @@ impl EncodedMetadata {
let file = std::fs::File::open(&path)?;
let file_metadata = file.metadata()?;
if file_metadata.len() == 0 {
return Ok(Self { full_metadata: None, stub_metadata: None, _temp_dir: None });
return Ok(Self {
full_metadata: None,
stub_metadata: None,
path: None,
_temp_dir: None,
});
}
let full_mmap = unsafe { Some(Mmap::map(file)?) };
let stub =
if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
Ok(Self { full_metadata: full_mmap, stub_metadata: stub, _temp_dir: temp_dir })
Ok(Self {
full_metadata: full_mmap,
stub_metadata: stub,
path: Some(path.into()),
_temp_dir: temp_dir,
})
}
#[inline]
@ -2341,6 +2353,11 @@ impl EncodedMetadata {
pub fn stub_or_full(&self) -> &[u8] {
self.stub_metadata.as_deref().unwrap_or(self.full())
}
#[inline]
pub fn path(&self) -> Option<&Path> {
self.path.as_deref()
}
}
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@ -2365,7 +2382,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
None
};
Self { full_metadata, stub_metadata: stub, _temp_dir: None }
Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
}
}