Call the method fork instead of clone and add proper comments
This commit is contained in:
parent
3fd89a662a
commit
f4bb4500dd
9 changed files with 36 additions and 3 deletions
|
@ -13,6 +13,7 @@ mod tests;
|
||||||
pub type SnapshotMapStorage<K, V> = SnapshotMap<K, V, FxHashMap<K, V>, ()>;
|
pub type SnapshotMapStorage<K, V> = SnapshotMap<K, V, FxHashMap<K, V>, ()>;
|
||||||
pub type SnapshotMapRef<'a, K, V, L> = SnapshotMap<K, V, &'a mut FxHashMap<K, V>, &'a mut L>;
|
pub type SnapshotMapRef<'a, K, V, L> = SnapshotMap<K, V, &'a mut FxHashMap<K, V>, &'a mut L>;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct SnapshotMap<K, V, M = FxHashMap<K, V>, L = VecLog<UndoLog<K, V>>> {
|
pub struct SnapshotMap<K, V, M = FxHashMap<K, V>, L = VecLog<UndoLog<K, V>>> {
|
||||||
map: M,
|
map: M,
|
||||||
undo_log: L,
|
undo_log: L,
|
||||||
|
@ -30,6 +31,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub enum UndoLog<K, V> {
|
pub enum UndoLog<K, V> {
|
||||||
Inserted(K),
|
Inserted(K),
|
||||||
Overwrite(K, V),
|
Overwrite(K, V),
|
||||||
|
|
|
@ -51,6 +51,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
) -> At<'a, 'tcx> {
|
) -> At<'a, 'tcx> {
|
||||||
At { infcx: self, cause, param_env }
|
At { infcx: self, cause, param_env }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Forks the inference context, creating a new inference context with the same inference
|
||||||
|
/// variables in the same state. This can be used to "branch off" many tests from the same
|
||||||
|
/// common state. Used in coherence.
|
||||||
|
pub fn fork(&self) -> Self {
|
||||||
|
Self {
|
||||||
|
tcx: self.tcx.clone(),
|
||||||
|
defining_use_anchor: self.defining_use_anchor.clone(),
|
||||||
|
reveal_defining_opaque_types: self.reveal_defining_opaque_types,
|
||||||
|
in_progress_typeck_results: self.in_progress_typeck_results.clone(),
|
||||||
|
inner: self.inner.clone(),
|
||||||
|
skip_leak_check: self.skip_leak_check.clone(),
|
||||||
|
lexical_region_resolutions: self.lexical_region_resolutions.clone(),
|
||||||
|
selection_cache: self.selection_cache.clone(),
|
||||||
|
evaluation_cache: self.evaluation_cache.clone(),
|
||||||
|
reported_trait_errors: self.reported_trait_errors.clone(),
|
||||||
|
reported_closure_mismatch: self.reported_closure_mismatch.clone(),
|
||||||
|
tainted_by_errors_flag: self.tainted_by_errors_flag.clone(),
|
||||||
|
err_count_on_creation: self.err_count_on_creation,
|
||||||
|
in_snapshot: self.in_snapshot.clone(),
|
||||||
|
universe: self.universe.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
|
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
|
||||||
|
|
|
@ -61,6 +61,7 @@ pub(crate) fn resolve<'tcx>(
|
||||||
|
|
||||||
/// Contains the result of lexical region resolution. Offers methods
|
/// Contains the result of lexical region resolution. Offers methods
|
||||||
/// to lookup up the final value of a region variable.
|
/// to lookup up the final value of a region variable.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct LexicalRegionResolutions<'tcx> {
|
pub struct LexicalRegionResolutions<'tcx> {
|
||||||
values: IndexVec<RegionVid, VarValue<'tcx>>,
|
values: IndexVec<RegionVid, VarValue<'tcx>>,
|
||||||
error_region: ty::Region<'tcx>,
|
error_region: ty::Region<'tcx>,
|
||||||
|
|
|
@ -130,6 +130,7 @@ impl RegionckMode {
|
||||||
/// `RefCell` and are involved with taking/rolling back snapshots. Snapshot
|
/// `RefCell` and are involved with taking/rolling back snapshots. Snapshot
|
||||||
/// operations are hot enough that we want only one call to `borrow_mut` per
|
/// operations are hot enough that we want only one call to `borrow_mut` per
|
||||||
/// call to `start_snapshot` and `rollback_to`.
|
/// call to `start_snapshot` and `rollback_to`.
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct InferCtxtInner<'tcx> {
|
pub struct InferCtxtInner<'tcx> {
|
||||||
/// Cache for projections. This cache is snapshotted along with the infcx.
|
/// Cache for projections. This cache is snapshotted along with the infcx.
|
||||||
///
|
///
|
||||||
|
|
|
@ -28,7 +28,7 @@ mod leak_check;
|
||||||
|
|
||||||
pub use rustc_middle::infer::MemberConstraint;
|
pub use rustc_middle::infer::MemberConstraint;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct RegionConstraintStorage<'tcx> {
|
pub struct RegionConstraintStorage<'tcx> {
|
||||||
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
|
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
|
||||||
var_infos: IndexVec<RegionVid, RegionVariableInfo>,
|
var_infos: IndexVec<RegionVid, RegionVariableInfo>,
|
||||||
|
|
|
@ -14,6 +14,7 @@ use std::ops::Range;
|
||||||
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
|
||||||
|
|
||||||
/// Represents a single undo-able action that affects a type inference variable.
|
/// Represents a single undo-able action that affects a type inference variable.
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) enum UndoLog<'tcx> {
|
pub(crate) enum UndoLog<'tcx> {
|
||||||
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
|
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
|
||||||
SubRelation(sv::UndoLog<ut::Delegate<ty::TyVid>>),
|
SubRelation(sv::UndoLog<ut::Delegate<ty::TyVid>>),
|
||||||
|
@ -58,6 +59,7 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct TypeVariableStorage<'tcx> {
|
pub struct TypeVariableStorage<'tcx> {
|
||||||
values: sv::SnapshotVecStorage<Delegate>,
|
values: sv::SnapshotVecStorage<Delegate>,
|
||||||
|
|
||||||
|
@ -137,6 +139,7 @@ pub enum TypeVariableOriginKind {
|
||||||
LatticeVariable,
|
LatticeVariable,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct TypeVariableData {
|
pub(crate) struct TypeVariableData {
|
||||||
origin: TypeVariableOrigin,
|
origin: TypeVariableOrigin,
|
||||||
}
|
}
|
||||||
|
@ -165,6 +168,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct Instantiate;
|
pub(crate) struct Instantiate;
|
||||||
|
|
||||||
pub(crate) struct Delegate;
|
pub(crate) struct Delegate;
|
||||||
|
|
|
@ -17,6 +17,7 @@ pub struct Snapshot<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Records the "undo" data for a single operation that affects some form of inference variable.
|
/// Records the "undo" data for a single operation that affects some form of inference variable.
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) enum UndoLog<'tcx> {
|
pub(crate) enum UndoLog<'tcx> {
|
||||||
TypeVariables(type_variable::UndoLog<'tcx>),
|
TypeVariables(type_variable::UndoLog<'tcx>),
|
||||||
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
|
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
|
||||||
|
@ -84,6 +85,7 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
|
||||||
|
|
||||||
/// The combined undo log for all the various unification tables. For each change to the storage
|
/// The combined undo log for all the various unification tables. For each change to the storage
|
||||||
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
|
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct InferCtxtUndoLogs<'tcx> {
|
pub(crate) struct InferCtxtUndoLogs<'tcx> {
|
||||||
logs: Vec<UndoLog<'tcx>>,
|
logs: Vec<UndoLog<'tcx>>,
|
||||||
num_open_snapshots: usize,
|
num_open_snapshots: usize,
|
||||||
|
|
|
@ -70,7 +70,7 @@ pub struct ProjectionCache<'a, 'tcx> {
|
||||||
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
|
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct ProjectionCacheStorage<'tcx> {
|
pub struct ProjectionCacheStorage<'tcx> {
|
||||||
map: SnapshotMapStorage<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>,
|
map: SnapshotMapStorage<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,7 +379,7 @@ fn negative_impl_exists<'cx, 'tcx>(
|
||||||
region_context: DefId,
|
region_context: DefId,
|
||||||
o: &PredicateObligation<'tcx>,
|
o: &PredicateObligation<'tcx>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let infcx = selcx.infcx().clone();
|
let infcx = &selcx.infcx().fork();
|
||||||
let tcx = infcx.tcx;
|
let tcx = infcx.tcx;
|
||||||
o.flip_polarity(tcx)
|
o.flip_polarity(tcx)
|
||||||
.map(|o| {
|
.map(|o| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue