Skip to content

Commit 4a8ecda

Browse files
committed
Save metadata among work products.
1 parent 8fa7bdf commit 4a8ecda

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
@@ -507,6 +507,7 @@ pub fn start_async_codegen<B: ExtraBackendMethods>(
507507

508508
fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
509509
sess: &Session,
510+
metadata: &EncodedMetadata,
510511
compiled_modules: &CompiledModules,
511512
) -> FxIndexMap<WorkProductId, WorkProduct> {
512513
let mut work_products = FxIndexMap::default();
@@ -517,6 +518,14 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
517518

518519
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
519520

521+
if let Some(path) = metadata.path() {
522+
if let Some((id, product)) =
523+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, "metadata", &[("rmeta", path)])
524+
{
525+
work_products.insert(id, product);
526+
}
527+
}
528+
520529
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
521530
let mut files = Vec::new();
522531
if let Some(object_file_path) = &module.object {
@@ -1973,8 +1982,11 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
19731982

19741983
sess.abort_if_errors();
19751984

1976-
let work_products =
1977-
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);
1985+
let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(
1986+
sess,
1987+
&self.metadata,
1988+
&compiled_modules,
1989+
);
19781990
produce_final_output_artifacts(sess, &compiled_modules, &self.output_filenames);
19791991

19801992
// 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
@@ -2126,6 +2126,8 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
21262126
pub struct EncodedMetadata {
21272127
// The declaration order matters because `mmap` should be dropped before `_temp_dir`.
21282128
mmap: Option<Mmap>,
2129+
// The path containing the metadata, to record as work product.
2130+
path: Option<Box<Path>>,
21292131
// We need to carry MaybeTempDir to avoid deleting the temporary
21302132
// directory while accessing the Mmap.
21312133
_temp_dir: Option<MaybeTempDir>,
@@ -2137,16 +2139,21 @@ impl EncodedMetadata {
21372139
let file = std::fs::File::open(&path)?;
21382140
let file_metadata = file.metadata()?;
21392141
if file_metadata.len() == 0 {
2140-
return Ok(Self { mmap: None, _temp_dir: None });
2142+
return Ok(Self { mmap: None, path: None, _temp_dir: None });
21412143
}
21422144
let mmap = unsafe { Some(Mmap::map(file)?) };
2143-
Ok(Self { mmap, _temp_dir: temp_dir })
2145+
Ok(Self { mmap, path: Some(path.into()), _temp_dir: temp_dir })
21442146
}
21452147

21462148
#[inline]
21472149
pub fn raw_data(&self) -> &[u8] {
21482150
self.mmap.as_deref().unwrap_or_default()
21492151
}
2152+
2153+
#[inline]
2154+
pub fn path(&self) -> Option<&Path> {
2155+
self.path.as_deref()
2156+
}
21502157
}
21512158

21522159
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2170,7 +2177,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
21702177
None
21712178
};
21722179

2173-
Self { mmap, _temp_dir: None }
2180+
Self { mmap, path: None, _temp_dir: None }
21742181
}
21752182
}
21762183

0 commit comments

Comments
 (0)