Skip to content

Commit 6f495f3

Browse files
author
Markus Westerlind
committed
Improve naming
1 parent 0d448cf commit 6f495f3

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

src/librustc_infer/infer/fudge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8282
{
8383
debug!("fudge_inference_if_ok()");
8484

85-
let (mut fudger, value) = self.probe_full(|snapshot| {
85+
let (mut fudger, value) = self.probe_fudge(|snapshot| {
8686
match f() {
8787
Ok(value) => {
8888
let value = self.resolve_vars_if_possible(&value);

src/librustc_infer/infer/mod.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub struct InferCtxtInner<'tcx> {
167167
/// `resolve_regions_and_report_errors` is invoked, this gets set to `None`
168168
/// -- further attempts to perform unification, etc., may fail if new
169169
/// region constraints would've been added.
170-
region_constraints: Option<RegionConstraintStorage<'tcx>>,
170+
region_constraint_storage: Option<RegionConstraintStorage<'tcx>>,
171171

172172
/// A set of constraints that regionck must validate. Each
173173
/// constraint has the form `T:'a`, meaning "some type `T` must
@@ -214,7 +214,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
214214
const_unification_storage: ut::UnificationTableStorage::new(),
215215
int_unification_storage: ut::UnificationTableStorage::new(),
216216
float_unification_storage: ut::UnificationTableStorage::new(),
217-
region_constraints: Some(RegionConstraintStorage::new()),
217+
region_constraint_storage: Some(RegionConstraintStorage::new()),
218218
region_obligations: vec![],
219219
}
220220
}
@@ -268,7 +268,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
268268
}
269269

270270
pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'tcx, '_> {
271-
self.region_constraints
271+
self.region_constraint_storage
272272
.as_mut()
273273
.expect("region constraints already solved")
274274
.with_log(&mut self.undo_log)
@@ -705,8 +705,9 @@ impl<'tcx> InferOk<'tcx, ()> {
705705
}
706706
}
707707

708+
/// Extends `CombinedSnapshot` by tracking which variables were added in the snapshot
708709
#[must_use = "once you start a snapshot, you should always consume it"]
709-
pub struct FullSnapshot<'a, 'tcx> {
710+
pub struct FudgeSnapshot<'a, 'tcx> {
710711
snapshot: CombinedSnapshot<'a, 'tcx>,
711712
region_constraints_snapshot: RegionSnapshot,
712713
type_snapshot: type_variable::Snapshot<'tcx>,
@@ -830,10 +831,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
830831
result
831832
}
832833

833-
fn start_full_snapshot(&self) -> FullSnapshot<'a, 'tcx> {
834+
fn start_fudge_snapshot(&self) -> FudgeSnapshot<'a, 'tcx> {
834835
let snapshot = self.start_snapshot();
835836
let mut inner = self.inner.borrow_mut();
836-
FullSnapshot {
837+
FudgeSnapshot {
837838
snapshot,
838839
type_snapshot: inner.type_variables().snapshot(),
839840
const_var_len: inner.const_unification_table().len(),
@@ -925,12 +926,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
925926
r
926927
}
927928

928-
pub fn probe_full<R, F>(&self, f: F) -> R
929+
/// Like `probe` but provides information about which variables were created in the snapshot,
930+
/// allowing for inference fudging
931+
pub fn probe_fudge<R, F>(&self, f: F) -> R
929932
where
930-
F: FnOnce(&FullSnapshot<'a, 'tcx>) -> R,
933+
F: FnOnce(&FudgeSnapshot<'a, 'tcx>) -> R,
931934
{
932935
debug!("probe()");
933-
let snapshot = self.start_full_snapshot();
936+
let snapshot = self.start_fudge_snapshot();
934937
let r = f(&snapshot);
935938
self.rollback_to("probe", snapshot.snapshot);
936939
r
@@ -1294,7 +1297,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12941297
inner.region_obligations
12951298
);
12961299
inner
1297-
.region_constraints
1300+
.region_constraint_storage
12981301
.take()
12991302
.expect("regions already resolved")
13001303
.with_log(&mut inner.undo_log)
@@ -1362,7 +1365,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13621365
pub fn take_region_var_origins(&self) -> VarInfos {
13631366
let mut inner = self.inner.borrow_mut();
13641367
let (var_infos, data) = inner
1365-
.region_constraints
1368+
.region_constraint_storage
13661369
.take()
13671370
.expect("regions already resolved")
13681371
.with_log(&mut inner.undo_log)

src/librustc_infer/infer/type_variable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,35 @@ use std::ops::Range;
1313

1414
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
1515

16+
/// Represents a single undo-able action that affects a type inference variable.
1617
pub(crate) enum UndoLog<'tcx> {
1718
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
1819
SubRelation(sv::UndoLog<ut::Delegate<ty::TyVid>>),
1920
Values(sv::UndoLog<Delegate>),
2021
}
2122

23+
/// Convert from a specific kind of undo to the more general UndoLog
2224
impl<'tcx> From<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for UndoLog<'tcx> {
2325
fn from(l: sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>) -> Self {
2426
UndoLog::EqRelation(l)
2527
}
2628
}
2729

30+
/// Convert from a specific kind of undo to the more general UndoLog
2831
impl<'tcx> From<sv::UndoLog<ut::Delegate<ty::TyVid>>> for UndoLog<'tcx> {
2932
fn from(l: sv::UndoLog<ut::Delegate<ty::TyVid>>) -> Self {
3033
UndoLog::SubRelation(l)
3134
}
3235
}
3336

37+
/// Convert from a specific kind of undo to the more general UndoLog
3438
impl<'tcx> From<sv::UndoLog<Delegate>> for UndoLog<'tcx> {
3539
fn from(l: sv::UndoLog<Delegate>) -> Self {
3640
UndoLog::Values(l)
3741
}
3842
}
3943

44+
/// Convert from a specific kind of undo to the more general UndoLog
4045
impl<'tcx> From<Instantiate> for UndoLog<'tcx> {
4146
fn from(l: Instantiate) -> Self {
4247
UndoLog::Values(sv::UndoLog::Other(l))

src/librustc_infer/infer/undo_log.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl_from! {
5959
ProjectionCache(traits::UndoLog<'tcx>),
6060
}
6161

62+
/// The Rollback trait defines how to rollback a particular action.
6263
impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
6364
fn reverse(&mut self, undo: UndoLog<'tcx>) {
6465
match undo {
@@ -67,10 +68,10 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
6768
UndoLog::IntUnificationTable(undo) => self.int_unification_storage.reverse(undo),
6869
UndoLog::FloatUnificationTable(undo) => self.float_unification_storage.reverse(undo),
6970
UndoLog::RegionConstraintCollector(undo) => {
70-
self.region_constraints.as_mut().unwrap().reverse(undo)
71+
self.region_constraint_storage.as_mut().unwrap().reverse(undo)
7172
}
7273
UndoLog::RegionUnificationTable(undo) => {
73-
self.region_constraints.as_mut().unwrap().unification_table.reverse(undo)
74+
self.region_constraint_storage.as_mut().unwrap().unification_table.reverse(undo)
7475
}
7576
UndoLog::ProjectionCache(undo) => self.projection_cache.reverse(undo),
7677
UndoLog::PushRegionObligation => {
@@ -80,6 +81,8 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
8081
}
8182
}
8283

84+
/// The combined undo log for all the various unification tables. For each change to the storage
85+
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
8386
pub(crate) struct InferCtxtUndoLogs<'tcx> {
8487
logs: Vec<UndoLog<'tcx>>,
8588
num_open_snapshots: usize,
@@ -91,22 +94,27 @@ impl Default for InferCtxtUndoLogs<'_> {
9194
}
9295
}
9396

97+
/// The UndoLogs trait defines how we undo a particular kind of action (of type T). We can undo any
98+
/// action that is convertable into a UndoLog (per the From impls above).
9499
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>
95100
where
96101
UndoLog<'tcx>: From<T>,
97102
{
98103
fn num_open_snapshots(&self) -> usize {
99104
self.num_open_snapshots
100105
}
106+
101107
fn push(&mut self, undo: T) {
102108
if self.in_snapshot() {
103109
self.logs.push(undo.into())
104110
}
105111
}
112+
106113
fn clear(&mut self) {
107114
self.logs.clear();
108115
self.num_open_snapshots = 0;
109116
}
117+
110118
fn extend<J>(&mut self, undos: J)
111119
where
112120
Self: Sized,
@@ -196,6 +204,7 @@ impl<'tcx> InferCtxtUndoLogs<'tcx> {
196204

197205
impl<'tcx> std::ops::Index<usize> for InferCtxtUndoLogs<'tcx> {
198206
type Output = UndoLog<'tcx>;
207+
199208
fn index(&self, key: usize) -> &Self::Output {
200209
&self.logs[key]
201210
}

0 commit comments

Comments
 (0)