refactor: Rename Logs to InferCtxtUndoLogs

This commit is contained in:
Markus Westerlind 2020-02-25 16:41:29 +01:00
parent e6d7f1584d
commit bc7f7b2d4d
5 changed files with 53 additions and 24 deletions

View File

@ -485,7 +485,7 @@ version = "0.0.212"
dependencies = [
"cargo_metadata 0.9.1",
"if_chain",
"itertools 0.8.0",
"itertools 0.9.0",
"lazy_static 1.4.0",
"pulldown-cmark 0.7.1",
"quine-mc_cluskey",
@ -1629,6 +1629,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "0.4.4"
@ -2179,6 +2188,7 @@ dependencies = [
"rustc-workspace-hack",
"rustc_version",
"serde",
"serde_json",
"shell-escape",
"vergen",
]

View File

@ -147,7 +147,6 @@ pub struct InferCtxtInner<'tcx> {
/// that might instantiate a general type variable have an order,
/// represented by its upper and lower bounds.
type_variables: type_variable::TypeVariableStorage<'tcx>,
undo_log: Logs<'tcx>,
/// Map from const parameter variable to the kind of const it represents.
const_unification_table: ut::UnificationStorage<ty::ConstVid<'tcx>>,
@ -197,6 +196,8 @@ pub struct InferCtxtInner<'tcx> {
/// obligations within. This is expected to be done 'late enough'
/// that all type inference variables have been bound and so forth.
region_obligations: Vec<(hir::HirId, RegionObligation<'tcx>)>,
undo_log: InferCtxtUndoLogs<'tcx>,
}
impl<'tcx> InferCtxtInner<'tcx> {
@ -204,7 +205,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
InferCtxtInner {
projection_cache: Default::default(),
type_variables: type_variable::TypeVariableStorage::new(),
undo_log: Logs::default(),
undo_log: InferCtxtUndoLogs::default(),
const_unification_table: ut::UnificationStorage::new(),
int_unification_table: ut::UnificationStorage::new(),
float_unification_table: ut::UnificationStorage::new(),
@ -228,7 +229,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
fn int_unification_table(
&mut self,
) -> ut::UnificationTable<
ut::InPlace<ty::IntVid, &mut ut::UnificationStorage<ty::IntVid>, &mut Logs<'tcx>>,
ut::InPlace<
ty::IntVid,
&mut ut::UnificationStorage<ty::IntVid>,
&mut InferCtxtUndoLogs<'tcx>,
>,
> {
ut::UnificationTable::with_log(&mut self.int_unification_table, &mut self.undo_log)
}
@ -236,7 +241,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
fn float_unification_table(
&mut self,
) -> ut::UnificationTable<
ut::InPlace<ty::FloatVid, &mut ut::UnificationStorage<ty::FloatVid>, &mut Logs<'tcx>>,
ut::InPlace<
ty::FloatVid,
&mut ut::UnificationStorage<ty::FloatVid>,
&mut InferCtxtUndoLogs<'tcx>,
>,
> {
ut::UnificationTable::with_log(&mut self.float_unification_table, &mut self.undo_log)
}
@ -247,7 +256,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
ut::InPlace<
ty::ConstVid<'tcx>,
&mut ut::UnificationStorage<ty::ConstVid<'tcx>>,
&mut Logs<'tcx>,
&mut InferCtxtUndoLogs<'tcx>,
>,
> {
ut::UnificationTable::with_log(&mut self.const_unification_table, &mut self.undo_log)
@ -343,8 +352,9 @@ impl<'tcx> From<traits::UndoLog<'tcx>> for UndoLog<'tcx> {
}
}
pub(crate) type UnificationTable<'a, 'tcx, T> =
ut::UnificationTable<ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut Logs<'tcx>>>;
pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable<
ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut InferCtxtUndoLogs<'tcx>>,
>;
struct RollbackView<'tcx, 'a> {
type_variables: &'a mut type_variable::TypeVariableStorage<'tcx>,
@ -375,18 +385,18 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
}
}
pub(crate) struct Logs<'tcx> {
pub(crate) struct InferCtxtUndoLogs<'tcx> {
logs: Vec<UndoLog<'tcx>>,
num_open_snapshots: usize,
}
impl Default for Logs<'_> {
impl Default for InferCtxtUndoLogs<'_> {
fn default() -> Self {
Self { logs: Default::default(), num_open_snapshots: Default::default() }
}
}
impl<'tcx, T> UndoLogs<T> for Logs<'tcx>
impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>
where
UndoLog<'tcx>: From<T>,
{
@ -413,7 +423,7 @@ where
}
}
impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
impl<'tcx> Snapshots<UndoLog<'tcx>> for InferCtxtUndoLogs<'tcx> {
type Snapshot = Snapshot<'tcx>;
fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[UndoLog<'tcx>] {
&self.logs[snapshot.undo_len..]
@ -464,7 +474,7 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
}
}
impl<'tcx> Logs<'tcx> {
impl<'tcx> InferCtxtUndoLogs<'tcx> {
pub(crate) fn region_constraints(
&self,
after: usize,

View File

@ -4,7 +4,9 @@ use self::CombineMapType::*;
use self::UndoLog::*;
use super::unify_key;
use super::{Logs, MiscVariable, RegionVariableOrigin, Rollback, Snapshot, SubregionOrigin};
use super::{
InferCtxtUndoLogs, MiscVariable, RegionVariableOrigin, Rollback, Snapshot, SubregionOrigin,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::Lrc;
@ -61,7 +63,7 @@ pub struct RegionConstraintStorage<'tcx> {
pub struct RegionConstraintCollector<'tcx, 'a> {
storage: &'a mut RegionConstraintStorage<'tcx>,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
}
impl std::ops::Deref for RegionConstraintCollector<'tcx, '_> {
@ -346,7 +348,7 @@ impl<'tcx> RegionConstraintStorage<'tcx> {
pub(crate) fn with_log<'a>(
&'a mut self,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
) -> RegionConstraintCollector<'tcx, 'a> {
RegionConstraintCollector { storage: self, undo_log }
}

View File

@ -3,7 +3,7 @@ use rustc_middle::ty::{self, Ty, TyVid};
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use crate::infer::Logs;
use crate::infer::InferCtxtUndoLogs;
use rustc_data_structures::snapshot_vec as sv;
use rustc_data_structures::unify as ut;
@ -88,7 +88,7 @@ pub struct TypeVariableTable<'tcx, 'a> {
sub_relations: &'a mut ut::UnificationStorage<ty::TyVid>,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
}
#[derive(Copy, Clone, Debug)]
@ -167,7 +167,7 @@ impl<'tcx> TypeVariableStorage<'tcx> {
pub(crate) fn with_log<'a>(
&'a mut self,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
) -> TypeVariableTable<'tcx, 'a> {
let TypeVariableStorage { values, eq_relations, sub_relations } = self;
TypeVariableTable { values, eq_relations, sub_relations, undo_log }
@ -327,7 +327,9 @@ impl<'tcx> TypeVariableTable<'tcx, '_> {
Snapshot { value_count: self.eq_relations().len() as u32, _marker: PhantomData }
}
fn values(&mut self) -> sv::SnapshotVec<Delegate, &mut Vec<TypeVariableData>, &mut Logs<'tcx>> {
fn values(
&mut self,
) -> sv::SnapshotVec<Delegate, &mut Vec<TypeVariableData>, &mut InferCtxtUndoLogs<'tcx>> {
sv::SnapshotVec::with_log(self.values, self.undo_log)
}

View File

@ -2,7 +2,7 @@
use super::PredicateObligation;
use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap};
use rustc_data_structures::snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, Ty};
@ -63,7 +63,7 @@ impl<'tcx, T> Normalized<'tcx, T> {
// reduce the amount of duplication. Let's see what we get with the Chalk reforms.
pub struct ProjectionCache<'tcx, 'a> {
map: &'a mut SnapshotMapStorage<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
}
#[derive(Default)]
@ -93,7 +93,7 @@ pub enum ProjectionCacheEntry<'tcx> {
impl<'tcx> ProjectionCacheStorage<'tcx> {
pub(crate) fn with_log<'a>(
&'a mut self,
undo_log: &'a mut Logs<'tcx>,
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
) -> ProjectionCache<'tcx, 'a> {
ProjectionCache { map: &mut self.map, undo_log }
}
@ -102,7 +102,12 @@ impl<'tcx> ProjectionCacheStorage<'tcx> {
impl<'tcx> ProjectionCache<'tcx, '_> {
fn map(
&mut self,
) -> SnapshotMapRef<'_, ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>, Logs<'tcx>> {
) -> SnapshotMapRef<
'_,
ProjectionCacheKey<'tcx>,
ProjectionCacheEntry<'tcx>,
InferCtxtUndoLogs<'tcx>,
> {
self.map.with_log(self.undo_log)
}