diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2018-08-24 23:11:44 -0400 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2018-09-06 19:58:22 -0400 |
| commit | db01b6789db9b4f89209ea6e28781dfd66eebbcb (patch) | |
| tree | 1a726a48df4bd9b1bcf0c8433d37157291d48313 | |
| parent | a8c11d216b04abe21a03220b344f1415e1d6ebd1 (diff) | |
| download | rust-db01b6789db9b4f89209ea6e28781dfd66eebbcb.tar.gz rust-db01b6789db9b4f89209ea6e28781dfd66eebbcb.zip | |
[nll] Refactor the `Edges` iterator to return `OutlivesConstraints`
Part of #53178
3 files changed, 31 insertions, 29 deletions
diff --git a/src/librustc_mir/borrow_check/nll/constraints/graph.rs b/src/librustc_mir/borrow_check/nll/constraints/graph.rs index 1a1094b570b..7cf94ec84dc 100644 --- a/src/librustc_mir/borrow_check/nll/constraints/graph.rs +++ b/src/librustc_mir/borrow_check/nll/constraints/graph.rs @@ -103,10 +103,15 @@ impl<D: ConstraintGraphDirecton> ConstraintGraph<D> { } /// Given a region `R`, iterate over all constraints `R: R1`. - crate fn outgoing_edges(&self, region_sup: RegionVid) -> Edges<'_, D> { + crate fn outgoing_edges<'a>( + &'a self, + region_sup: RegionVid, + constraints: &'a ConstraintSet, + ) -> Edges<'a, D> { let first = self.first_constraints[region_sup]; Edges { graph: self, + constraints, pointer: first, } } @@ -114,16 +119,17 @@ impl<D: ConstraintGraphDirecton> ConstraintGraph<D> { crate struct Edges<'s, D: ConstraintGraphDirecton> { graph: &'s ConstraintGraph<D>, + constraints: &'s ConstraintSet, pointer: Option<ConstraintIndex>, } impl<'s, D: ConstraintGraphDirecton> Iterator for Edges<'s, D> { - type Item = ConstraintIndex; + type Item = OutlivesConstraint; fn next(&mut self) -> Option<Self::Item> { if let Some(p) = self.pointer { self.pointer = self.graph.next_constraints[p]; - Some(p) + Some(self.constraints[p]) } else { None } @@ -154,14 +160,12 @@ impl<'s, D: ConstraintGraphDirecton> RegionGraph<'s, D> { /// there exists a constraint `R: R1`. crate fn outgoing_regions(&self, region_sup: RegionVid) -> Successors<'_, D> { Successors { - set: self.set, - edges: self.constraint_graph.outgoing_edges(region_sup), + edges: self.constraint_graph.outgoing_edges(region_sup, self.set), } } } crate struct Successors<'s, D: ConstraintGraphDirecton> { - set: &'s ConstraintSet, edges: Edges<'s, D>, } @@ -169,7 +173,7 @@ impl<'s, D: ConstraintGraphDirecton> Iterator for Successors<'s, D> { type Item = RegionVid; fn next(&mut self) -> Option<Self::Item> { - self.edges.next().map(|c| D::end_region(&self.set[c])) + self.edges.next().map(|c| D::end_region(&c)) } } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs index ca208a43431..2a541b6474f 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs @@ -8,7 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use borrow_check::nll::region_infer::{ConstraintIndex, RegionInferenceContext}; +use borrow_check::nll::constraints::OutlivesConstraint; +use borrow_check::nll::region_infer::RegionInferenceContext; use borrow_check::nll::type_check::Locations; use rustc::hir::def_id::DefId; use rustc::infer::error_reporting::nice_region_error::NiceRegionError; @@ -53,7 +54,7 @@ impl fmt::Display for ConstraintCategory { #[derive(Copy, Clone, PartialEq, Eq)] enum Trace { StartRegion, - FromConstraint(ConstraintIndex), + FromOutlivesConstraint(OutlivesConstraint), NotVisited, } @@ -80,12 +81,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!( "best_blame_constraint: path={:#?}", path.iter() - .map(|&ci| format!( - "{:?}: {:?} ({:?}: {:?})", - ci, - &self.constraints[ci], - self.constraint_sccs.scc(self.constraints[ci].sup), - self.constraint_sccs.scc(self.constraints[ci].sub), + .map(|&c| format!( + "{:?} ({:?}: {:?})", + c, + self.constraint_sccs.scc(c.sup), + self.constraint_sccs.scc(c.sub), )) .collect::<Vec<_>>() ); @@ -121,7 +121,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // highlight (e.g., a call site or something). let target_scc = self.constraint_sccs.scc(target_region); let best_choice = (0..path.len()).rev().find(|&i| { - let constraint = &self.constraints[path[i]]; + let constraint = path[i]; let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup); @@ -164,7 +164,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { &self, from_region: RegionVid, target_test: impl Fn(RegionVid) -> bool, - ) -> Option<(Vec<ConstraintIndex>, RegionVid)> { + ) -> Option<(Vec<OutlivesConstraint>, RegionVid)> { let mut context = IndexVec::from_elem(Trace::NotVisited, &self.definitions); context[from_region] = Trace::StartRegion; @@ -185,9 +185,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { Trace::NotVisited => { bug!("found unvisited region {:?} on path to {:?}", p, r) } - Trace::FromConstraint(c) => { + Trace::FromOutlivesConstraint(c) => { result.push(c); - p = self.constraints[c].sup; + p = c.sup; } Trace::StartRegion => { @@ -201,11 +201,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Otherwise, walk over the outgoing constraints and // enqueue any regions we find, keeping track of how we // reached them. - for constraint in self.constraint_graph.outgoing_edges(r) { - assert_eq!(self.constraints[constraint].sup, r); - let sub_region = self.constraints[constraint].sub; + for constraint in self.constraint_graph.outgoing_edges(r, &self.constraints) { + assert_eq!(constraint.sup, r); + let sub_region = constraint.sub; if let Trace::NotVisited = context[sub_region] { - context[sub_region] = Trace::FromConstraint(constraint); + context[sub_region] = Trace::FromOutlivesConstraint(constraint); deque.push_back(sub_region); } } @@ -216,8 +216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// This function will return true if a constraint is interesting and false if a constraint /// is not. It is useful in filtering constraint paths to only interesting points. - fn constraint_is_interesting(&self, index: ConstraintIndex) -> bool { - let constraint = self.constraints[index]; + fn constraint_is_interesting(&self, constraint: OutlivesConstraint) -> bool { debug!( "constraint_is_interesting: locations={:?} constraint={:?}", constraint.locations, constraint @@ -232,11 +231,10 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// This function classifies a constraint from a location. fn classify_constraint( &self, - index: ConstraintIndex, + constraint: OutlivesConstraint, mir: &Mir<'tcx>, tcx: TyCtxt<'_, '_, 'tcx>, ) -> (ConstraintCategory, Span) { - let constraint = self.constraints[index]; debug!("classify_constraint: constraint={:?}", constraint); let span = constraint.locations.span(mir); let location = constraint @@ -244,7 +242,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { .from_location() .unwrap_or(Location::START); - if !self.constraint_is_interesting(index) { + if !self.constraint_is_interesting(constraint) { return (ConstraintCategory::Boring, span); } diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index ff68b5987e8..4fe39ba3c95 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -11,7 +11,7 @@ use super::universal_regions::UniversalRegions; use borrow_check::nll::constraints::graph::NormalConstraintGraph; use borrow_check::nll::constraints::{ - ConstraintIndex, ConstraintSccIndex, ConstraintSet, OutlivesConstraint, + ConstraintSccIndex, ConstraintSet, OutlivesConstraint, }; use borrow_check::nll::region_infer::values::{RegionElement, ToElementIndex}; use borrow_check::nll::type_check::free_region_relations::UniversalRegionRelations; |
