Skip to content

Commit c7ee3a5

Browse files
committed
Save metadata among work products.
1 parent 556d20a commit c7ee3a5

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

compiler/rustc_interface/src/queries.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,24 @@ impl Linker {
4545
}
4646

4747
pub fn link(self, sess: &Session, codegen_backend: &dyn CodegenBackend) {
48-
let (codegen_results, work_products) = sess.time("finish_ongoing_codegen", || {
48+
let (codegen_results, mut work_products) = sess.time("finish_ongoing_codegen", || {
4949
codegen_backend.join_codegen(self.ongoing_codegen, sess, &self.output_filenames)
5050
});
5151
sess.timings.end_section(sess.dcx(), TimingSection::Codegen);
5252

53+
if sess.opts.incremental.is_some()
54+
&& let Some(path) = self.metadata.path()
55+
&& let Some((id, product)) =
56+
rustc_incremental::copy_cgu_workproduct_to_incr_comp_cache_dir(
57+
sess,
58+
"metadata",
59+
&[("rmeta", path)],
60+
&[],
61+
)
62+
{
63+
work_products.insert(id, product);
64+
}
65+
5366
sess.dcx().abort_if_errors();
5467

5568
let _timer = sess.timer("link");

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,6 +2307,8 @@ pub struct EncodedMetadata {
23072307
// This is an optional stub metadata containing only the crate header.
23082308
// The header should be very small, so we load it directly into memory.
23092309
stub_metadata: Option<Vec<u8>>,
2310+
// The path containing the metadata, to record as work product.
2311+
path: Option<Box<Path>>,
23102312
// We need to carry MaybeTempDir to avoid deleting the temporary
23112313
// directory while accessing the Mmap.
23122314
_temp_dir: Option<MaybeTempDir>,
@@ -2322,14 +2324,24 @@ impl EncodedMetadata {
23222324
let file = std::fs::File::open(&path)?;
23232325
let file_metadata = file.metadata()?;
23242326
if file_metadata.len() == 0 {
2325-
return Ok(Self { full_metadata: None, stub_metadata: None, _temp_dir: None });
2327+
return Ok(Self {
2328+
full_metadata: None,
2329+
stub_metadata: None,
2330+
path: None,
2331+
_temp_dir: None,
2332+
});
23262333
}
23272334
let full_mmap = unsafe { Some(Mmap::map(file)?) };
23282335

23292336
let stub =
23302337
if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
23312338

2332-
Ok(Self { full_metadata: full_mmap, stub_metadata: stub, _temp_dir: temp_dir })
2339+
Ok(Self {
2340+
full_metadata: full_mmap,
2341+
stub_metadata: stub,
2342+
path: Some(path.into()),
2343+
_temp_dir: temp_dir,
2344+
})
23332345
}
23342346

23352347
#[inline]
@@ -2341,6 +2353,11 @@ impl EncodedMetadata {
23412353
pub fn stub_or_full(&self) -> &[u8] {
23422354
self.stub_metadata.as_deref().unwrap_or(self.full())
23432355
}
2356+
2357+
#[inline]
2358+
pub fn path(&self) -> Option<&Path> {
2359+
self.path.as_deref()
2360+
}
23442361
}
23452362

23462363
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2365,7 +2382,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
23652382
None
23662383
};
23672384

2368-
Self { full_metadata, stub_metadata: stub, _temp_dir: None }
2385+
Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
23692386
}
23702387
}
23712388

0 commit comments

Comments
 (0)