Skip to content

Commit 50beacc

Browse files
committed
cleanup1
1 parent 5dc471c commit 50beacc

File tree

2 files changed

+21
-46
lines changed

2 files changed

+21
-46
lines changed

compiler/rustc_type_ir/src/search_graph/mod.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
703703
evaluation_result.encountered_overflow,
704704
UpdateParentGoalCtxt::Ordinary(&evaluation_result.nested_goals),
705705
);
706+
// FIXME: Cloning the cycle heads here is quite ass. We should make cycle heads
707+
// CoW and use reference counting.
708+
self.tree.finish_evaluation(
709+
evaluation_result.node_id,
710+
evaluation_result.encountered_overflow,
711+
evaluation_result.heads.clone(),
712+
evaluation_result.result,
713+
);
706714
let result = evaluation_result.result;
707715

708716
// We're now done with this goal. We only add the root of cycles to the global cache.
@@ -1130,15 +1138,6 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
11301138
let mut stack_entry = self.stack.pop();
11311139
let mut encountered_overflow = stack_entry.encountered_overflow;
11321140
debug_assert_eq!(stack_entry.input, input);
1133-
// FIXME: Cloning the cycle heads here is quite ass. We should make cycle heads
1134-
// CoW and use reference counting.
1135-
self.tree.finish_evaluate(
1136-
stack_entry.node_id,
1137-
stack_entry.encountered_overflow,
1138-
stack_entry.heads.clone(),
1139-
result,
1140-
);
1141-
11421141
// If the current goal is not the root of a cycle, we are done.
11431142
//
11441143
// There are no provisional cache entries which depend on this goal.
@@ -1290,7 +1289,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
12901289
self.tree.get_cycle(cycle);
12911290

12921291
match self.tree.node_kind_raw(cycle_node_id) {
1293-
&tree::NodeKind::InProgress { .. } | &tree::NodeKind::Regular { .. } => {
1292+
&tree::NodeKind::InProgress { .. } | &tree::NodeKind::Finished { .. } => {
12941293
unreachable!()
12951294
}
12961295
&tree::NodeKind::CycleOnStack { entry_node_id, result: _ } => {

compiler/rustc_type_ir/src/search_graph/tree.rs

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,10 @@ rustc_index::newtype_index! {
2828

2929
#[derive_where(Debug; X: Cx)]
3030
pub(super) enum NodeKind<X: Cx> {
31-
InProgress {
32-
cycles_start: CycleId,
33-
},
34-
Regular {
35-
// The result of evaluating this node. This does not change between
36-
// reruns and may get accessed multiple times when rerunning parent nodes.
37-
encountered_overflow: bool,
38-
heads: CycleHeads,
39-
result: X::Result,
40-
41-
// When reevaluating the current goal, we need to know all cyclic
42-
// goals to check whether changing the provisional result changes the
43-
// the final result. This is only accessed when reevaluating a goal
44-
// and gets reset to the `tree.cycles.next_index()` at this point.
45-
// Not all of the cycles encountered while evaluating this goal actually
46-
// depend on this goal itself.
47-
cycles_start: CycleId,
48-
},
49-
CycleOnStack {
50-
entry_node_id: NodeId,
51-
result: X::Result,
52-
},
53-
ProvisionalCacheHit {
54-
entry_node_id: NodeId,
55-
},
31+
InProgress { cycles_start: CycleId },
32+
Finished { encountered_overflow: bool, heads: CycleHeads, result: X::Result },
33+
CycleOnStack { entry_node_id: NodeId, result: X::Result },
34+
ProvisionalCacheHit { entry_node_id: NodeId },
5635
}
5736

5837
#[derive_where(Debug; X: Cx)]
@@ -122,18 +101,17 @@ impl<X: Cx> SearchTree<X> {
122101
self.nodes[node_id].kind = NodeKind::CycleOnStack { entry_node_id, result }
123102
}
124103

125-
pub(super) fn finish_evaluate(
104+
pub(super) fn finish_evaluation(
126105
&mut self,
127106
node_id: NodeId,
128107
encountered_overflow: bool,
129108
heads: CycleHeads,
130109
result: X::Result,
131110
) {
132-
let NodeKind::InProgress { cycles_start } = self.nodes[node_id].kind else {
111+
let NodeKind::InProgress { cycles_start: _ } = self.nodes[node_id].kind else {
133112
panic!("unexpected node kind: {:?}", self.nodes[node_id]);
134113
};
135-
self.nodes[node_id].kind =
136-
NodeKind::Regular { cycles_start, encountered_overflow, heads, result }
114+
self.nodes[node_id].kind = NodeKind::Finished { encountered_overflow, heads, result }
137115
}
138116

139117
pub(super) fn get_cycle(&self, cycle_id: CycleId) -> &Cycle<X> {
@@ -147,17 +125,15 @@ impl<X: Cx> SearchTree<X> {
147125
pub(super) fn result_matches(&self, prev: NodeId, new: NodeId) -> bool {
148126
match (&self.nodes[prev].kind, &self.nodes[new].kind) {
149127
(
150-
NodeKind::Regular {
151-
result: prev_result,
128+
NodeKind::Finished {
152129
encountered_overflow: prev_overflow,
153130
heads: prev_heads,
154-
cycles_start: _,
131+
result: prev_result,
155132
},
156-
NodeKind::Regular {
133+
NodeKind::Finished {
157134
encountered_overflow: new_overflow,
158135
heads: new_heads,
159136
result: new_result,
160-
cycles_start: _,
161137
},
162138
) => {
163139
prev_result == new_result
@@ -173,7 +149,7 @@ impl<X: Cx> SearchTree<X> {
173149
}
174150

175151
pub(super) fn rerun_get_and_reset_cycles(&mut self, node_id: NodeId) -> Range<CycleId> {
176-
if let NodeKind::Regular { cycles_start, .. } = &mut self.nodes[node_id].kind {
152+
if let NodeKind::InProgress { cycles_start, .. } = &mut self.nodes[node_id].kind {
177153
let prev = *cycles_start;
178154
*cycles_start = self.cycles.next_index();
179155
prev..self.cycles.next_index()
@@ -183,7 +159,7 @@ impl<X: Cx> SearchTree<X> {
183159
}
184160

185161
pub(super) fn get_heads(&self, node_id: NodeId) -> &CycleHeads {
186-
if let NodeKind::Regular { heads, .. } = &self.nodes[node_id].kind {
162+
if let NodeKind::Finished { heads, .. } = &self.nodes[node_id].kind {
187163
heads
188164
} else {
189165
panic!("unexpected node kind: {:?}", self.nodes[node_id]);

0 commit comments

Comments
 (0)