diff options
| author | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-04-28 20:46:02 +0200 |
|---|---|---|
| committer | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-05-05 11:25:12 +0200 |
| commit | 4a2a6bcfb1b014587daa543a9aa618502750e489 (patch) | |
| tree | 5b4b86f7827fcbaba11d9b912e12d8fbc8b52013 /src | |
| parent | 6f495f3466f510ac3db45fc3057b96efed971b7f (diff) | |
refactor: Move probe_fudge into fudge.rs
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_infer/infer/fudge.rs | 42 | ||||
| -rw-r--r-- | src/librustc_infer/infer/mod.rs | 41 |
2 files changed, 41 insertions, 42 deletions
diff --git a/src/librustc_infer/infer/fudge.rs b/src/librustc_infer/infer/fudge.rs index 53fd70a28e8..abe952d60f1 100644 --- a/src/librustc_infer/infer/fudge.rs +++ b/src/librustc_infer/infer/fudge.rs @@ -1,9 +1,10 @@ use rustc_middle::ty::fold::{TypeFoldable, TypeFolder}; use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid}; -use super::type_variable::TypeVariableOrigin; +use super::region_constraints::RegionSnapshot; +use super::type_variable::{self, TypeVariableOrigin}; use super::InferCtxt; -use super::{ConstVariableOrigin, RegionVariableOrigin, UnificationTable}; +use super::{CombinedSnapshot, ConstVariableOrigin, RegionVariableOrigin, UnificationTable}; use rustc_data_structures::snapshot_vec as sv; use rustc_data_structures::unify as ut; @@ -35,7 +36,44 @@ fn const_vars_since_snapshot<'tcx>( ) } +/// Extends `CombinedSnapshot` by tracking which variables were added in the snapshot +#[must_use = "once you start a snapshot, you should always consume it"] +struct FudgeSnapshot<'a, 'tcx> { + snapshot: CombinedSnapshot<'a, 'tcx>, + region_constraints_snapshot: RegionSnapshot, + type_snapshot: type_variable::Snapshot<'tcx>, + const_var_len: usize, + int_var_len: usize, + float_var_len: usize, +} + impl<'a, 'tcx> InferCtxt<'a, 'tcx> { + /// Like `probe` but provides information about which variables were created in the snapshot, + /// allowing for inference fudging + fn probe_fudge<R, F>(&self, f: F) -> R + where + F: FnOnce(&FudgeSnapshot<'a, 'tcx>) -> R, + { + debug!("probe()"); + let snapshot = self.start_fudge_snapshot(); + let r = f(&snapshot); + self.rollback_to("probe", snapshot.snapshot); + r + } + + fn start_fudge_snapshot(&self) -> FudgeSnapshot<'a, 'tcx> { + let snapshot = self.start_snapshot(); + let mut inner = self.inner.borrow_mut(); + FudgeSnapshot { + snapshot, + type_snapshot: inner.type_variables().snapshot(), + const_var_len: inner.const_unification_table().len(), + int_var_len: inner.int_unification_table().len(), + float_var_len: inner.float_unification_table().len(), + region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(), + } + } + /// This rather funky routine is used while processing expected /// types. What happens here is that we want to propagate a /// coercion through the return type of a fn to its diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index e92008c68eb..679118d7698 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -45,9 +45,7 @@ use self::free_regions::RegionRelations; use self::lexical_region_resolve::LexicalRegionResolutions; use self::outlives::env::OutlivesEnvironment; use self::region_constraints::{GenericKind, RegionConstraintData, VarInfos, VerifyBound}; -use self::region_constraints::{ - RegionConstraintCollector, RegionConstraintStorage, RegionSnapshot, -}; +use self::region_constraints::{RegionConstraintCollector, RegionConstraintStorage}; use self::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; pub mod at; @@ -705,17 +703,6 @@ impl<'tcx> InferOk<'tcx, ()> { } } -/// Extends `CombinedSnapshot` by tracking which variables were added in the snapshot -#[must_use = "once you start a snapshot, you should always consume it"] -pub struct FudgeSnapshot<'a, 'tcx> { - snapshot: CombinedSnapshot<'a, 'tcx>, - region_constraints_snapshot: RegionSnapshot, - type_snapshot: type_variable::Snapshot<'tcx>, - const_var_len: usize, - int_var_len: usize, - float_var_len: usize, -} - #[must_use = "once you start a snapshot, you should always consume it"] pub struct CombinedSnapshot<'a, 'tcx> { undo_snapshot: Snapshot<'tcx>, @@ -831,19 +818,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { result } - fn start_fudge_snapshot(&self) -> FudgeSnapshot<'a, 'tcx> { - let snapshot = self.start_snapshot(); - let mut inner = self.inner.borrow_mut(); - FudgeSnapshot { - snapshot, - type_snapshot: inner.type_variables().snapshot(), - const_var_len: inner.const_unification_table().len(), - int_var_len: inner.int_unification_table().len(), - float_var_len: inner.float_unification_table().len(), - region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(), - } - } - fn start_snapshot(&self) -> CombinedSnapshot<'a, 'tcx> { debug!("start_snapshot()"); @@ -926,19 +900,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { r } - /// Like `probe` but provides information about which variables were created in the snapshot, - /// allowing for inference fudging - pub fn probe_fudge<R, F>(&self, f: F) -> R - where - F: FnOnce(&FudgeSnapshot<'a, 'tcx>) -> R, - { - debug!("probe()"); - let snapshot = self.start_fudge_snapshot(); - let r = f(&snapshot); - self.rollback_to("probe", snapshot.snapshot); - r - } - /// If `should_skip` is true, then execute `f` then unroll any bindings it creates. pub fn probe_maybe_skip_leak_check<R, F>(&self, should_skip: bool, f: F) -> R where |
