Call the method fork instead of clone and add proper comments

This commit is contained in:
Santiago Pastorino 2022-02-09 19:37:10 -03:00
parent 3fd89a662a
commit f4bb4500dd
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
9 changed files with 36 additions and 3 deletions

View File

@ -13,6 +13,7 @@
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>;
#[derive(Clone)]
pub struct SnapshotMap<K, V, M = FxHashMap<K, V>, L = VecLog<UndoLog<K, V>>> {
map: M,
undo_log: L,
@ -30,6 +31,7 @@ fn default() -> Self {
}
}
#[derive(Clone)]
pub enum UndoLog<K, V> {
Inserted(K),
Overwrite(K, V),

View File

@ -51,6 +51,29 @@ pub fn at(
) -> At<'a, 'tcx> {
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 {

View File

@ -61,6 +61,7 @@ pub(crate) fn resolve<'tcx>(
/// Contains the result of lexical region resolution. Offers methods
/// to lookup up the final value of a region variable.
#[derive(Clone)]
pub struct LexicalRegionResolutions<'tcx> {
values: IndexVec<RegionVid, VarValue<'tcx>>,
error_region: ty::Region<'tcx>,

View File

@ -130,6 +130,7 @@ pub fn for_item_body(tcx: TyCtxt<'_>) -> Self {
/// `RefCell` and are involved with taking/rolling back snapshots. Snapshot
/// operations are hot enough that we want only one call to `borrow_mut` per
/// call to `start_snapshot` and `rollback_to`.
#[derive(Clone)]
pub struct InferCtxtInner<'tcx> {
/// Cache for projections. This cache is snapshotted along with the infcx.
///

View File

@ -28,7 +28,7 @@
pub use rustc_middle::infer::MemberConstraint;
#[derive(Default)]
#[derive(Clone, Default)]
pub struct RegionConstraintStorage<'tcx> {
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
var_infos: IndexVec<RegionVid, RegionVariableInfo>,

View File

@ -14,6 +14,7 @@
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
/// Represents a single undo-able action that affects a type inference variable.
#[derive(Clone)]
pub(crate) enum UndoLog<'tcx> {
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
SubRelation(sv::UndoLog<ut::Delegate<ty::TyVid>>),
@ -58,6 +59,7 @@ fn reverse(&mut self, undo: UndoLog<'tcx>) {
}
}
#[derive(Clone)]
pub struct TypeVariableStorage<'tcx> {
values: sv::SnapshotVecStorage<Delegate>,
@ -137,6 +139,7 @@ pub enum TypeVariableOriginKind {
LatticeVariable,
}
#[derive(Clone)]
pub(crate) struct TypeVariableData {
origin: TypeVariableOrigin,
}
@ -165,6 +168,7 @@ pub fn is_unknown(&self) -> bool {
}
}
#[derive(Clone)]
pub(crate) struct Instantiate;
pub(crate) struct Delegate;

View File

@ -17,6 +17,7 @@ pub struct Snapshot<'tcx> {
}
/// Records the "undo" data for a single operation that affects some form of inference variable.
#[derive(Clone)]
pub(crate) enum UndoLog<'tcx> {
TypeVariables(type_variable::UndoLog<'tcx>),
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
@ -84,6 +85,7 @@ fn reverse(&mut self, undo: UndoLog<'tcx>) {
/// 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.
#[derive(Clone)]
pub(crate) struct InferCtxtUndoLogs<'tcx> {
logs: Vec<UndoLog<'tcx>>,
num_open_snapshots: usize,

View File

@ -70,7 +70,7 @@ pub struct ProjectionCache<'a, 'tcx> {
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
}
#[derive(Default)]
#[derive(Clone, Default)]
pub struct ProjectionCacheStorage<'tcx> {
map: SnapshotMapStorage<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>,
}

View File

@ -379,7 +379,7 @@ fn negative_impl_exists<'cx, 'tcx>(
region_context: DefId,
o: &PredicateObligation<'tcx>,
) -> bool {
let infcx = selcx.infcx().clone();
let infcx = &selcx.infcx().fork();
let tcx = infcx.tcx;
o.flip_polarity(tcx)
.map(|o| {