use deref instead of inner
This commit is contained in:
parent
4b44db126e
commit
ad71cbfe66
4 changed files with 16 additions and 14 deletions
|
@ -15,6 +15,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use syntax_pos::Span;
|
use syntax_pos::Span;
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
crate struct ConstraintSet {
|
crate struct ConstraintSet {
|
||||||
|
@ -37,10 +38,6 @@ impl ConstraintSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inner(&self) -> &IndexVec<ConstraintIndex, OutlivesConstraint> {
|
|
||||||
&self.constraints
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn link(&mut self, len: usize) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
|
pub fn link(&mut self, len: usize) -> IndexVec<RegionVid, Option<ConstraintIndex>> {
|
||||||
let mut map = IndexVec::from_elem_n(None, len);
|
let mut map = IndexVec::from_elem_n(None, len);
|
||||||
|
|
||||||
|
@ -66,6 +63,12 @@ impl ConstraintSet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Deref for ConstraintSet {
|
||||||
|
type Target = IndexVec<ConstraintIndex, OutlivesConstraint>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target { &self.constraints }
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct OutlivesConstraint {
|
pub struct OutlivesConstraint {
|
||||||
// NB. The ordering here is not significant for correctness, but
|
// NB. The ordering here is not significant for correctness, but
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut constraints: Vec<_> = self.constraints.inner().iter().collect();
|
let mut constraints: Vec<_> = self.constraints.iter().collect();
|
||||||
constraints.sort();
|
constraints.sort();
|
||||||
for constraint in &constraints {
|
for constraint in &constraints {
|
||||||
let OutlivesConstraint {
|
let OutlivesConstraint {
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl<'this, 'tcx> dot::GraphWalk<'this> for RegionInferenceContext<'tcx> {
|
||||||
vids.into_cow()
|
vids.into_cow()
|
||||||
}
|
}
|
||||||
fn edges(&'this self) -> dot::Edges<'this, OutlivesConstraint> {
|
fn edges(&'this self) -> dot::Edges<'this, OutlivesConstraint> {
|
||||||
(&self.constraints.inner().raw[..]).into_cow()
|
(&self.constraints.raw[..]).into_cow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render `a: b` as `a <- b`, indicating the flow
|
// Render `a: b` as `a <- b`, indicating the flow
|
||||||
|
|
|
@ -216,7 +216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
type_tests: Vec<TypeTest<'tcx>>,
|
type_tests: Vec<TypeTest<'tcx>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// The `next` field should not yet have been initialized:
|
// The `next` field should not yet have been initialized:
|
||||||
debug_assert!(outlives_constraints.inner().iter().all(|c| c.next.is_none()));
|
debug_assert!(outlives_constraints.iter().all(|c| c.next.is_none()));
|
||||||
|
|
||||||
let num_region_variables = var_infos.len();
|
let num_region_variables = var_infos.len();
|
||||||
let num_universal_regions = universal_regions.len();
|
let num_universal_regions = universal_regions.len();
|
||||||
|
@ -438,7 +438,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues {
|
fn compute_region_values(&self, _mir: &Mir<'tcx>) -> RegionValues {
|
||||||
debug!("compute_region_values()");
|
debug!("compute_region_values()");
|
||||||
debug!("compute_region_values: constraints={:#?}", {
|
debug!("compute_region_values: constraints={:#?}", {
|
||||||
let mut constraints: Vec<_> = self.constraints.inner().iter().collect();
|
let mut constraints: Vec<_> = self.constraints.iter().collect();
|
||||||
constraints.sort();
|
constraints.sort();
|
||||||
constraints
|
constraints
|
||||||
});
|
});
|
||||||
|
@ -450,7 +450,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
let dependency_map = self.dependency_map.as_ref().unwrap();
|
let dependency_map = self.dependency_map.as_ref().unwrap();
|
||||||
|
|
||||||
// Constraints that may need to be repropagated (initially all):
|
// Constraints that may need to be repropagated (initially all):
|
||||||
let mut dirty_list: Vec<_> = self.constraints.inner().indices().collect();
|
let mut dirty_list: Vec<_> = self.constraints.indices().collect();
|
||||||
|
|
||||||
// Set to 0 for each constraint that is on the dirty list:
|
// Set to 0 for each constraint that is on the dirty list:
|
||||||
let mut clean_bit_vec = BitVector::new(dirty_list.len());
|
let mut clean_bit_vec = BitVector::new(dirty_list.len());
|
||||||
|
@ -459,7 +459,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
while let Some(constraint_idx) = dirty_list.pop() {
|
while let Some(constraint_idx) = dirty_list.pop() {
|
||||||
clean_bit_vec.insert(constraint_idx.index());
|
clean_bit_vec.insert(constraint_idx.index());
|
||||||
|
|
||||||
let constraint = &self.constraints.inner()[constraint_idx];
|
let constraint = &self.constraints[constraint_idx];
|
||||||
debug!("propagate_constraints: constraint={:?}", constraint);
|
debug!("propagate_constraints: constraint={:?}", constraint);
|
||||||
|
|
||||||
if inferred_values.add_region(constraint.sup, constraint.sub) {
|
if inferred_values.add_region(constraint.sup, constraint.sub) {
|
||||||
|
@ -925,7 +925,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
let blame_index = self.blame_constraint(longer_fr, shorter_fr);
|
let blame_index = self.blame_constraint(longer_fr, shorter_fr);
|
||||||
let blame_span = self.constraints.inner()[blame_index].span;
|
let blame_span = self.constraints[blame_index].span;
|
||||||
|
|
||||||
if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
|
if let Some(propagated_outlives_requirements) = propagated_outlives_requirements {
|
||||||
// Shrink `fr` until we find a non-local region (if we do).
|
// Shrink `fr` until we find a non-local region (if we do).
|
||||||
|
@ -1016,7 +1016,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
// - `fr1: X` transitively
|
// - `fr1: X` transitively
|
||||||
// - and `Y` is live at `elem`
|
// - and `Y` is live at `elem`
|
||||||
let index = self.blame_constraint(fr1, elem);
|
let index = self.blame_constraint(fr1, elem);
|
||||||
let region_sub = self.constraints.inner()[index].sub;
|
let region_sub = self.constraints[index].sub;
|
||||||
|
|
||||||
// then return why `Y` was live at `elem`
|
// then return why `Y` was live at `elem`
|
||||||
self.liveness_constraints.cause(region_sub, elem)
|
self.liveness_constraints.cause(region_sub, elem)
|
||||||
|
@ -1037,7 +1037,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
// of dependencies, which doesn't account for the locations of
|
// of dependencies, which doesn't account for the locations of
|
||||||
// contraints at all. But it will do for now.
|
// contraints at all. But it will do for now.
|
||||||
let relevant_constraint = self.constraints
|
let relevant_constraint = self.constraints
|
||||||
.inner()
|
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.filter_map(|(i, constraint)| {
|
.filter_map(|(i, constraint)| {
|
||||||
if !self.liveness_constraints.contains(constraint.sub, elem) {
|
if !self.liveness_constraints.contains(constraint.sub, elem) {
|
||||||
|
@ -1073,7 +1072,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
|
|
||||||
while changed {
|
while changed {
|
||||||
changed = false;
|
changed = false;
|
||||||
for constraint in self.constraints.inner() {
|
for constraint in self.constraints.iter() {
|
||||||
if let Some(n) = result_set[constraint.sup] {
|
if let Some(n) = result_set[constraint.sup] {
|
||||||
let m = n + 1;
|
let m = n + 1;
|
||||||
if result_set[constraint.sub]
|
if result_set[constraint.sub]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue