From a80bff87c19cf91deafefc8fdaace71f77727258 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 5 Jan 2020 19:43:25 +0100 Subject: Move normalize_erasing_regions to rustc::ty. --- src/librustc/traits/query/mod.rs | 1 - .../traits/query/normalize_erasing_regions.rs | 78 ---------------------- src/librustc/ty/mod.rs | 1 + src/librustc/ty/normalize_erasing_regions.rs | 78 ++++++++++++++++++++++ 4 files changed, 79 insertions(+), 79 deletions(-) delete mode 100644 src/librustc/traits/query/normalize_erasing_regions.rs create mode 100644 src/librustc/ty/normalize_erasing_regions.rs (limited to 'src') diff --git a/src/librustc/traits/query/mod.rs b/src/librustc/traits/query/mod.rs index fb9f46011b9..440268aab8f 100644 --- a/src/librustc/traits/query/mod.rs +++ b/src/librustc/traits/query/mod.rs @@ -13,7 +13,6 @@ pub mod dropck_outlives; pub mod evaluate_obligation; pub mod method_autoderef; pub mod normalize; -pub mod normalize_erasing_regions; pub mod outlives_bounds; pub mod type_op; diff --git a/src/librustc/traits/query/normalize_erasing_regions.rs b/src/librustc/traits/query/normalize_erasing_regions.rs deleted file mode 100644 index 2fa52e8810b..00000000000 --- a/src/librustc/traits/query/normalize_erasing_regions.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Methods for normalizing when you don't care about regions (and -//! aren't doing type inference). If either of those things don't -//! apply to you, use `infcx.normalize(...)`. -//! -//! The methods in this file use a `TypeFolder` to recursively process -//! contents, invoking the underlying -//! `normalize_ty_after_erasing_regions` query for each type found -//! within. (This underlying query is what is cached.) - -use crate::ty::fold::{TypeFoldable, TypeFolder}; -use crate::ty::{self, Ty, TyCtxt}; - -impl<'tcx> TyCtxt<'tcx> { - /// Erase the regions in `value` and then fully normalize all the - /// types found within. The result will also have regions erased. - /// - /// This is appropriate to use only after type-check: it assumes - /// that normalization will succeed, for example. - pub fn normalize_erasing_regions(self, param_env: ty::ParamEnv<'tcx>, value: T) -> T - where - T: TypeFoldable<'tcx>, - { - debug!( - "normalize_erasing_regions::<{}>(value={:?}, param_env={:?})", - ::std::any::type_name::(), - value, - param_env, - ); - - // Erase first before we do the real query -- this keeps the - // cache from being too polluted. - let value = self.erase_regions(&value); - if !value.has_projections() { - value - } else { - value.fold_with(&mut NormalizeAfterErasingRegionsFolder { - tcx: self, - param_env: param_env, - }) - } - } - - /// If you have a `Binder`, you can do this to strip out the - /// late-bound regions and then normalize the result, yielding up - /// a `T` (with regions erased). This is appropriate when the - /// binder is being instantiated at the call site. - /// - /// N.B., currently, higher-ranked type bounds inhibit - /// normalization. Therefore, each time we erase them in - /// codegen, we need to normalize the contents. - pub fn normalize_erasing_late_bound_regions( - self, - param_env: ty::ParamEnv<'tcx>, - value: &ty::Binder, - ) -> T - where - T: TypeFoldable<'tcx>, - { - assert!(!value.needs_subst()); - let value = self.erase_late_bound_regions(value); - self.normalize_erasing_regions(param_env, value) - } -} - -struct NormalizeAfterErasingRegionsFolder<'tcx> { - tcx: TyCtxt<'tcx>, - param_env: ty::ParamEnv<'tcx>, -} - -impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> { - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx - } - - fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - self.tcx.normalize_ty_after_erasing_regions(self.param_env.and(ty)) - } -} diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 1698a0685b7..6e7a4d6c53e 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -109,6 +109,7 @@ pub mod flags; pub mod fold; pub mod inhabitedness; pub mod layout; +pub mod normalize_erasing_regions; pub mod outlives; pub mod print; pub mod query; diff --git a/src/librustc/ty/normalize_erasing_regions.rs b/src/librustc/ty/normalize_erasing_regions.rs new file mode 100644 index 00000000000..2fa52e8810b --- /dev/null +++ b/src/librustc/ty/normalize_erasing_regions.rs @@ -0,0 +1,78 @@ +//! Methods for normalizing when you don't care about regions (and +//! aren't doing type inference). If either of those things don't +//! apply to you, use `infcx.normalize(...)`. +//! +//! The methods in this file use a `TypeFolder` to recursively process +//! contents, invoking the underlying +//! `normalize_ty_after_erasing_regions` query for each type found +//! within. (This underlying query is what is cached.) + +use crate::ty::fold::{TypeFoldable, TypeFolder}; +use crate::ty::{self, Ty, TyCtxt}; + +impl<'tcx> TyCtxt<'tcx> { + /// Erase the regions in `value` and then fully normalize all the + /// types found within. The result will also have regions erased. + /// + /// This is appropriate to use only after type-check: it assumes + /// that normalization will succeed, for example. + pub fn normalize_erasing_regions(self, param_env: ty::ParamEnv<'tcx>, value: T) -> T + where + T: TypeFoldable<'tcx>, + { + debug!( + "normalize_erasing_regions::<{}>(value={:?}, param_env={:?})", + ::std::any::type_name::(), + value, + param_env, + ); + + // Erase first before we do the real query -- this keeps the + // cache from being too polluted. + let value = self.erase_regions(&value); + if !value.has_projections() { + value + } else { + value.fold_with(&mut NormalizeAfterErasingRegionsFolder { + tcx: self, + param_env: param_env, + }) + } + } + + /// If you have a `Binder`, you can do this to strip out the + /// late-bound regions and then normalize the result, yielding up + /// a `T` (with regions erased). This is appropriate when the + /// binder is being instantiated at the call site. + /// + /// N.B., currently, higher-ranked type bounds inhibit + /// normalization. Therefore, each time we erase them in + /// codegen, we need to normalize the contents. + pub fn normalize_erasing_late_bound_regions( + self, + param_env: ty::ParamEnv<'tcx>, + value: &ty::Binder, + ) -> T + where + T: TypeFoldable<'tcx>, + { + assert!(!value.needs_subst()); + let value = self.erase_late_bound_regions(value); + self.normalize_erasing_regions(param_env, value) + } +} + +struct NormalizeAfterErasingRegionsFolder<'tcx> { + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, +} + +impl TypeFolder<'tcx> for NormalizeAfterErasingRegionsFolder<'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { + self.tcx.normalize_ty_after_erasing_regions(self.param_env.and(ty)) + } +} -- cgit 1.4.1-3-g733a5