Skip to content

Commit d04775d

Browse files
committed
change snapshot tracking in fulfillment contexts
1 parent 46973c9 commit d04775d

File tree

23 files changed

+80
-122
lines changed

23 files changed

+80
-122
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19741974
.copied()
19751975
.filter(|&(impl_, _)| {
19761976
infcx.probe(|_| {
1977-
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
1977+
let ocx = ObligationCtxt::new(&infcx);
19781978
ocx.register_obligations(obligations.clone());
19791979

19801980
let impl_substs = infcx.fresh_substs_for_item(span, impl_);

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
161161
&self,
162162
ty: Ty<'tcx>,
163163
) -> Option<(Ty<'tcx>, Vec<traits::PredicateObligation<'tcx>>)> {
164-
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.infcx);
164+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(self.infcx);
165165

166166
let cause = traits::ObligationCause::misc(self.span, self.body_id);
167167
let normalized_ty = match self

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ fn suggest_impl_trait<'tcx>(
12821282
{
12831283
continue;
12841284
}
1285-
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
1285+
let ocx = ObligationCtxt::new(&infcx);
12861286
let item_ty = ocx.normalize(
12871287
&ObligationCause::misc(span, def_id),
12881288
param_env,

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10331033
let Ok(ok) = coerce.coerce(source, target) else {
10341034
return false;
10351035
};
1036-
let ocx = ObligationCtxt::new_in_snapshot(self);
1036+
let ocx = ObligationCtxt::new(self);
10371037
ocx.register_obligations(ok.obligations);
10381038
ocx.select_where_possible().is_empty()
10391039
})

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29182918
};
29192919

29202920
self.commit_if_ok(|_| {
2921-
let ocx = ObligationCtxt::new_in_snapshot(self);
2921+
let ocx = ObligationCtxt::new(self);
29222922
let impl_substs = self.fresh_substs_for_item(base_expr.span, impl_def_id);
29232923
let impl_trait_ref =
29242924
self.tcx.impl_trait_ref(impl_def_id).unwrap().subst(self.tcx, impl_substs);

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
746746

747747
let expect_args = self
748748
.fudge_inference_if_ok(|| {
749-
let ocx = ObligationCtxt::new_in_snapshot(self);
749+
let ocx = ObligationCtxt::new(self);
750750

751751
// Attempt to apply a subtyping relationship between the formal
752752
// return type (likely containing type variables if the function

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163163
return fn_sig;
164164
}
165165
self.probe(|_| {
166-
let ocx = ObligationCtxt::new_in_snapshot(self);
166+
let ocx = ObligationCtxt::new(self);
167167
let normalized_fn_sig =
168168
ocx.normalize(&ObligationCause::dummy(), self.param_env, fn_sig);
169169
if ocx.select_all_or_error().is_empty() {

compiler/rustc_infer/src/infer/at.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ impl<'tcx> InferCtxt<'tcx> {
7979
reported_closure_mismatch: self.reported_closure_mismatch.clone(),
8080
tainted_by_errors: self.tainted_by_errors.clone(),
8181
err_count_on_creation: self.err_count_on_creation,
82-
in_snapshot: self.in_snapshot.clone(),
8382
universe: self.universe.clone(),
8483
intercrate: self.intercrate,
8584
next_trait_solver: self.next_trait_solver,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub use self::RegionVariableOrigin::*;
66
pub use self::SubregionOrigin::*;
77
pub use self::ValuePairs::*;
88
pub use combine::ObligationEmittingRelation;
9+
use rustc_data_structures::undo_log::UndoLogs;
910

1011
use self::opaque_types::OpaqueTypeStorage;
1112
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
@@ -297,9 +298,6 @@ pub struct InferCtxt<'tcx> {
297298
// FIXME(matthewjasper) Merge into `tainted_by_errors`
298299
err_count_on_creation: usize,
299300

300-
/// This flag is true while there is an active snapshot.
301-
in_snapshot: Cell<bool>,
302-
303301
/// What is the innermost universe we have created? Starts out as
304302
/// `UniverseIndex::root()` but grows from there as we enter
305303
/// universal quantifiers.
@@ -643,7 +641,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
643641
reported_closure_mismatch: Default::default(),
644642
tainted_by_errors: Cell::new(None),
645643
err_count_on_creation: tcx.sess.err_count(),
646-
in_snapshot: Cell::new(false),
647644
universe: Cell::new(ty::UniverseIndex::ROOT),
648645
intercrate,
649646
next_trait_solver,
@@ -679,7 +676,6 @@ pub struct CombinedSnapshot<'tcx> {
679676
undo_snapshot: Snapshot<'tcx>,
680677
region_constraints_snapshot: RegionSnapshot,
681678
universe: ty::UniverseIndex,
682-
was_in_snapshot: bool,
683679
}
684680

685681
impl<'tcx> InferCtxt<'tcx> {
@@ -702,10 +698,6 @@ impl<'tcx> InferCtxt<'tcx> {
702698
}
703699
}
704700

705-
pub fn is_in_snapshot(&self) -> bool {
706-
self.in_snapshot.get()
707-
}
708-
709701
pub fn freshen<T: TypeFoldable<TyCtxt<'tcx>>>(&self, t: T) -> T {
710702
t.fold_with(&mut self.freshener())
711703
}
@@ -766,31 +758,30 @@ impl<'tcx> InferCtxt<'tcx> {
766758
}
767759
}
768760

761+
pub fn in_snapshot(&self) -> bool {
762+
UndoLogs::<UndoLog<'tcx>>::in_snapshot(&self.inner.borrow_mut().undo_log)
763+
}
764+
765+
pub fn num_open_snapshots(&self) -> usize {
766+
UndoLogs::<UndoLog<'tcx>>::num_open_snapshots(&self.inner.borrow_mut().undo_log)
767+
}
768+
769769
fn start_snapshot(&self) -> CombinedSnapshot<'tcx> {
770770
debug!("start_snapshot()");
771771

772-
let in_snapshot = self.in_snapshot.replace(true);
773-
774772
let mut inner = self.inner.borrow_mut();
775773

776774
CombinedSnapshot {
777775
undo_snapshot: inner.undo_log.start_snapshot(),
778776
region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(),
779777
universe: self.universe(),
780-
was_in_snapshot: in_snapshot,
781778
}
782779
}
783780

784781
#[instrument(skip(self, snapshot), level = "debug")]
785782
fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'tcx>) {
786-
let CombinedSnapshot {
787-
undo_snapshot,
788-
region_constraints_snapshot,
789-
universe,
790-
was_in_snapshot,
791-
} = snapshot;
792-
793-
self.in_snapshot.set(was_in_snapshot);
783+
let CombinedSnapshot { undo_snapshot, region_constraints_snapshot, universe } = snapshot;
784+
794785
self.universe.set(universe);
795786

796787
let mut inner = self.inner.borrow_mut();
@@ -800,14 +791,8 @@ impl<'tcx> InferCtxt<'tcx> {
800791

801792
#[instrument(skip(self, snapshot), level = "debug")]
802793
fn commit_from(&self, snapshot: CombinedSnapshot<'tcx>) {
803-
let CombinedSnapshot {
804-
undo_snapshot,
805-
region_constraints_snapshot: _,
806-
universe: _,
807-
was_in_snapshot,
808-
} = snapshot;
809-
810-
self.in_snapshot.set(was_in_snapshot);
794+
let CombinedSnapshot { undo_snapshot, region_constraints_snapshot: _, universe: _ } =
795+
snapshot;
811796

812797
self.inner.borrow_mut().commit(undo_snapshot);
813798
}

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ impl<'tcx> InferCtxt<'tcx> {
125125
/// right before lexical region resolution.
126126
#[instrument(level = "debug", skip(self, outlives_env))]
127127
pub fn process_registered_region_obligations(&self, outlives_env: &OutlivesEnvironment<'tcx>) {
128-
assert!(
129-
!self.in_snapshot.get(),
130-
"cannot process registered region obligations in a snapshot"
131-
);
128+
assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
132129

133130
let my_region_obligations = self.take_registered_region_obligations();
134131

0 commit comments

Comments
 (0)