Skip to content

Commit

Permalink
Call FileEncoder::finish in rmeta encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 28, 2023
1 parent cf226e9 commit e33d313
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
join(
move || {
sess.time("incr_comp_persist_dep_graph", || {
if let Err(err) = tcx.dep_graph.encode(&tcx.sess.prof) {
if let Err(err) = tcx.dep_graph.finish_encoding(&tcx.sess.prof) {
sess.emit_err(errors::WriteDepGraph { path: &staging_dep_graph_path, err });
}
if let Err(err) = fs::rename(&staging_dep_graph_path, &dep_graph_path) {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2251,7 +2251,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
// culminating in the `CrateRoot` which points to all of it.
let root = ecx.encode_crate_root();

ecx.opaque.flush();
// Make sure we report any errors from writing to the file.
// If we forget this, compilation can succeed with an incomplete rmeta file,
// causing an ICE when the rmeta file is read by another compilation.
if let Err(err) = ecx.opaque.finish() {
tcx.sess.emit_err(FailWriteFile { err });
}

let mut file = ecx.opaque.file();
// We will return to this position after writing the root position.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
}

#[inline]
fn finish(self) -> Result<usize, io::Error> {
fn finish(mut self) -> Result<usize, io::Error> {
self.encoder.finish()
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ impl<D: Deps> DepGraph<D> {
}
}

pub fn encode(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
pub fn finish_encoding(&self, profiler: &SelfProfilerRef) -> FileEncodeResult {
if let Some(data) = &self.data {
data.current.encoder.steal().finish(profiler)
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl FileEncoder {
})
}

pub fn finish(mut self) -> Result<usize, io::Error> {
pub fn finish(&mut self) -> Result<usize, io::Error> {
self.flush();
match std::mem::replace(&mut self.res, Ok(())) {
Ok(()) => Ok(self.position()),
Expand Down

0 comments on commit e33d313

Please sign in to comment.