Skip to content

Commit ac230b7

Browse files
committed
Cleanup.
1 parent 33c9290 commit ac230b7

File tree

1 file changed

+43
-48
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+43
-48
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 43 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl std::convert::From<DepNodeIndex> for QueryInvocationId {
4646
}
4747

4848
struct DepGraphData<K: DepKind> {
49-
/// The dep-graph from the previous compilation session. It contains all
49+
/// The dep-graph from the compilation session. It contains all
5050
/// nodes and edges as well as all fingerprints of nodes that have them.
51-
previous: RwLock<CurrentDepGraph<K>>,
51+
graph: RwLock<CurrentDepGraph<K>>,
5252

5353
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
5454
/// their edges. This has the beneficial side-effect that multiple anonymous
@@ -120,7 +120,7 @@ impl<K: DepKind> DepGraph<K> {
120120

121121
DepGraph {
122122
data: Some(Lrc::new(DepGraphData {
123-
previous: RwLock::new(CurrentDepGraph::new(prev_graph)),
123+
graph: RwLock::new(CurrentDepGraph::new(prev_graph)),
124124
emitting_diagnostics: Default::default(),
125125
previous_work_products: prev_work_products,
126126
dep_node_debug: Default::default(),
@@ -148,7 +148,7 @@ impl<K: DepKind> DepGraph<K> {
148148

149149
pub fn query(&self) -> DepGraphQuery<K> {
150150
let data = self.data.as_ref().unwrap();
151-
data.previous.read().query()
151+
data.graph.read().query()
152152
}
153153

154154
pub fn assert_ignored(&self) {
@@ -238,7 +238,7 @@ impl<K: DepKind> DepGraph<K> {
238238
let current_fingerprint = hash_result(&mut hcx, &result);
239239

240240
// Intern the new `DepNode`.
241-
let dep_node_index = data.previous.write().intern_task_node(
241+
let dep_node_index = data.graph.write().intern_task_node(
242242
key,
243243
&edges[..],
244244
current_fingerprint,
@@ -284,8 +284,8 @@ impl<K: DepKind> DepGraph<K> {
284284
hash: data.anon_id_seed.combine(hasher.finish()).into(),
285285
};
286286

287-
let mut previous = data.previous.write();
288-
let dep_node_index = previous.intern_anon_node(target_dep_node, &task_deps.reads[..]);
287+
let dep_node_index =
288+
data.graph.write().intern_anon_node(target_dep_node, &task_deps.reads[..]);
289289

290290
(result, dep_node_index)
291291
} else {
@@ -295,7 +295,7 @@ impl<K: DepKind> DepGraph<K> {
295295

296296
/// Executes something within an "eval-always" task which is a task
297297
/// that runs whenever anything changes.
298-
pub fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
298+
pub(crate) fn with_eval_always_task<Ctxt: HasDepContext<DepKind = K>, A, R>(
299299
&self,
300300
key: DepNode<K>,
301301
cx: Ctxt,
@@ -350,31 +350,26 @@ impl<K: DepKind> DepGraph<K> {
350350
}
351351

352352
#[inline]
353-
pub fn dep_node_index_of(&self, dep_node: &DepNode<K>) -> DepNodeIndex {
354-
self.dep_node_index_of_opt(dep_node).unwrap()
355-
}
356-
357-
#[inline]
358-
pub fn dep_node_index_of_opt(&self, dep_node: &DepNode<K>) -> Option<DepNodeIndex> {
359-
let data = self.data.as_ref().unwrap();
360-
data.previous.read().dep_node_index_of_opt(dep_node)
353+
fn dep_node_index_of_opt(&self, dep_node: &DepNode<K>) -> Option<DepNodeIndex> {
354+
let data = self.data.as_ref()?;
355+
data.graph.read().dep_node_index_of_opt(dep_node)
361356
}
362357

363358
#[inline]
364359
pub fn dep_node_exists(&self, dep_node: &DepNode<K>) -> bool {
365-
self.data.is_some() && self.dep_node_index_of_opt(dep_node).is_some()
360+
self.dep_node_index_of_opt(dep_node).is_some()
366361
}
367362

368363
#[inline]
369-
pub fn dep_node_of(&self, dep_node_index: DepNodeIndex) -> DepNode<K> {
364+
fn dep_node_of(&self, dep_node_index: DepNodeIndex) -> DepNode<K> {
370365
let data = self.data.as_ref().unwrap();
371-
data.previous.read().dep_node_of(dep_node_index)
366+
data.graph.read().dep_node_of(dep_node_index)
372367
}
373368

374369
#[inline]
375-
pub fn fingerprint_of(&self, dep_node_index: DepNodeIndex) -> Fingerprint {
370+
pub(crate) fn fingerprint_of(&self, dep_node_index: DepNodeIndex) -> Fingerprint {
376371
let data = self.data.as_ref().unwrap();
377-
data.previous.read().fingerprint_of(dep_node_index)
372+
data.graph.read().fingerprint_of(dep_node_index)
378373
}
379374

380375
/// Checks whether a previous work product exists for `v` and, if
@@ -390,7 +385,7 @@ impl<K: DepKind> DepGraph<K> {
390385
}
391386

392387
#[inline(always)]
393-
pub fn register_dep_node_debug_str<F>(&self, dep_node: DepNode<K>, debug_str_gen: F)
388+
pub(crate) fn register_dep_node_debug_str<F>(&self, dep_node: DepNode<K>, debug_str_gen: F)
394389
where
395390
F: FnOnce() -> String,
396391
{
@@ -409,9 +404,9 @@ impl<K: DepKind> DepGraph<K> {
409404

410405
pub fn node_color(&self, dep_node: &DepNode<K>) -> Option<DepNodeColor> {
411406
if let Some(ref data) = self.data {
412-
let previous = data.previous.read();
413-
if let Some(prev_index) = previous.node_to_index_opt(dep_node) {
414-
return previous.color(prev_index);
407+
let graph = data.graph.read();
408+
if let Some(prev_index) = graph.node_to_index_opt(dep_node) {
409+
return graph.color(prev_index);
415410
} else {
416411
// This is a node that did not exist in the previous compilation
417412
// session, so we consider it to be red.
@@ -426,7 +421,7 @@ impl<K: DepKind> DepGraph<K> {
426421
/// A node will have an index, when it's already been marked green, or when we can mark it
427422
/// green. This function will mark the current task as a reader of the specified node, when
428423
/// a node index can be found for that node.
429-
pub fn try_mark_green_and_read<Ctxt: QueryContext<DepKind = K>>(
424+
pub(crate) fn try_mark_green_and_read<Ctxt: QueryContext<DepKind = K>>(
430425
&self,
431426
tcx: Ctxt,
432427
dep_node: &DepNode<K>,
@@ -449,8 +444,8 @@ impl<K: DepKind> DepGraph<K> {
449444
let data = self.data.as_ref()?;
450445

451446
// Return None if the dep node didn't exist in the previous session
452-
let prev_index = data.previous.read().node_to_index_opt(dep_node)?;
453-
let prev_deps = data.previous.read().color_or_edges(prev_index);
447+
let prev_index = data.graph.read().node_to_index_opt(dep_node)?;
448+
let prev_deps = data.graph.read().color_or_edges(prev_index);
454449
let prev_deps = match prev_deps {
455450
Err(prev_deps) => prev_deps,
456451
Ok(DepNodeColor::Green) => return Some((prev_index, prev_index.rejuvenate())),
@@ -473,7 +468,7 @@ impl<K: DepKind> DepGraph<K> {
473468
parent_dep_node_index: SerializedDepNodeIndex,
474469
dep_node: &DepNode<K>,
475470
) -> Option<()> {
476-
let dep_dep_node_color = data.previous.read().color_or_edges(parent_dep_node_index);
471+
let dep_dep_node_color = data.graph.read().color_or_edges(parent_dep_node_index);
477472
let prev_deps = match dep_dep_node_color {
478473
Ok(DepNodeColor::Green) => {
479474
// This dependency has been marked as green before, we are
@@ -482,7 +477,7 @@ impl<K: DepKind> DepGraph<K> {
482477
debug!(
483478
"try_mark_parent_green({:?}) --- found dependency {:?} to be immediately green",
484479
dep_node,
485-
data.previous.read().index_to_node(parent_dep_node_index)
480+
data.graph.read().index_to_node(parent_dep_node_index)
486481
);
487482
return Some(());
488483
}
@@ -494,7 +489,7 @@ impl<K: DepKind> DepGraph<K> {
494489
debug!(
495490
"try_mark_parent_green({:?}) - END - dependency {:?} was immediately red",
496491
dep_node,
497-
data.previous.read().index_to_node(parent_dep_node_index)
492+
data.graph.read().index_to_node(parent_dep_node_index)
498493
);
499494
return None;
500495
}
@@ -508,12 +503,12 @@ impl<K: DepKind> DepGraph<K> {
508503
is unknown, trying to mark it green",
509504
dep_node,
510505
{
511-
let dep_dep_node = data.previous.read().index_to_node(parent_dep_node_index);
506+
let dep_dep_node = data.graph.read().index_to_node(parent_dep_node_index);
512507
(dep_dep_node, dep_dep_node.hash)
513508
}
514509
);
515510

516-
let dep_dep_node = &data.previous.read().index_to_node(parent_dep_node_index);
511+
let dep_dep_node = &data.graph.read().index_to_node(parent_dep_node_index);
517512
let node_index =
518513
self.try_mark_previous_green(tcx, data, parent_dep_node_index, prev_deps, dep_dep_node);
519514
if node_index.is_some() {
@@ -538,7 +533,7 @@ impl<K: DepKind> DepGraph<K> {
538533
return None;
539534
}
540535

541-
let dep_dep_node_color = data.previous.read().color(parent_dep_node_index);
536+
let dep_dep_node_color = data.graph.read().color(parent_dep_node_index);
542537

543538
match dep_dep_node_color {
544539
Some(DepNodeColor::Green) => {
@@ -597,15 +592,15 @@ impl<K: DepKind> DepGraph<K> {
597592

598593
// We never try to mark eval_always nodes as green
599594
debug_assert!(!dep_node.kind.is_eval_always());
600-
debug_assert_eq!(data.previous.read().index_to_node(prev_dep_node_index), *dep_node);
595+
debug_assert_eq!(data.graph.read().index_to_node(prev_dep_node_index), *dep_node);
601596

602597
for &dep_dep_node_index in prev_deps {
603598
self.try_mark_parent_green(tcx, data, dep_dep_node_index, dep_node)?
604599
}
605600

606601
#[cfg(not(parallel_compiler))]
607602
debug_assert_eq!(
608-
data.previous.read().color(prev_dep_node_index),
603+
data.graph.read().color(prev_dep_node_index),
609604
None,
610605
"DepGraph::try_mark_previous_green() - Duplicate DepNodeColor \
611606
insertion for {:?}",
@@ -621,7 +616,7 @@ impl<K: DepKind> DepGraph<K> {
621616
let dep_node_index = {
622617
// We allocating an entry for the node in the current dependency graph and
623618
// adding all the appropriate edges imported from the previous graph
624-
data.previous.write().intern_dark_green_node(prev_dep_node_index)
619+
data.graph.write().intern_dark_green_node(prev_dep_node_index)
625620
};
626621

627622
// ... and emitting any stored diagnostic.
@@ -677,11 +672,11 @@ impl<K: DepKind> DepGraph<K> {
677672
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
678673

679674
let data = self.data.as_ref().unwrap();
680-
let previous = data.previous.read();
681-
for prev_index in previous.serialized_indices() {
682-
match previous.color(prev_index) {
675+
let graph = data.graph.read();
676+
for prev_index in graph.serialized_indices() {
677+
match graph.color(prev_index) {
683678
Some(DepNodeColor::Green) => {
684-
let dep_node = data.previous.read().index_to_node(prev_index);
679+
let dep_node = data.graph.read().index_to_node(prev_index);
685680
debug!("PROMOTE {:?} {:?}", prev_index, dep_node);
686681
qcx.try_load_from_on_disk_cache(&dep_node);
687682
}
@@ -697,11 +692,11 @@ impl<K: DepKind> DepGraph<K> {
697692
// Register reused dep nodes (i.e. nodes we've marked red or green) with the context.
698693
pub fn register_reused_dep_nodes<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
699694
let data = self.data.as_ref().unwrap();
700-
let previous = data.previous.read();
701-
for prev_index in previous.serialized_indices() {
702-
match previous.color(prev_index) {
695+
let graph = data.graph.read();
696+
for prev_index in graph.serialized_indices() {
697+
match graph.color(prev_index) {
703698
Some(_) => {
704-
let dep_node = data.previous.read().index_to_node(prev_index);
699+
let dep_node = data.graph.read().index_to_node(prev_index);
705700
tcx.register_reused_dep_node(&dep_node);
706701
}
707702
None => {}
@@ -718,7 +713,7 @@ impl<K: DepKind> DepGraph<K> {
718713
}
719714

720715
let data = self.data.as_ref().unwrap();
721-
let prev = &data.previous.read();
716+
let prev = &data.graph.read();
722717

723718
let mut stats: FxHashMap<_, Stat<K>> = FxHashMap::with_hasher(Default::default());
724719

@@ -797,14 +792,14 @@ impl<K: DepKind> DepGraph<K> {
797792
}
798793

799794
pub fn compression_map(&self) -> IndexVec<DepNodeIndex, Option<SerializedDepNodeIndex>> {
800-
self.data.as_ref().unwrap().previous.read().compression_map()
795+
self.data.as_ref().unwrap().graph.read().compression_map()
801796
}
802797

803798
pub fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), E::Error>
804799
where
805800
K: Encodable<E>,
806801
{
807-
if let Some(data) = &self.data { data.previous.read().encode(encoder) } else { Ok(()) }
802+
if let Some(data) = &self.data { data.graph.read().encode(encoder) } else { Ok(()) }
808803
}
809804
}
810805

0 commit comments

Comments
 (0)