Skip to content

Commit

Permalink
Try to make Queries::finish move out of self
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 28, 2023
1 parent 80648b8 commit fa7023d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
11 changes: 5 additions & 6 deletions compiler/rustc_interface/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ impl Compiler {
where
F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T,
{
let mut _timer = None;
let queries = Queries::new(self);
let ret = f(&queries);

Expand All @@ -352,11 +351,11 @@ impl Compiler {
.time("serialize_dep_graph", || gcx.enter(rustc_incremental::save_dep_graph));
}

if let Err((path, error)) = queries.finish() {
self.session().emit_err(errors::FailedWritingFile { path: &path, error });
}

_timer = Some(self.session().timer("free_global_ctxt"));
self.session().time("free_global_ctxt", || {
if let Err((path, error)) = queries.finish() {
self.session().emit_err(errors::FailedWritingFile { path: &path, error });
}
});

ret
}
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2252,16 +2252,18 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
// culminating in the `CrateRoot` which points to all of it.
let root = ecx.encode_crate_root();

let file = ecx.opaque.file().try_clone().unwrap();
let path = ecx.opaque.path().to_owned();

// 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((path, err)) = ecx.opaque.finish() {
tcx.sess.emit_err(FailWriteFile { path: &path, err });
}

let file = ecx.opaque.file();
if let Err(err) = encode_root_position(file, root.position.get()) {
tcx.sess.emit_err(FailWriteFile { path: ecx.opaque.path(), err });
if let Err(err) = encode_root_position(&file, root.position.get()) {
tcx.sess.emit_err(FailWriteFile { path: &path, err });
}

// Record metadata size for self-profiling
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 @@ -866,7 +866,7 @@ impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
}

#[inline]
fn finish(mut self) -> FileEncodeResult {
fn finish(self) -> FileEncodeResult {
self.encoder.finish()
}
}
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 @@ -176,7 +176,7 @@ impl FileEncoder {
})
}

pub fn finish(&mut self) -> FileEncodeResult {
pub fn finish(mut self) -> FileEncodeResult {
self.flush();
#[cfg(debug_assertions)]
{
Expand Down

0 comments on commit fa7023d

Please sign in to comment.