Skip to content

Commit 8877f02

Browse files
committed
wip
1 parent edc0107 commit 8877f02

File tree

6 files changed

+81
-37
lines changed

6 files changed

+81
-37
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ where
164164
pub struct DepGraphArgs {
165165
pub prev_graph: PreviousDepGraph,
166166
pub prev_work_products: FxHashMap<WorkProductId, WorkProduct>,
167-
pub file: File,
167+
pub file: Option<File>,
168168
pub state: IndexVec<DepNodeIndex, AtomicCell<DepNodeState>>,
169169
pub invalidated: Vec<DepNodeIndex>,
170170
pub model: Option<DepGraphModel>,
@@ -712,8 +712,18 @@ impl DepGraph {
712712
DepNodeState::Invalid |
713713
DepNodeState::UnknownEvalAlways |
714714
DepNodeState::Unknown => {
715-
bug!("try_force_previous_green() - Forcing the DepNode \
715+
if !tcx.sess.has_errors() {
716+
bug!("try_force_previous_green() - Forcing the DepNode \
716717
should have set its color")
718+
} else {
719+
// If the query we just forced has resulted
720+
// in some kind of compilation error, we
721+
// don't expect that the corresponding
722+
// dep-node color has been updated.
723+
// A query cycle which does not panic is one
724+
// such error.
725+
false
726+
}
717727
}
718728
}
719729
} else {
@@ -1061,7 +1071,7 @@ pub(super) struct CurrentDepGraph {
10611071
impl CurrentDepGraph {
10621072
fn new(
10631073
prev_graph: Lrc<PreviousDepGraph>,
1064-
file: File,
1074+
file: Option<File>,
10651075
invalidated: Vec<DepNodeIndex>,
10661076
model: Option<DepGraphModel>,
10671077
) -> CurrentDepGraph {

src/librustc/dep_graph/serialized.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ enum Action {
352352
struct SerializerWorker {
353353
fingerprints: IndexVec<DepNodeIndex, Fingerprint>,
354354
previous: Lrc<PreviousDepGraph>,
355-
file: File,
355+
file: Option<File>,
356356
model: Option<DepGraphModel>,
357357
}
358358

@@ -495,7 +495,9 @@ impl Worker for SerializerWorker {
495495
},
496496
};
497497
action.encode(&mut encoder).ok();
498-
self.file.write_all(&encoder.into_inner()).expect("unable to write to temp dep graph");
498+
self.file.as_mut().map(|file| {
499+
file.write_all(&encoder.into_inner()).expect("unable to write to temp dep graph");
500+
});
499501
}
500502

501503
fn complete(self) -> CompletedDepGraph {
@@ -520,7 +522,7 @@ pub struct Serializer {
520522

521523
impl Serializer {
522524
pub fn new(
523-
file: File,
525+
file: Option<File>,
524526
previous: Lrc<PreviousDepGraph>,
525527
invalidated: Vec<DepNodeIndex>,
526528
model: Option<DepGraphModel>,

src/librustc/ty/query/plumbing.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'tcx> TyCtxt<'tcx> {
484484
// If -Zincremental-verify-ich is specified, re-hash results from
485485
// the cache and make sure that they have the expected fingerprint.
486486
if unlikely!(self.sess.opts.debugging_opts.incremental_verify_ich) {
487-
self.incremental_verify_ich::<Q>(&result, dep_node, dep_node_index);
487+
self.incremental_verify_ich::<Q>(&result, dep_node);
488488
}
489489

490490
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
@@ -498,28 +498,21 @@ impl<'tcx> TyCtxt<'tcx> {
498498
#[cold]
499499
fn incremental_verify_ich<Q: QueryDescription<'tcx>>(
500500
self,
501-
_result: &Q::Value,
502-
_dep_node: &DepNode,
503-
_dep_node_index: DepNodeIndex,
501+
result: &Q::Value,
502+
dep_node: &DepNode,
504503
) {
505-
panic!()/*
506504
use crate::ich::Fingerprint;
507505

508-
assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
509-
self.dep_graph.prev_fingerprint_of(dep_node),
510-
"Fingerprint for green query instance not loaded \
511-
from cache: {:?}", dep_node);
512-
513506
debug!("BEGIN verify_ich({:?})", dep_node);
514507
let mut hcx = self.create_stable_hashing_context();
515508

516509
let new_hash = Q::hash_result(&mut hcx, result).unwrap_or(Fingerprint::ZERO);
517510
debug!("END verify_ich({:?})", dep_node);
518511

519-
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
512+
let old_hash = self.dep_graph.prev_fingerprint_of(dep_node);
520513

521-
assert!(new_hash == old_hash, "Found unstable fingerprints \
522-
for {:?}", dep_node);*/
514+
assert!(Some(new_hash) == old_hash, "Found unstable fingerprints \
515+
for {:?}", dep_node);
523516
}
524517

525518
#[inline(always)]

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
use std::iter::FromIterator;
1717
use std::vec::Vec;
18-
use rustc::dep_graph::{DepNode, label_strs};
18+
use rustc::dep_graph::{CompletedDepGraph, ReconstructedDepGraph, DepNode, label_strs};
1919
use rustc::hir;
2020
use rustc::hir::{ItemKind as HirItem, ImplItemKind, TraitItemKind};
2121
use rustc::hir::Node as HirNode;
@@ -206,16 +206,21 @@ impl Assertion {
206206
}
207207
}
208208

209-
pub fn check_dirty_clean_annotations<'tcx>(tcx: TyCtxt<'tcx>) {
209+
pub fn check_dirty_clean_annotations(
210+
tcx: TyCtxt<'_>,
211+
dep_graph: &CompletedDepGraph,
212+
) {
210213
// can't add `#[rustc_dirty]` etc without opting in to this feature
211214
if !tcx.features().rustc_attrs {
212215
return;
213216
}
214217

215218
tcx.dep_graph.with_ignore(|| {
219+
let graph = ReconstructedDepGraph::new(dep_graph);
216220
let krate = tcx.hir().krate();
217221
let mut dirty_clean_visitor = DirtyCleanVisitor {
218222
tcx,
223+
graph,
219224
checked_attrs: Default::default(),
220225
};
221226
krate.visit_all_item_likes(&mut dirty_clean_visitor);
@@ -236,6 +241,7 @@ pub fn check_dirty_clean_annotations<'tcx>(tcx: TyCtxt<'tcx>) {
236241

237242
struct DirtyCleanVisitor<'tcx> {
238243
tcx: TyCtxt<'tcx>,
244+
graph: ReconstructedDepGraph,
239245
checked_attrs: FxHashSet<ast::AttrId>,
240246
}
241247

@@ -459,7 +465,7 @@ impl DirtyCleanVisitor<'tcx> {
459465
})
460466
}
461467

462-
fn _dep_node_str(&self, dep_node: &DepNode) -> String {
468+
fn dep_node_str(&self, dep_node: &DepNode) -> String {
463469
if let Some(def_id) = dep_node.extract_def_id(self.tcx) {
464470
format!("{:?}({})",
465471
dep_node.kind,
@@ -469,34 +475,32 @@ impl DirtyCleanVisitor<'tcx> {
469475
}
470476
}
471477

472-
fn assert_dirty(&self, _item_span: Span, dep_node: DepNode) {
478+
fn assert_dirty(&self, item_span: Span, dep_node: DepNode) {
473479
debug!("assert_dirty({:?})", dep_node);
474-
panic!()
475-
/*let dep_node_index = self.tcx.dep_graph.dep_node_index_of(&dep_node);
476-
let current_fingerprint = self.tcx.dep_graph.fingerprint_of(dep_node_index);
480+
let dep_node_index = self.graph.dep_node_index_of(&dep_node);
481+
let current_fingerprint = self.graph.fingerprint_of(dep_node_index);
477482
let prev_fingerprint = self.tcx.dep_graph.prev_fingerprint_of(&dep_node);
478483

479484
if Some(current_fingerprint) == prev_fingerprint {
480485
let dep_node_str = self.dep_node_str(&dep_node);
481486
self.tcx.sess.span_err(
482487
item_span,
483488
&format!("`{}` should be dirty but is not", dep_node_str));
484-
}*/
489+
}
485490
}
486491

487-
fn assert_clean(&self, _item_span: Span, dep_node: DepNode) {
492+
fn assert_clean(&self, item_span: Span, dep_node: DepNode) {
488493
debug!("assert_clean({:?})", dep_node);
489-
panic!()
490-
/*let dep_node_index = self.tcx.dep_graph.dep_node_index_of(&dep_node);
491-
let current_fingerprint = self.tcx.dep_graph.fingerprint_of(dep_node_index);
494+
let dep_node_index = self.graph.dep_node_index_of(&dep_node);
495+
let current_fingerprint = self.graph.fingerprint_of(dep_node_index);
492496
let prev_fingerprint = self.tcx.dep_graph.prev_fingerprint_of(&dep_node);
493497

494498
if Some(current_fingerprint) != prev_fingerprint {
495499
let dep_node_str = self.dep_node_str(&dep_node);
496500
self.tcx.sess.span_err(
497501
item_span,
498502
&format!("`{}` should be clean but is not", dep_node_str));
499-
}*/
503+
}
500504
}
501505

502506
fn check_item(&mut self, item_id: hir::HirId, item_span: Span) {

src/librustc_incremental/persist/load.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn dep_graph_from_future(sess: &Session, future: DepGraphFuture) -> DepGraph
4545
DepGraphArgs {
4646
prev_graph: Default::default(),
4747
prev_work_products: Default::default(),
48-
file,
48+
file: Some(file),
4949
state: Default::default(),
5050
invalidated: Vec::new(),
5151
model: if use_model {
@@ -169,6 +169,28 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
169169

170170
let time_passes = sess.time_passes();
171171

172+
let use_model = sess.reconstruct_dep_graph() || cfg!(debug_assertions);
173+
174+
if sess.opts.incremental.is_none() {
175+
let args = DepGraphArgs {
176+
prev_graph: Default::default(),
177+
prev_work_products: Default::default(),
178+
file: None,
179+
state: Default::default(),
180+
invalidated: Vec::new(),
181+
model: if use_model {
182+
Some(Default::default())
183+
} else {
184+
None
185+
},
186+
};
187+
188+
// No incremental compilation.
189+
return MaybeAsync::Sync(LoadResult::Ok {
190+
data: args,
191+
});
192+
}
193+
172194
// Calling `sess.incr_comp_session_dir()` will panic if `sess.opts.incremental.is_none()`.
173195
// Fortunately, we just checked that this isn't the case.
174196
let dir = &sess.incr_comp_session_dir();
@@ -187,7 +209,6 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
187209

188210
let report_incremental_info = sess.opts.debugging_opts.incremental_info;
189211
let expected_hash = sess.opts.dep_tracking_hash();
190-
let use_model = sess.reconstruct_dep_graph() || cfg!(debug_assertions);
191212

192213
let mut prev_work_products = FxHashMap::default();
193214

@@ -285,7 +306,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
285306
data: DepGraphArgs {
286307
prev_graph: result.prev_graph,
287308
prev_work_products,
288-
file,
309+
file: Some(file),
289310
state: result.state,
290311
invalidated: result.invalidated,
291312
model: result.model,

src/librustc_incremental/persist/save.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,20 @@ pub fn save_dep_graph<'tcx>(tcx: TyCtxt<'tcx>) {
2121
debug!("save_dep_graph()");
2222
tcx.dep_graph.with_ignore(|| {
2323
let sess = tcx.sess;
24+
2425
if sess.opts.incremental.is_none() {
26+
if !tcx.sess.opts.build_dep_graph() {
27+
return;
28+
}
29+
30+
let results = time(tcx.sess, "finish dep graph", || {
31+
tcx.dep_graph.complete()
32+
});
33+
34+
time(tcx.sess,
35+
"assert dep graph",
36+
|| assert_dep_graph(tcx, &results));
37+
2538
return;
2639
}
2740

@@ -42,8 +55,6 @@ pub fn save_dep_graph<'tcx>(tcx: TyCtxt<'tcx>) {
4255
finish_dep_graph(tcx, &results_path)
4356
});
4457
});
45-
46-
dirty_clean::check_dirty_clean_annotations(tcx);
4758
})
4859
}
4960

@@ -142,6 +153,9 @@ fn finish_dep_graph(tcx: TyCtxt<'_>, results_path: &Path) {
142153
"assert dep graph",
143154
|| assert_dep_graph(tcx, &results));
144155

156+
157+
dirty_clean::check_dirty_clean_annotations(tcx, &results);
158+
145159
if tcx.sess.opts.debugging_opts.incremental_info {
146160
let data = &results.model.as_ref().unwrap().data;
147161

0 commit comments

Comments
 (0)