Skip to content

Commit 3da0e99

Browse files
committed
Save metadata among work products.
1 parent 992fa62 commit 3da0e99

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,10 +45,23 @@ 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

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

5467
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
@@ -2268,6 +2268,8 @@ pub struct EncodedMetadata {
22682268
// This is an optional stub metadata containing only the crate header.
22692269
// The header should be very small, so we load it directly into memory.
22702270
stub_metadata: Option<Vec<u8>>,
2271+
// The path containing the metadata, to record as work product.
2272+
path: Option<Box<Path>>,
22712273
// We need to carry MaybeTempDir to avoid deleting the temporary
22722274
// directory while accessing the Mmap.
22732275
_temp_dir: Option<MaybeTempDir>,
@@ -2283,14 +2285,24 @@ impl EncodedMetadata {
22832285
let file = std::fs::File::open(&path)?;
22842286
let file_metadata = file.metadata()?;
22852287
if file_metadata.len() == 0 {
2286-
return Ok(Self { full_metadata: None, stub_metadata: None, _temp_dir: None });
2288+
return Ok(Self {
2289+
full_metadata: None,
2290+
stub_metadata: None,
2291+
path: None,
2292+
_temp_dir: None,
2293+
});
22872294
}
22882295
let full_mmap = unsafe { Some(Mmap::map(file)?) };
22892296

22902297
let stub =
22912298
if let Some(stub_path) = stub_path { Some(std::fs::read(stub_path)?) } else { None };
22922299

2293-
Ok(Self { full_metadata: full_mmap, stub_metadata: stub, _temp_dir: temp_dir })
2300+
Ok(Self {
2301+
full_metadata: full_mmap,
2302+
stub_metadata: stub,
2303+
path: Some(path.into()),
2304+
_temp_dir: temp_dir,
2305+
})
22942306
}
22952307

22962308
#[inline]
@@ -2302,6 +2314,11 @@ impl EncodedMetadata {
23022314
pub fn stub_or_full(&self) -> &[u8] {
23032315
self.stub_metadata.as_deref().unwrap_or(self.full())
23042316
}
2317+
2318+
#[inline]
2319+
pub fn path(&self) -> Option<&Path> {
2320+
self.path.as_deref()
2321+
}
23052322
}
23062323

23072324
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2326,7 +2343,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
23262343
None
23272344
};
23282345

2329-
Self { full_metadata, stub_metadata: stub, _temp_dir: None }
2346+
Self { full_metadata, stub_metadata: stub, path: None, _temp_dir: None }
23302347
}
23312348
}
23322349

0 commit comments

Comments
 (0)