Skip to content

Commit b19f5a1

Browse files
committed
wip
1 parent 16952fd commit b19f5a1

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>,
@@ -713,8 +713,18 @@ impl DepGraph {
713713
DepNodeState::Invalid |
714714
DepNodeState::UnknownEvalAlways |
715715
DepNodeState::Unknown => {
716-
bug!("try_force_previous_green() - Forcing the DepNode \
716+
if !tcx.sess.has_errors() {
717+
bug!("try_force_previous_green() - Forcing the DepNode \
717718
should have set its color")
719+
} else {
720+
// If the query we just forced has resulted
721+
// in some kind of compilation error, we
722+
// don't expect that the corresponding
723+
// dep-node color has been updated.
724+
// A query cycle which does not panic is one
725+
// such error.
726+
false
727+
}
718728
}
719729
}
720730
} else {
@@ -1062,7 +1072,7 @@ pub(super) struct CurrentDepGraph {
10621072
impl CurrentDepGraph {
10631073
fn new(
10641074
prev_graph: Lrc<PreviousDepGraph>,
1065-
file: File,
1075+
file: Option<File>,
10661076
invalidated: Vec<DepNodeIndex>,
10671077
model: Option<DepGraphModel>,
10681078
) -> 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
@@ -494,7 +494,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
494494
// If -Zincremental-verify-ich is specified, re-hash results from
495495
// the cache and make sure that they have the expected fingerprint.
496496
if unlikely!(self.sess.opts.debugging_opts.incremental_verify_ich) {
497-
self.incremental_verify_ich::<Q>(&result, dep_node, dep_node_index);
497+
self.incremental_verify_ich::<Q>(&result, dep_node);
498498
}
499499

500500
if unlikely!(self.sess.opts.debugging_opts.query_dep_graph) {
@@ -508,28 +508,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
508508
#[cold]
509509
fn incremental_verify_ich<Q: QueryDescription<'gcx>>(
510510
self,
511-
_result: &Q::Value,
512-
_dep_node: &DepNode,
513-
_dep_node_index: DepNodeIndex,
511+
result: &Q::Value,
512+
dep_node: &DepNode,
514513
) {
515-
panic!()/*
516514
use crate::ich::Fingerprint;
517515

518-
assert!(Some(self.dep_graph.fingerprint_of(dep_node_index)) ==
519-
self.dep_graph.prev_fingerprint_of(dep_node),
520-
"Fingerprint for green query instance not loaded \
521-
from cache: {:?}", dep_node);
522-
523516
debug!("BEGIN verify_ich({:?})", dep_node);
524517
let mut hcx = self.create_stable_hashing_context();
525518

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

529-
let old_hash = self.dep_graph.fingerprint_of(dep_node_index);
522+
let old_hash = self.dep_graph.prev_fingerprint_of(dep_node);
530523

531-
assert!(new_hash == old_hash, "Found unstable fingerprints \
532-
for {:?}", dep_node);*/
524+
assert!(Some(new_hash) == old_hash, "Found unstable fingerprints \
525+
for {:?}", dep_node);
533526
}
534527

535528
#[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<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
209+
pub fn check_dirty_clean_annotations<'a, 'tcx>(
210+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
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<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
236241

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

@@ -460,7 +466,7 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
460466
})
461467
}
462468

463-
fn _dep_node_str(&self, dep_node: &DepNode) -> String {
469+
fn dep_node_str(&self, dep_node: &DepNode) -> String {
464470
if let Some(def_id) = dep_node.extract_def_id(self.tcx) {
465471
format!("{:?}({})",
466472
dep_node.kind,
@@ -470,34 +476,32 @@ impl<'a, 'tcx> DirtyCleanVisitor<'a, 'tcx> {
470476
}
471477
}
472478

473-
fn assert_dirty(&self, _item_span: Span, dep_node: DepNode) {
479+
fn assert_dirty(&self, item_span: Span, dep_node: DepNode) {
474480
debug!("assert_dirty({:?})", dep_node);
475-
panic!()
476-
/*let dep_node_index = self.tcx.dep_graph.dep_node_index_of(&dep_node);
477-
let current_fingerprint = self.tcx.dep_graph.fingerprint_of(dep_node_index);
481+
let dep_node_index = self.graph.dep_node_index_of(&dep_node);
482+
let current_fingerprint = self.graph.fingerprint_of(dep_node_index);
478483
let prev_fingerprint = self.tcx.dep_graph.prev_fingerprint_of(&dep_node);
479484

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

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

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

503507
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<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, '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>(tcx: TyCtxt<'_, 'tcx, 'tcx>, 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)