1
Fork 0

remove inner_mut as it can mess up invariants

This commit is contained in:
Eh2406 2018-06-27 17:47:55 -04:00
parent 497a3b4fd5
commit 9bd2a63f29
2 changed files with 23 additions and 22 deletions

View file

@ -23,17 +23,21 @@ crate struct ConstraintSet {
} }
impl ConstraintSet { impl ConstraintSet {
pub fn push(&mut self, outlives_constraint: OutlivesConstraint) { pub fn new() -> Self {
Default::default()
}
pub fn push(&mut self, constraint: OutlivesConstraint) {
debug!("add_outlives({:?}: {:?} @ {:?}", debug!("add_outlives({:?}: {:?} @ {:?}",
outlives_constraint.sup, constraint.sup,
outlives_constraint.sub, constraint.sub,
outlives_constraint.point); constraint.point);
if outlives_constraint.sup == outlives_constraint.sub { if constraint.sup == constraint.sub {
// 'a: 'a is pretty uninteresting // 'a: 'a is pretty uninteresting
return; return;
} }
if self.seen_constraints.insert(outlives_constraint.dedup_key()) { if self.seen_constraints.insert(constraint.dedup_key()) {
self.constraints.push(outlives_constraint); self.constraints.push(constraint);
} }
} }
@ -41,11 +45,17 @@ impl ConstraintSet {
&self.constraints &self.constraints
} }
/// Do Not use this to add nor remove items to the Vec, pub fn link(&mut self, len: usize) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
/// nor change the `sup`, let mut map = IndexVec::from_elem_n(None, len);
/// nor `sub` of the data.
pub fn inner_mut(&mut self) -> &mut IndexVec<ConstraintIndex, OutlivesConstraint> { for (idx, constraint) in self.constraints.iter_enumerated_mut().rev() {
&mut self.constraints let mut head = &mut map[constraint.sub];
debug_assert!(constraint.next.is_none());
constraint.next = *head;
*head = Some(idx);
}
map
} }
} }

View file

@ -486,16 +486,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// These are constraints like Y: X @ P -- so if X changed, we may /// These are constraints like Y: X @ P -- so if X changed, we may
/// need to grow Y. /// need to grow Y.
fn build_dependency_map(&mut self) -> IndexVec<RegionVid, Option<ConstraintIndex>> { fn build_dependency_map(&mut self) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
let mut map = IndexVec::from_elem(None, &self.definitions); self.constraints.link(self.definitions.len())
for (idx, constraint) in self.constraints.inner_mut().iter_enumerated_mut().rev() {
let mut head = &mut map[constraint.sub];
debug_assert!(constraint.next.is_none());
constraint.next = *head;
*head = Some(idx);
}
map
} }
/// Once regions have been propagated, this method is used to see /// Once regions have been propagated, this method is used to see