Skip to content

Commit 80221b4

Browse files
committed
Save metadata among work products.
1 parent b08dd92 commit 80221b4

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

495495
fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
496496
sess: &Session,
497+
metadata: &EncodedMetadata,
497498
compiled_modules: &CompiledModules,
498499
) -> FxIndexMap<WorkProductId, WorkProduct> {
499500
let mut work_products = FxIndexMap::default();
@@ -504,6 +505,14 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
504505

505506
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
506507

508+
if let Some(path) = metadata.path() {
509+
if let Some((id, product)) =
510+
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, "metadata", &[("rmeta", path)])
511+
{
512+
work_products.insert(id, product);
513+
}
514+
}
515+
507516
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
508517
let mut files = Vec::new();
509518
if let Some(object_file_path) = &module.object {
@@ -1959,8 +1968,11 @@ impl<B: ExtraBackendMethods> OngoingCodegen<B> {
19591968

19601969
sess.abort_if_errors();
19611970

1962-
let work_products =
1963-
copy_all_cgu_workproducts_to_incr_comp_cache_dir(sess, &compiled_modules);
1971+
let work_products = copy_all_cgu_workproducts_to_incr_comp_cache_dir(
1972+
sess,
1973+
&self.metadata,
1974+
&compiled_modules,
1975+
);
19641976
produce_final_output_artifacts(sess, &compiled_modules, &self.output_filenames);
19651977

19661978
// 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
@@ -2108,6 +2108,8 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
21082108
pub struct EncodedMetadata {
21092109
// The declaration order matters because `mmap` should be dropped before `_temp_dir`.
21102110
mmap: Option<Mmap>,
2111+
// The path containing the metadata, to record as work product.
2112+
path: Option<Box<Path>>,
21112113
// We need to carry MaybeTempDir to avoid deleting the temporary
21122114
// directory while accessing the Mmap.
21132115
_temp_dir: Option<MaybeTempDir>,
@@ -2119,16 +2121,21 @@ impl EncodedMetadata {
21192121
let file = std::fs::File::open(&path)?;
21202122
let file_metadata = file.metadata()?;
21212123
if file_metadata.len() == 0 {
2122-
return Ok(Self { mmap: None, _temp_dir: None });
2124+
return Ok(Self { mmap: None, path: None, _temp_dir: None });
21232125
}
21242126
let mmap = unsafe { Some(Mmap::map(file)?) };
2125-
Ok(Self { mmap, _temp_dir: temp_dir })
2127+
Ok(Self { mmap, path: Some(path.into()), _temp_dir: temp_dir })
21262128
}
21272129

21282130
#[inline]
21292131
pub fn raw_data(&self) -> &[u8] {
21302132
self.mmap.as_deref().unwrap_or_default()
21312133
}
2134+
2135+
#[inline]
2136+
pub fn path(&self) -> Option<&Path> {
2137+
self.path.as_deref()
2138+
}
21322139
}
21332140

21342141
impl<S: Encoder> Encodable<S> for EncodedMetadata {
@@ -2152,7 +2159,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
21522159
None
21532160
};
21542161

2155-
Self { mmap, _temp_dir: None }
2162+
Self { mmap, path: None, _temp_dir: None }
21562163
}
21572164
}
21582165

0 commit comments

Comments
 (0)