mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Simplify path compression logic
This commit is contained in:
parent
d2a01760bc
commit
905db03b28
@ -62,15 +62,22 @@ impl scc::Annotation for RegionTracker {
|
|||||||
|
|
||||||
impl RegionTracker {
|
impl RegionTracker {
|
||||||
pub fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
|
pub fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
|
||||||
|
let (representative_is_placeholder, representative_is_existential) = match definition.origin {
|
||||||
|
rustc_infer::infer::NllRegionVariableOrigin::FreeRegion => (false, false),
|
||||||
|
rustc_infer::infer::NllRegionVariableOrigin::Placeholder(_) => (true, false),
|
||||||
|
rustc_infer::infer::NllRegionVariableOrigin::Existential { .. } => (false, true),
|
||||||
|
};
|
||||||
|
|
||||||
let placeholder_universe =
|
let placeholder_universe =
|
||||||
if definition.is_placeholder() { definition.universe } else { UniverseIndex::ROOT };
|
if representative_is_placeholder { definition.universe } else { UniverseIndex::ROOT };
|
||||||
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
max_placeholder_universe_reached: placeholder_universe,
|
max_placeholder_universe_reached: placeholder_universe,
|
||||||
min_reachable_universe: definition.universe,
|
min_reachable_universe: definition.universe,
|
||||||
representative: rvid,
|
representative: rvid,
|
||||||
representative_is_placeholder: definition.is_placeholder(),
|
representative_is_placeholder,
|
||||||
representative_is_existential: definition.is_existential(),
|
representative_is_existential,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn universe(self) -> UniverseIndex {
|
pub fn universe(self) -> UniverseIndex {
|
||||||
|
@ -2163,10 +2163,12 @@ impl<'tcx> RegionDefinition<'tcx> {
|
|||||||
Self { origin, universe, external_name: None }
|
Self { origin, universe, external_name: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_placeholder(&self) -> bool {
|
pub fn is_placeholder(&self) -> bool {
|
||||||
matches!(self.origin, NllRegionVariableOrigin::Placeholder(_))
|
matches!(self.origin, NllRegionVariableOrigin::Placeholder(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
pub fn is_existential(&self) -> bool {
|
pub fn is_existential(&self) -> bool {
|
||||||
matches!(self.origin, NllRegionVariableOrigin::Existential { .. })
|
matches!(self.origin, NllRegionVariableOrigin::Existential { .. })
|
||||||
}
|
}
|
||||||
|
@ -393,38 +393,23 @@ where
|
|||||||
// `InCycleWith` upwards.
|
// `InCycleWith` upwards.
|
||||||
// This loop performs the downward link encoding mentioned above. Details below!
|
// This loop performs the downward link encoding mentioned above. Details below!
|
||||||
let node_state = {
|
let node_state = {
|
||||||
let mut annotation = (self.to_annotation)(node);
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
debug!("find_state(r = {node:?} in state {:?})", self.node_states[node]);
|
debug!("find_state(r = {node:?} in state {:?})", self.node_states[node]);
|
||||||
match self.node_states[node] {
|
match self.node_states[node] {
|
||||||
NodeState::NotVisited => break NodeState::NotVisited,
|
s @ (NodeState::NotVisited | NodeState::BeingVisited{..} | NodeState::InCycle { .. }) => break s,
|
||||||
NodeState::BeingVisited { depth, annotation: previous_annotation } => {
|
|
||||||
break NodeState::BeingVisited {
|
|
||||||
depth,
|
|
||||||
annotation: previous_annotation.merge_scc(annotation),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
NodeState::InCycleWith { parent } => {
|
NodeState::InCycleWith { parent } => {
|
||||||
// We test this, to be extremely sure that we never
|
// We test this, to be extremely sure that we never
|
||||||
// ever break our termination condition for the
|
// ever break our termination condition for the
|
||||||
// reverse iteration loop.
|
// reverse iteration loop.
|
||||||
assert!(node != parent, "Node can not be in cycle with itself");
|
assert!(node != parent, "Node can not be in cycle with itself");
|
||||||
|
|
||||||
annotation = annotation.merge_scc((self.to_annotation)(node));
|
|
||||||
|
|
||||||
// Store the previous node as an inverted list link
|
// Store the previous node as an inverted list link
|
||||||
self.node_states[node] = NodeState::InCycleWith { parent: previous_node };
|
self.node_states[node] = NodeState::InCycleWith { parent: previous_node };
|
||||||
// Update to parent node.
|
// Update to parent node.
|
||||||
previous_node = node;
|
previous_node = node;
|
||||||
node = parent;
|
node = parent;
|
||||||
}
|
}
|
||||||
NodeState::InCycle { scc_index, annotation: previous_annotation } => {
|
|
||||||
break NodeState::InCycle {
|
|
||||||
scc_index,
|
|
||||||
annotation: previous_annotation.merge_scc(annotation),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user