more centril nits

This commit is contained in:
Niko Matsakis 2019-06-24 15:34:37 -04:00
parent d9f4d2ad1a
commit 0dd074e854
4 changed files with 39 additions and 30 deletions

View File

@ -27,7 +27,7 @@ pub fn new(
let num_edges = edge_pairs.len(); let num_edges = edge_pairs.len();
// Store the *target* of each edge into `edge_targets` // Store the *target* of each edge into `edge_targets`.
let edge_targets: Vec<N> = edge_pairs.iter().map(|&(_, target)| target).collect(); let edge_targets: Vec<N> = edge_pairs.iter().map(|&(_, target)| target).collect();
// Create the *edge starts* array. We are iterating over over // Create the *edge starts* array. We are iterating over over

View File

@ -8,18 +8,18 @@
use syntax_pos::Span; use syntax_pos::Span;
/// Compactly stores a set of `R0 member of [R1...Rn]` constraints, /// Compactly stores a set of `R0 member of [R1...Rn]` constraints,
/// indexed by the region R0. /// indexed by the region `R0`.
crate struct MemberConstraintSet<'tcx, R> crate struct MemberConstraintSet<'tcx, R>
where where
R: Copy + Hash + Eq, R: Copy + Hash + Eq,
{ {
/// Stores the first "member" constraint for a given R0. This is an /// Stores the first "member" constraint for a given `R0`. This is an
/// index into the `constraints` vector below. /// index into the `constraints` vector below.
first_constraints: FxHashMap<R, NllMemberConstraintIndex>, first_constraints: FxHashMap<R, NllMemberConstraintIndex>,
/// Stores the data about each `R0 member of [R1..Rn]` constraint. /// Stores the data about each `R0 member of [R1..Rn]` constraint.
/// These are organized into a linked list, so each constraint /// These are organized into a linked list, so each constraint
/// contains the index of the next constraint with the same R0. /// contains the index of the next constraint with the same `R0`.
constraints: IndexVec<NllMemberConstraintIndex, NllMemberConstraint<'tcx>>, constraints: IndexVec<NllMemberConstraintIndex, NllMemberConstraint<'tcx>>,
/// Stores the `R1..Rn` regions for *all* sets. For any given /// Stores the `R1..Rn` regions for *all* sets. For any given
@ -38,10 +38,10 @@
/// The span where the hidden type was instantiated. /// The span where the hidden type was instantiated.
crate definition_span: Span, crate definition_span: Span,
/// The hidden type in which R0 appears. (Used in error reporting.) /// The hidden type in which `R0` appears. (Used in error reporting.)
crate hidden_ty: Ty<'tcx>, crate hidden_ty: Ty<'tcx>,
/// The region R0. /// The region `R0`.
crate member_region_vid: ty::RegionVid, crate member_region_vid: ty::RegionVid,
/// Index of `R1` in `choice_regions` vector from `MemberConstraintSet`. /// Index of `R1` in `choice_regions` vector from `MemberConstraintSet`.
@ -68,6 +68,15 @@ fn default() -> Self {
} }
impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> { impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
/// Pushes a member constraint into the set.
///
/// The input member constraint `m_c` is in the form produced by
/// the the `rustc::infer` code.
///
/// The `to_region_vid` callback fn is used to convert the regions
/// within into `RegionVid` format -- it typically consults the
/// `UniversalRegions` data structure that is known to the caller
/// (but which this code is unaware of).
crate fn push_constraint( crate fn push_constraint(
&mut self, &mut self,
m_c: &MemberConstraint<'tcx>, m_c: &MemberConstraint<'tcx>,
@ -93,14 +102,14 @@ impl<'tcx> MemberConstraintSet<'tcx, ty::RegionVid> {
} }
} }
impl<'tcx, R1> MemberConstraintSet<'tcx, R1> impl<R1> MemberConstraintSet<'tcx, R1>
where where
R1: Copy + Hash + Eq, R1: Copy + Hash + Eq,
{ {
/// Remap the "member region" key using `map_fn`, producing a new /// Remap the "member region" key using `map_fn`, producing a new
/// pick-constraint set. This is used in the NLL code to map from /// member constraint set. This is used in the NLL code to map from
/// the original `RegionVid` to an scc index. In some cases, we /// the original `RegionVid` to an scc index. In some cases, we
/// may have multiple R1 values mapping to the same R2 key -- that /// may have multiple `R1` values mapping to the same `R2` key -- that
/// is ok, the two sets will be merged. /// is ok, the two sets will be merged.
crate fn into_mapped<R2>( crate fn into_mapped<R2>(
self, self,
@ -112,12 +121,12 @@ impl<'tcx, R1> MemberConstraintSet<'tcx, R1>
// We can re-use most of the original data, just tweaking the // We can re-use most of the original data, just tweaking the
// linked list links a bit. // linked list links a bit.
// //
// For example if we had two keys Ra and Rb that both now wind // For example if we had two keys `Ra` and `Rb` that both now
// up mapped to the same key S, we would append the linked // wind up mapped to the same key `S`, we would append the
// list for Ra onto the end of the linked list for Rb (or vice // linked list for `Ra` onto the end of the linked list for
// versa) -- this basically just requires rewriting the final // `Rb` (or vice versa) -- this basically just requires
// link from one list to point at the othe other (see // rewriting the final link from one list to point at the othe
// `append_list`). // other (see `append_list`).
let MemberConstraintSet { first_constraints, mut constraints, choice_regions } = self; let MemberConstraintSet { first_constraints, mut constraints, choice_regions } = self;
@ -140,7 +149,7 @@ impl<'tcx, R1> MemberConstraintSet<'tcx, R1>
} }
} }
impl<'tcx, R> MemberConstraintSet<'tcx, R> impl<R> MemberConstraintSet<'tcx, R>
where where
R: Copy + Hash + Eq, R: Copy + Hash + Eq,
{ {
@ -169,7 +178,7 @@ impl<'tcx, R> MemberConstraintSet<'tcx, R>
} }
/// Returns the "choice regions" for a given member /// Returns the "choice regions" for a given member
/// constraint. This is the R1..Rn from a constraint like: /// constraint. This is the `R1..Rn` from a constraint like:
/// ///
/// ``` /// ```
/// R0 member of [R1..Rn] /// R0 member of [R1..Rn]

View File

@ -221,7 +221,7 @@ fn find_constraint_paths_between_regions(
.outgoing_edges(r, &self.constraints, fr_static); .outgoing_edges(r, &self.constraints, fr_static);
// But pick-constraints can also give rise to `'r: 'x` // But member constraints can also give rise to `'r: 'x`
// edges that were not part of the graph initially, so // edges that were not part of the graph initially, so
// watch out for those. // watch out for those.
let outgoing_edges_from_picks = self.applied_member_constraints(r) let outgoing_edges_from_picks = self.applied_member_constraints(r)

View File

@ -75,7 +75,7 @@ pub struct RegionInferenceContext<'tcx> {
/// The "R0 member of [R1..Rn]" constraints, indexed by SCC. /// The "R0 member of [R1..Rn]" constraints, indexed by SCC.
member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>, member_constraints: Rc<MemberConstraintSet<'tcx, ConstraintSccIndex>>,
/// Records the pick-constraints that we applied to each scc. /// Records the member constraints that we applied to each scc.
/// This is useful for error reporting. Once constraint /// This is useful for error reporting. Once constraint
/// propagation is done, this vector is sorted according to /// propagation is done, this vector is sorted according to
/// `member_region_scc`. /// `member_region_scc`.
@ -447,7 +447,7 @@ pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
} }
/// Once region solving has completed, this function will return /// Once region solving has completed, this function will return
/// the pick-constraints that were applied to the value of a given /// the member constraints that were applied to the value of a given
/// region `r`. See `AppliedMemberConstraint`. /// region `r`. See `AppliedMemberConstraint`.
fn applied_member_constraints(&self, r: impl ToRegionVid) -> &[AppliedMemberConstraint] { fn applied_member_constraints(&self, r: impl ToRegionVid) -> &[AppliedMemberConstraint] {
let scc = self.constraint_sccs.scc(r.to_region_vid()); let scc = self.constraint_sccs.scc(r.to_region_vid());
@ -598,7 +598,7 @@ fn propagate_constraint_sccs_new(
} }
} }
// Now take member constraints into account // Now take member constraints into account.
let member_constraints = self.member_constraints.clone(); let member_constraints = self.member_constraints.clone();
for m_c_i in member_constraints.indices(scc_a) { for m_c_i in member_constraints.indices(scc_a) {
self.apply_member_constraint( self.apply_member_constraint(
@ -615,7 +615,7 @@ fn propagate_constraint_sccs_new(
); );
} }
/// Invoked for each `member R0 of [R1..Rn]` constraint. /// Invoked for each `R0 member of [R1..Rn]` constraint.
/// ///
/// `scc` is the SCC containing R0, and `choice_regions` are the /// `scc` is the SCC containing R0, and `choice_regions` are the
/// `R1..Rn` regions -- they are always known to be universal /// `R1..Rn` regions -- they are always known to be universal
@ -659,16 +659,16 @@ fn apply_member_constraint(
assert!(self.scc_universes[scc] == ty::UniverseIndex::ROOT); assert!(self.scc_universes[scc] == ty::UniverseIndex::ROOT);
debug_assert!( debug_assert!(
self.scc_values.placeholders_contained_in(scc).next().is_none(), self.scc_values.placeholders_contained_in(scc).next().is_none(),
"scc {:?} in a pick-constraint has placeholder value: {:?}", "scc {:?} in a member constraint has placeholder value: {:?}",
scc, scc,
self.scc_values.region_value_str(scc), self.scc_values.region_value_str(scc),
); );
// The existing value for `scc` is a lower-bound. This will // The existing value for `scc` is a lower-bound. This will
// consist of some set {P} + {LB} of points {P} and // consist of some set `{P} + {LB}` of points `{P}` and
// lower-bound free regions {LB}. As each choice region O is a // lower-bound free regions `{LB}`. As each choice region `O`
// free region, it will outlive the points. But we can only // is a free region, it will outlive the points. But we can
// consider the option O if O: LB. // only consider the option `O` if `O: LB`.
choice_regions.retain(|&o_r| { choice_regions.retain(|&o_r| {
self.scc_values self.scc_values
.universal_regions_outlived_by(scc) .universal_regions_outlived_by(scc)
@ -677,8 +677,8 @@ fn apply_member_constraint(
debug!("apply_member_constraint: after lb, choice_regions={:?}", choice_regions); debug!("apply_member_constraint: after lb, choice_regions={:?}", choice_regions);
// Now find all the *upper bounds* -- that is, each UB is a // Now find all the *upper bounds* -- that is, each UB is a
// free region that must outlive the member region R0 (`UB: // free region that must outlive the member region `R0` (`UB:
// R0`). Therefore, we need only keep an option O if `UB: O` // R0`). Therefore, we need only keep an option `O` if `UB: O`
// for all UB. // for all UB.
if choice_regions.len() > 1 { if choice_regions.len() > 1 {
let universal_region_relations = self.universal_region_relations.clone(); let universal_region_relations = self.universal_region_relations.clone();
@ -755,7 +755,7 @@ fn upper_bounds(
// I wanted to return an `impl Iterator` here, but it's // I wanted to return an `impl Iterator` here, but it's
// annoying because the `rev_constraint_graph` is in a local // annoying because the `rev_constraint_graph` is in a local
// variable. We'd need a "once-cell" or some such thing to let // variable. We'd need a "once-cell" or some such thing to let
// us borrow it for the right amount of time. // us borrow it for the right amount of time. -- nikomatsakis
let rev_constraint_graph = self.rev_constraint_graph(); let rev_constraint_graph = self.rev_constraint_graph();
let scc_values = &self.scc_values; let scc_values = &self.scc_values;
let mut duplicates = FxHashSet::default(); let mut duplicates = FxHashSet::default();