Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cc132b5

Browse files
committed
Simplify path compression logic
1 parent 609a202 commit cc132b5

File tree

3 files changed

+14
-20
lines changed
  • compiler
    • rustc_borrowck/src
    • rustc_data_structures/src/graph/scc

3 files changed

+14
-20
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,22 @@ impl scc::Annotation for RegionTracker {
6262

6363
impl RegionTracker {
6464
pub fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
65+
let (representative_is_placeholder, representative_is_existential) = match definition.origin {
66+
rustc_infer::infer::NllRegionVariableOrigin::FreeRegion => (false, false),
67+
rustc_infer::infer::NllRegionVariableOrigin::Placeholder(_) => (true, false),
68+
rustc_infer::infer::NllRegionVariableOrigin::Existential { .. } => (false, true),
69+
};
70+
6571
let placeholder_universe =
66-
if definition.is_placeholder() { definition.universe } else { UniverseIndex::ROOT };
72+
if representative_is_placeholder { definition.universe } else { UniverseIndex::ROOT };
73+
6774

6875
Self {
6976
max_placeholder_universe_reached: placeholder_universe,
7077
min_reachable_universe: definition.universe,
7178
representative: rvid,
72-
representative_is_placeholder: definition.is_placeholder(),
73-
representative_is_existential: definition.is_existential(),
79+
representative_is_placeholder,
80+
representative_is_existential,
7481
}
7582
}
7683
pub fn universe(self) -> UniverseIndex {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,10 +2163,12 @@ impl<'tcx> RegionDefinition<'tcx> {
21632163
Self { origin, universe, external_name: None }
21642164
}
21652165

2166+
#[inline(always)]
21662167
pub fn is_placeholder(&self) -> bool {
21672168
matches!(self.origin, NllRegionVariableOrigin::Placeholder(_))
21682169
}
21692170

2171+
#[inline(always)]
21702172
pub fn is_existential(&self) -> bool {
21712173
matches!(self.origin, NllRegionVariableOrigin::Existential { .. })
21722174
}

compiler/rustc_data_structures/src/graph/scc/mod.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -393,38 +393,23 @@ where
393393
// `InCycleWith` upwards.
394394
// This loop performs the downward link encoding mentioned above. Details below!
395395
let node_state = {
396-
let mut annotation = (self.to_annotation)(node);
397-
398396
loop {
399397
debug!("find_state(r = {node:?} in state {:?})", self.node_states[node]);
400398
match self.node_states[node] {
401-
NodeState::NotVisited => break NodeState::NotVisited,
402-
NodeState::BeingVisited { depth, annotation: previous_annotation } => {
403-
break NodeState::BeingVisited {
404-
depth,
405-
annotation: previous_annotation.merge_scc(annotation),
406-
};
407-
}
399+
s @ (NodeState::NotVisited | NodeState::BeingVisited{..} | NodeState::InCycle { .. }) => break s,
408400
NodeState::InCycleWith { parent } => {
409401
// We test this, to be extremely sure that we never
410402
// ever break our termination condition for the
411403
// reverse iteration loop.
412404
assert!(node != parent, "Node can not be in cycle with itself");
413405

414-
annotation = annotation.merge_scc((self.to_annotation)(node));
415-
416406
// Store the previous node as an inverted list link
417407
self.node_states[node] = NodeState::InCycleWith { parent: previous_node };
418408
// Update to parent node.
419409
previous_node = node;
420410
node = parent;
421411
}
422-
NodeState::InCycle { scc_index, annotation: previous_annotation } => {
423-
break NodeState::InCycle {
424-
scc_index,
425-
annotation: previous_annotation.merge_scc(annotation),
426-
};
427-
}
412+
428413
}
429414
}
430415
};

0 commit comments

Comments
 (0)