Skip to content

Commit 1533298

Browse files
committed
Save metadata among work products.
1 parent 298c746 commit 1533298

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
520520

521521
fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
522522
sess: &Session,
523+
metadata: &EncodedMetadata,
523524
compiled_modules: &CompiledModules,
524525
) -> FxIndexMap<WorkProductId, WorkProduct> {
525526
let mut work_products = FxIndexMap::default();
@@ -530,6 +531,14 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
530531

531532
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
532533

534+
if let Some(path) = metadata.path() {
535+
if let Some((id, product)) =
536+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, "metadata", &[("rmeta", path)])
537+
{
538+
work_products.insert(id, product);
539+
}
540+
}
541+
533542
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
534543
let mut files = Vec::new();
535544
if let Some(object_file_path) = &module.object {
@@ -2059,8 +2068,11 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
20592068

20602069
sess.dcx().abort_if_errors();
20612070

2062-
let work_products =
2063-
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);
2071+
let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(
2072+
sess,
2073+
&self.metadata,
2074+
&compiled_modules,
2075+
);
20642076
produce_final_output_artifacts(sess, &compiled_modules, &self.output_filenames);
20652077

20662078
// FIXME: time_llvm_passes support - does this use a global context or

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,6 +2205,8 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
22052205
pub struct EncodedMetadata {
22062206
// The declaration order matters because `mmap` should be dropped before `_temp_dir`.
22072207
mmap: Option<Mmap>,
2208+
// The path containing the metadata, to record as work product.
2209+
path: Option<Box<Path>>,
22082210
// We need to carry MaybeTempDir to avoid deleting the temporary
22092211
// directory while accessing the Mmap.
22102212
_temp_dir: Option<MaybeTempDir>,
@@ -2216,16 +2218,21 @@ impl EncodedMetadata {
22162218
let file = std::fs::File::open(&path)?;
22172219
let file_metadata = file.metadata()?;
22182220
if file_metadata.len() == 0 {
2219-
return Ok(Self { mmap: None, _temp_dir: None });
2221+
return Ok(Self { mmap: None, path: None, _temp_dir: None });
22202222
}
22212223
let mmap = unsafe { Some(Mmap::map(file)?) };
2222-
Ok(Self { mmap, _temp_dir: temp_dir })
2224+
Ok(Self { mmap, path: Some(path.into()), _temp_dir: temp_dir })
22232225
}
22242226

22252227
#[inline]
22262228
pub fn raw_data(&self) -> &[u8] {
22272229
self.mmap.as_deref().unwrap_or_default()
22282230
}
2231+
2232+
#[inline]
2233+
pub fn path(&self) -> Option<&Path> {
2234+
self.path.as_deref()
2235+
}
22292236
}
22302237

22312238
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2249,7 +2256,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
22492256
None
22502257
};
22512258

2252-
Self { mmap, _temp_dir: None }
2259+
Self { mmap, path: None, _temp_dir: None }
22532260
}
22542261
}
22552262

0 commit comments

Comments
 (0)