Skip to content

Commit 4170829

Browse files
committed
introduce ability to detect region constraints from snapshot
1 parent 4b5f274 commit 4170829

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

src/librustc/infer/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
868868
r
869869
}
870870

871+
pub fn region_constraints_added_in_snapshot(
872+
&self,
873+
snapshot: &CombinedSnapshot<'a, 'tcx>,
874+
) -> bool {
875+
self.borrow_region_constraints().region_constraints_added_in_snapshot(
876+
&snapshot.region_constraints_snapshot,
877+
)
878+
}
879+
871880
pub fn add_given(&self, sub: ty::Region<'tcx>, sup: ty::RegionVid) {
872881
self.borrow_region_constraints().add_given(sub, sup);
873882
}

src/librustc/infer/region_constraints/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,15 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
854854
debug!("tainted: result={:?}", taint_set);
855855
return taint_set.into_set();
856856
}
857+
858+
pub fn region_constraints_added_in_snapshot(&self, mark: &RegionSnapshot) -> bool {
859+
self.undo_log[mark.length..]
860+
.iter()
861+
.any(|&elt| match elt {
862+
AddConstraint(_) => true,
863+
_ => false,
864+
})
865+
}
857866
}
858867

859868
impl fmt::Debug for RegionSnapshot {

src/librustc/traits/select.rs

+22-8
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
629629
&mut self,
630630
obligation: &PredicateObligation<'tcx>,
631631
) -> Result<EvaluationResult, OverflowError> {
632-
self.infcx.probe(|_| {
633-
self.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
632+
self.evaluation_probe(|this| {
633+
this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
634+
})
635+
}
636+
637+
fn evaluation_probe(
638+
&mut self,
639+
op: impl FnOnce(&mut Self) -> Result<EvaluationResult, OverflowError>,
640+
) -> Result<EvaluationResult, OverflowError> {
641+
self.infcx.probe(|snapshot| -> Result<EvaluationResult, OverflowError> {
642+
let result = op(self)?;
643+
if !self.infcx.region_constraints_added_in_snapshot(snapshot) {
644+
Ok(result)
645+
} else {
646+
Ok(result.max(EvaluatedToOkModuloRegions))
647+
}
634648
})
635649
}
636650

@@ -988,10 +1002,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
9881002
"evaluate_candidate: depth={} candidate={:?}",
9891003
stack.obligation.recursion_depth, candidate
9901004
);
991-
let result = self.infcx.probe(|_| {
1005+
let result = self.evaluation_probe(|this| {
9921006
let candidate = (*candidate).clone();
993-
match self.confirm_candidate(stack.obligation, candidate) {
994-
Ok(selection) => self.evaluate_predicates_recursively(
1007+
match this.confirm_candidate(stack.obligation, candidate) {
1008+
Ok(selection) => this.evaluate_predicates_recursively(
9951009
stack.list(),
9961010
selection.nested_obligations().iter(),
9971011
),
@@ -1775,10 +1789,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17751789
stack: &TraitObligationStack<'o, 'tcx>,
17761790
where_clause_trait_ref: ty::PolyTraitRef<'tcx>,
17771791
) -> Result<EvaluationResult, OverflowError> {
1778-
self.infcx.probe(|_| {
1779-
match self.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
1792+
self.evaluation_probe(|this| {
1793+
match this.match_where_clause_trait_ref(stack.obligation, where_clause_trait_ref) {
17801794
Ok(obligations) => {
1781-
self.evaluate_predicates_recursively(stack.list(), obligations.iter())
1795+
this.evaluate_predicates_recursively(stack.list(), obligations.iter())
17821796
}
17831797
Err(()) => Ok(EvaluatedToErr),
17841798
}

0 commit comments

Comments
 (0)