diff --git a/Cargo.lock b/Cargo.lock index c5e25b0a2c7..45c298ea8bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index a2cf772e86e..90bc1ddc3eb 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -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>, @@ -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, &mut Logs<'tcx>>, + ut::InPlace< + ty::IntVid, + &mut ut::UnificationStorage, + &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, &mut Logs<'tcx>>, + ut::InPlace< + ty::FloatVid, + &mut ut::UnificationStorage, + &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>, - &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> for UndoLog<'tcx> { } } -pub(crate) type UnificationTable<'a, 'tcx, T> = - ut::UnificationTable, &'a mut Logs<'tcx>>>; +pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable< + ut::InPlace, &'a mut InferCtxtUndoLogs<'tcx>>, +>; struct RollbackView<'tcx, 'a> { type_variables: &'a mut type_variable::TypeVariableStorage<'tcx>, @@ -375,18 +385,18 @@ impl<'tcx> Rollback> for RollbackView<'tcx, '_> { } } -pub(crate) struct Logs<'tcx> { +pub(crate) struct InferCtxtUndoLogs<'tcx> { logs: Vec>, 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 for Logs<'tcx> +impl<'tcx, T> UndoLogs for InferCtxtUndoLogs<'tcx> where UndoLog<'tcx>: From, { @@ -413,7 +423,7 @@ where } } -impl<'tcx> Snapshots> for Logs<'tcx> { +impl<'tcx> Snapshots> 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> for Logs<'tcx> { } } -impl<'tcx> Logs<'tcx> { +impl<'tcx> InferCtxtUndoLogs<'tcx> { pub(crate) fn region_constraints( &self, after: usize, diff --git a/src/librustc_infer/infer/region_constraints/mod.rs b/src/librustc_infer/infer/region_constraints/mod.rs index 7b660ce4365..5f6f82ddaf9 100644 --- a/src/librustc_infer/infer/region_constraints/mod.rs +++ b/src/librustc_infer/infer/region_constraints/mod.rs @@ -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 } } diff --git a/src/librustc_infer/infer/type_variable.rs b/src/librustc_infer/infer/type_variable.rs index 26673cff1e8..69afb605b34 100644 --- a/src/librustc_infer/infer/type_variable.rs +++ b/src/librustc_infer/infer/type_variable.rs @@ -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, - 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, &mut Logs<'tcx>> { + fn values( + &mut self, + ) -> sv::SnapshotVec, &mut InferCtxtUndoLogs<'tcx>> { sv::SnapshotVec::with_log(self.values, self.undo_log) } diff --git a/src/librustc_infer/traits/project.rs b/src/librustc_infer/traits/project.rs index 0c51dafef6f..8cf3987b902 100644 --- a/src/librustc_infer/traits/project.rs +++ b/src/librustc_infer/traits/project.rs @@ -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, 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) }