Skip to content

Commit 0c81a2f

Browse files
nikomatsakisJohnHeitmann
authored andcommitted
track if any region constraints involved placeholders
1 parent 500c093 commit 0c81a2f

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

src/librustc/infer/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -867,10 +867,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
867867
r
868868
}
869869

870+
/// Scan the constraints produced since `snapshot` began and returns:
871+
///
872+
/// - None -- if none of them involve "region outlives" constraints
873+
/// - Some(true) -- if there are `'a: 'b` constraints where `'a` or `'b` is a placehodler
874+
/// - Some(false) -- if there are `'a: 'b` constraints but none involve placeholders
870875
pub fn region_constraints_added_in_snapshot(
871876
&self,
872877
snapshot: &CombinedSnapshot<'a, 'tcx>,
873-
) -> bool {
878+
) -> Option<bool> {
874879
self.borrow_region_constraints().region_constraints_added_in_snapshot(
875880
&snapshot.region_constraints_snapshot,
876881
)

src/librustc/infer/region_constraints/mod.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ pub enum Constraint<'tcx> {
128128
RegSubReg(Region<'tcx>, Region<'tcx>),
129129
}
130130

131+
impl Constraint<'_> {
132+
pub fn involves_placeholders(&self) -> bool {
133+
match self {
134+
Constraint::VarSubVar(_, _) => false,
135+
Constraint::VarSubReg(_, r) | Constraint::RegSubVar(r, _) => r.is_placeholder(),
136+
Constraint::RegSubReg(r, s) => r.is_placeholder() || s.is_placeholder(),
137+
}
138+
}
139+
}
140+
131141
/// VerifyGenericBound(T, _, R, RS): The parameter type `T` (or
132142
/// associated type) must outlive the region `R`. `T` is known to
133143
/// outlive `RS`. Therefore verify that `R <= RS[i]` for some
@@ -324,6 +334,8 @@ impl TaintDirections {
324334
}
325335
}
326336

337+
pub struct ConstraintInfo {}
338+
327339
impl<'tcx> RegionConstraintCollector<'tcx> {
328340
pub fn new() -> Self {
329341
Self::default()
@@ -485,7 +497,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
485497
) -> RegionVid {
486498
let vid = self.var_infos.push(RegionVariableInfo { origin, universe });
487499

488-
let u_vid = self.unification_table
500+
let u_vid = self
501+
.unification_table
489502
.new_key(unify_key::RegionVidKey { min_vid: vid });
490503
assert_eq!(vid, u_vid);
491504
if self.in_snapshot() {
@@ -517,7 +530,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
517530

518531
assert!(self.in_snapshot());
519532

520-
let constraints_to_kill: Vec<usize> = self.undo_log
533+
let constraints_to_kill: Vec<usize> = self
534+
.undo_log
521535
.iter()
522536
.enumerate()
523537
.rev()
@@ -820,17 +834,18 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
820834
.filter_map(|&elt| match elt {
821835
AddVar(vid) => Some(vid),
822836
_ => None,
823-
})
824-
.collect()
837+
}).collect()
825838
}
826839

827-
pub fn region_constraints_added_in_snapshot(&self, mark: &RegionSnapshot) -> bool {
840+
/// See [`RegionInference::region_constraints_added_in_snapshot`]
841+
pub fn region_constraints_added_in_snapshot(&self, mark: &RegionSnapshot) -> Option<bool> {
828842
self.undo_log[mark.length..]
829843
.iter()
830-
.any(|&elt| match elt {
831-
AddConstraint(_) => true,
832-
_ => false,
833-
})
844+
.map(|&elt| match elt {
845+
AddConstraint(constraint) => Some(constraint.involves_placeholders()),
846+
_ => None,
847+
}).max()
848+
.unwrap_or(None)
834849
}
835850
}
836851

src/librustc/traits/select.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -639,10 +639,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
639639
) -> Result<EvaluationResult, OverflowError> {
640640
self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
641641
let result = op(self)?;
642-
if !self.infcx.region_constraints_added_in_snapshot(snapshot) {
643-
Ok(result)
644-
} else {
645-
Ok(result.max(EvaluatedToOkModuloRegions))
642+
match self.infcx.region_constraints_added_in_snapshot(snapshot) {
643+
None => Ok(result),
644+
Some(_) => Ok(result.max(EvaluatedToOkModuloRegions)),
646645
}
647646
})
648647
}

0 commit comments

Comments
 (0)