diff options
| author | varkor <github@varkor.com> | 2019-03-21 12:37:31 +0000 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-03-27 09:44:55 +0000 |
| commit | abf5e816636428454262b907d64e6d8cb45dc387 (patch) | |
| tree | e39a5567517cedacf295c20023d105eb9f3df59f /src | |
| parent | a5c653be6389c5d62368ed07c60f064b6f1c037e (diff) | |
| download | rust-abf5e816636428454262b907d64e6d8cb45dc387.tar.gz rust-abf5e816636428454262b907d64e6d8cb45dc387.zip | |
Use Ranges for vars_since_snapshot
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/infer/fudge.rs | 59 | ||||
| -rw-r--r-- | src/librustc/infer/region_constraints/mod.rs | 5 | ||||
| -rw-r--r-- | src/librustc/infer/type_variable.rs | 12 | ||||
| -rw-r--r-- | src/librustc/lib.rs | 1 |
4 files changed, 38 insertions, 39 deletions
diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index 4dc4341d4c8..d8107e64d28 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -1,10 +1,11 @@ -use crate::infer::type_variable::TypeVariableMap; -use crate::ty::{self, Ty, TyCtxt}; +use crate::ty::{self, Ty, TyCtxt, TyVid, RegionVid}; use crate::ty::fold::{TypeFoldable, TypeFolder}; use super::InferCtxt; use super::RegionVariableOrigin; +use std::ops::Range; + impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// This rather funky routine is used while processing expected /// types. What happens here is that we want to propagate a @@ -42,12 +43,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// regions in question are not particularly important. We will /// use the expected types to guide coercions, but we will still /// type-check the resulting types from those coercions against - /// the actual types (`?T`, `Option<?T`) -- and remember that + /// the actual types (`?T`, `Option<?T>`) -- and remember that /// after the snapshot is popped, the variable `?T` is no longer /// unified. - pub fn fudge_regions_if_ok<T, E, F>(&self, - origin: &RegionVariableOrigin, - f: F) -> Result<T, E> where + pub fn fudge_regions_if_ok<T, E, F>( + &self, + origin: &RegionVariableOrigin, + f: F, + ) -> Result<T, E> where F: FnOnce() -> Result<T, E>, T: TypeFoldable<'tcx>, { @@ -101,8 +104,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { pub struct RegionFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - type_variables: &'a TypeVariableMap, - region_vars: &'a Vec<ty::RegionVid>, + type_variables: &'a Range<TyVid>, + region_vars: &'a Range<RegionVid>, origin: &'a RegionVariableOrigin, } @@ -114,25 +117,21 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { match ty.sty { ty::Infer(ty::InferTy::TyVar(vid)) => { - match self.type_variables.get(&vid) { - None => { - // This variable was created before the - // "fudging". Since we refresh all type - // variables to their binding anyhow, we know - // that it is unbound, so we can just return - // it. - debug_assert!(self.infcx.type_variables.borrow_mut() - .probe(vid) - .is_unknown()); - ty - } - - Some(&origin) => { - // This variable was created during the - // fudging. Recreate it with a fresh variable - // here. - self.infcx.next_ty_var(origin) - } + if self.type_variables.contains(&vid) { + // This variable was created during the fudging. + // Recreate it with a fresh variable here. + let origin = self.infcx.type_variables.borrow().var_origin(vid).clone(); + self.infcx.next_ty_var(origin) + } else { + // This variable was created before the + // "fudging". Since we refresh all type + // variables to their binding anyhow, we know + // that it is unbound, so we can just return + // it. + debug_assert!(self.infcx.type_variables.borrow_mut() + .probe(vid) + .is_unknown()); + ty } } _ => ty.super_fold_with(self), @@ -141,12 +140,10 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionFudger<'a, 'gcx, 'tcx> { fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { match *r { - ty::ReVar(v) if self.region_vars.contains(&v) => { + ty::ReVar(vid) if self.region_vars.contains(&vid) => { self.infcx.next_region_var(self.origin.clone()) } - _ => { - r - } + _ => r, } } } diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index c0d118eed86..51d8a0edc81 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -16,6 +16,7 @@ use crate::ty::{Region, RegionVid}; use std::collections::BTreeMap; use std::{cmp, fmt, mem, u32}; +use std::ops::Range; mod leak_check; @@ -840,8 +841,8 @@ impl<'tcx> RegionConstraintCollector<'tcx> { } } - pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Vec<RegionVid> { - self.unification_table.vars_since_snapshot(&mark.region_snapshot).collect() + pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> { + self.unification_table.vars_since_snapshot(&mark.region_snapshot) } /// See [`RegionInference::region_constraints_added_in_snapshot`]. diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs index 422dd24eb0b..a5b2e591f91 100644 --- a/src/librustc/infer/type_variable.rs +++ b/src/librustc/infer/type_variable.rs @@ -1,13 +1,15 @@ use syntax::symbol::InternedString; use syntax_pos::Span; -use crate::ty::{self, Ty}; +use crate::ty::{self, Ty, TyVid}; use std::cmp; use std::marker::PhantomData; +use std::ops::Range; use std::u32; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::snapshot_vec as sv; use rustc_data_structures::unify as ut; +use ut::UnifyKey; pub struct TypeVariableTable<'tcx> { values: sv::SnapshotVec<Delegate>, @@ -294,11 +296,9 @@ impl<'tcx> TypeVariableTable<'tcx> { /// Returns a map from the type variables created during the /// snapshot to the origin of the type variable. - pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> TypeVariableMap { - self.values.values_since_snapshot(&s.snapshot).map(|idx| { - let origin = self.values.get(idx).origin.clone(); - (ty::TyVid { index: idx as u32 }, origin) - }).collect() + pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range<TyVid> { + let range = self.values.values_since_snapshot(&s.snapshot); + TyVid::from_index(range.start as u32)..TyVid::from_index(range.end as u32) } /// Finds the set of type variables that existed *before* `s` diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 4b2fda3b02f..e905c368851 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -44,6 +44,7 @@ #![feature(non_exhaustive)] #![feature(proc_macro_internals)] #![feature(optin_builtin_traits)] +#![feature(range_is_empty)] #![feature(refcell_replace_swap)] #![feature(rustc_diagnostic_macros)] #![feature(rustc_attrs)] |
