Skip to content

Commit d4ddd87

Browse files
committed
Move dep_graph.finish_encoding() into save_dep_graph
1 parent 391bdb3 commit d4ddd87

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

compiler/rustc_incremental/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ incremental_delete_partial = failed to delete partly initialized session dir `{$
4646
4747
incremental_delete_workproduct = file-system error deleting outdated file `{$path}`: {$err}
4848
49+
incremental_failed_writing_file =
50+
failed to write file {$path}: {$error}"
51+
4952
incremental_finalize = error finalizing incremental compilation session directory `{$path}`: {$err}
5053
5154
incremental_finalized_gc_failed =

compiler/rustc_incremental/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
use rustc_macros::Diagnostic;
22
use rustc_span::{symbol::Ident, Span, Symbol};
3+
use std::io;
34
use std::path::{Path, PathBuf};
45

6+
#[derive(Diagnostic)]
7+
#[diag(incremental_failed_writing_file)]
8+
pub struct FailedWritingFile<'a> {
9+
pub path: &'a Path,
10+
pub error: io::Error,
11+
}
12+
513
#[derive(Diagnostic)]
614
#[diag(incremental_unrecognized_depnode)]
715
pub struct UnrecognizedDepNode {

compiler/rustc_incremental/src/persist/save.rs

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
3535
}
3636
// This is going to be deleted in finalize_session_directory, so let's not create it.
3737
if sess.dcx().has_errors_or_delayed_bugs().is_some() {
38+
// Dropping the DepGraph without calling finish_encoding ICEs even when the incr comp
39+
// session has already been invalidated due to an error.
40+
if let Err((path, error)) = tcx.dep_graph.finish_encoding() {
41+
tcx.sess.dcx().emit_fatal(errors::FailedWritingFile { path: &path, error });
42+
}
3843
return;
3944
}
4045

@@ -76,6 +81,11 @@ pub fn save_dep_graph(tcx: TyCtxt<'_>) {
7681
});
7782
},
7883
);
84+
85+
// FIXME finalize dep graph before renaming?
86+
if let Err((path, error)) = tcx.dep_graph.finish_encoding() {
87+
tcx.sess.dcx().emit_fatal(errors::FailedWritingFile { path: &path, error });
88+
}
7989
})
8090
}
8191

compiler/rustc_interface/src/queries.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::errors::FailedWritingFile;
22
use crate::interface::{Compiler, Result};
3-
use crate::{errors, passes};
3+
use crate::passes;
44

55
use rustc_ast as ast;
66
use rustc_codegen_ssa::traits::CodegenBackend;
@@ -12,7 +12,6 @@ use rustc_hir::def_id::LOCAL_CRATE;
1212
use rustc_middle::arena::Arena;
1313
use rustc_middle::dep_graph::DepGraph;
1414
use rustc_middle::ty::{GlobalCtxt, TyCtxt};
15-
use rustc_serialize::opaque::FileEncodeResult;
1615
use rustc_session::config::{self, OutputFilenames, OutputType};
1716
use rustc_session::Session;
1817
use std::any::Any;
@@ -95,10 +94,6 @@ impl<'tcx> Queries<'tcx> {
9594
}
9695
}
9796

98-
pub fn finish(&self) -> FileEncodeResult {
99-
if let Some(gcx) = self.gcx_cell.get() { gcx.finish() } else { Ok(0) }
100-
}
101-
10297
pub fn parse(&self) -> Result<QueryResult<'_, ast::Crate>> {
10398
self.parse.compute(|| passes::parse(&self.compiler.sess))
10499
}
@@ -228,9 +223,6 @@ impl Compiler {
228223
// The timer's lifetime spans the dropping of `queries`, which contains
229224
// the global context.
230225
_timer = Some(self.sess.timer("free_global_ctxt"));
231-
if let Err((path, error)) = queries.finish() {
232-
self.sess.dcx().emit_fatal(errors::FailedWritingFile { path: &path, error });
233-
}
234226

235227
ret
236228
}

compiler/rustc_middle/src/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1291,10 +1291,6 @@ impl<'tcx> GlobalCtxt<'tcx> {
12911291

12921292
tls::enter_context(&icx, || f(icx.tcx))
12931293
}
1294-
1295-
pub fn finish(&self) -> FileEncodeResult {
1296-
self.dep_graph.finish_encoding()
1297-
}
12981294
}
12991295

13001296
/// This is used to get a reference to a `GlobalCtxt` if one is available.

0 commit comments

Comments
 (0)