Skip to content

Commit 9c84ea5

Browse files
committed
Save metadata among work products.
1 parent 5a4ee43 commit 9c84ea5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

compiler/rustc_codegen_ssa/src/back/write.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
521521

522522
fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
523523
sess: &Session,
524+
metadata: &EncodedMetadata,
524525
compiled_modules: &CompiledModules,
525526
) -> FxIndexMap<WorkProductId, WorkProduct> {
526527
let mut work_products = FxIndexMap::default();
@@ -531,6 +532,14 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
531532

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

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

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

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

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

compiler/rustc_metadata/src/rmeta/encoder.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -2195,6 +2195,8 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
21952195
pub struct EncodedMetadata {
21962196
// The declaration order matters because `mmap` should be dropped before `_temp_dir`.
21972197
mmap: Option<Mmap>,
2198+
// The path containing the metadata, to record as work product.
2199+
path: Option<Box<Path>>,
21982200
// We need to carry MaybeTempDir to avoid deleting the temporary
21992201
// directory while accessing the Mmap.
22002202
_temp_dir: Option<MaybeTempDir>,
@@ -2206,16 +2208,21 @@ impl EncodedMetadata {
22062208
let file = std::fs::File::open(&path)?;
22072209
let file_metadata = file.metadata()?;
22082210
if file_metadata.len() == 0 {
2209-
return Ok(Self { mmap: None, _temp_dir: None });
2211+
return Ok(Self { mmap: None, path: None, _temp_dir: None });
22102212
}
22112213
let mmap = unsafe { Some(Mmap::map(file)?) };
2212-
Ok(Self { mmap, _temp_dir: temp_dir })
2214+
Ok(Self { mmap, path: Some(path.into()), _temp_dir: temp_dir })
22132215
}
22142216

22152217
#[inline]
22162218
pub fn raw_data(&self) -> &[u8] {
22172219
self.mmap.as_deref().unwrap_or_default()
22182220
}
2221+
2222+
#[inline]
2223+
pub fn path(&self) -> Option<&Path> {
2224+
self.path.as_deref()
2225+
}
22192226
}
22202227

22212228
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2239,7 +2246,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
22392246
None
22402247
};
22412248

2242-
Self { mmap, _temp_dir: None }
2249+
Self { mmap, path: None, _temp_dir: None }
22432250
}
22442251
}
22452252

0 commit comments

Comments
 (0)