Skip to content

Commit f4bb450

Browse files
committed
Call the method fork instead of clone and add proper comments
1 parent 3fd89a6 commit f4bb450

File tree

9 files changed

+36
-3
lines changed

9 files changed

+36
-3
lines changed

compiler/rustc_data_structures/src/snapshot_map/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ mod tests;
1313
pub type SnapshotMapStorage<K, V> = SnapshotMap<K, V, FxHashMap<K, V>, ()>;
1414
pub type SnapshotMapRef<'a, K, V, L> = SnapshotMap<K, V, &'a mut FxHashMap<K, V>, &'a mut L>;
1515

16+
#[derive(Clone)]
1617
pub struct SnapshotMap<K, V, M = FxHashMap<K, V>, L = VecLog<UndoLog<K, V>>> {
1718
map: M,
1819
undo_log: L,
@@ -30,6 +31,7 @@ where
3031
}
3132
}
3233

34+
#[derive(Clone)]
3335
pub enum UndoLog<K, V> {
3436
Inserted(K),
3537
Overwrite(K, V),

compiler/rustc_infer/src/infer/at.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5151
) -> At<'a, 'tcx> {
5252
At { infcx: self, cause, param_env }
5353
}
54+
55+
/// Forks the inference context, creating a new inference context with the same inference
56+
/// variables in the same state. This can be used to "branch off" many tests from the same
57+
/// common state. Used in coherence.
58+
pub fn fork(&self) -> Self {
59+
Self {
60+
tcx: self.tcx.clone(),
61+
defining_use_anchor: self.defining_use_anchor.clone(),
62+
reveal_defining_opaque_types: self.reveal_defining_opaque_types,
63+
in_progress_typeck_results: self.in_progress_typeck_results.clone(),
64+
inner: self.inner.clone(),
65+
skip_leak_check: self.skip_leak_check.clone(),
66+
lexical_region_resolutions: self.lexical_region_resolutions.clone(),
67+
selection_cache: self.selection_cache.clone(),
68+
evaluation_cache: self.evaluation_cache.clone(),
69+
reported_trait_errors: self.reported_trait_errors.clone(),
70+
reported_closure_mismatch: self.reported_closure_mismatch.clone(),
71+
tainted_by_errors_flag: self.tainted_by_errors_flag.clone(),
72+
err_count_on_creation: self.err_count_on_creation,
73+
in_snapshot: self.in_snapshot.clone(),
74+
universe: self.universe.clone(),
75+
}
76+
}
5477
}
5578

5679
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ pub(crate) fn resolve<'tcx>(
6161

6262
/// Contains the result of lexical region resolution. Offers methods
6363
/// to lookup up the final value of a region variable.
64+
#[derive(Clone)]
6465
pub struct LexicalRegionResolutions<'tcx> {
6566
values: IndexVec<RegionVid, VarValue<'tcx>>,
6667
error_region: ty::Region<'tcx>,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ impl RegionckMode {
130130
/// `RefCell` and are involved with taking/rolling back snapshots. Snapshot
131131
/// operations are hot enough that we want only one call to `borrow_mut` per
132132
/// call to `start_snapshot` and `rollback_to`.
133+
#[derive(Clone)]
133134
pub struct InferCtxtInner<'tcx> {
134135
/// Cache for projections. This cache is snapshotted along with the infcx.
135136
///

compiler/rustc_infer/src/infer/region_constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod leak_check;
2828

2929
pub use rustc_middle::infer::MemberConstraint;
3030

31-
#[derive(Default)]
31+
#[derive(Clone, Default)]
3232
pub struct RegionConstraintStorage<'tcx> {
3333
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
3434
var_infos: IndexVec<RegionVid, RegionVariableInfo>,

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ops::Range;
1414
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
1515

1616
/// Represents a single undo-able action that affects a type inference variable.
17+
#[derive(Clone)]
1718
pub(crate) enum UndoLog<'tcx> {
1819
EqRelation(sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>),
1920
SubRelation(sv::UndoLog<ut::Delegate<ty::TyVid>>),
@@ -58,6 +59,7 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
5859
}
5960
}
6061

62+
#[derive(Clone)]
6163
pub struct TypeVariableStorage<'tcx> {
6264
values: sv::SnapshotVecStorage<Delegate>,
6365

@@ -137,6 +139,7 @@ pub enum TypeVariableOriginKind {
137139
LatticeVariable,
138140
}
139141

142+
#[derive(Clone)]
140143
pub(crate) struct TypeVariableData {
141144
origin: TypeVariableOrigin,
142145
}
@@ -165,6 +168,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
165168
}
166169
}
167170

171+
#[derive(Clone)]
168172
pub(crate) struct Instantiate;
169173

170174
pub(crate) struct Delegate;

compiler/rustc_infer/src/infer/undo_log.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Snapshot<'tcx> {
1717
}
1818

1919
/// Records the "undo" data for a single operation that affects some form of inference variable.
20+
#[derive(Clone)]
2021
pub(crate) enum UndoLog<'tcx> {
2122
TypeVariables(type_variable::UndoLog<'tcx>),
2223
ConstUnificationTable(sv::UndoLog<ut::Delegate<ty::ConstVid<'tcx>>>),
@@ -84,6 +85,7 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for InferCtxtInner<'tcx> {
8485

8586
/// The combined undo log for all the various unification tables. For each change to the storage
8687
/// for any kind of inference variable, we record an UndoLog entry in the vector here.
88+
#[derive(Clone)]
8789
pub(crate) struct InferCtxtUndoLogs<'tcx> {
8890
logs: Vec<UndoLog<'tcx>>,
8991
num_open_snapshots: usize,

compiler/rustc_infer/src/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct ProjectionCache<'a, 'tcx> {
7070
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
7171
}
7272

73-
#[derive(Default)]
73+
#[derive(Clone, Default)]
7474
pub struct ProjectionCacheStorage<'tcx> {
7575
map: SnapshotMapStorage<ProjectionCacheKey<'tcx>, ProjectionCacheEntry<'tcx>>,
7676
}

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ fn negative_impl_exists<'cx, 'tcx>(
379379
region_context: DefId,
380380
o: &PredicateObligation<'tcx>,
381381
) -> bool {
382-
let infcx = selcx.infcx().clone();
382+
let infcx = &selcx.infcx().fork();
383383
let tcx = infcx.tcx;
384384
o.flip_polarity(tcx)
385385
.map(|o| {

0 commit comments

Comments
 (0)