diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2018-06-11 08:41:21 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2018-06-26 10:59:38 -0400 |
| commit | 1d664622b6e46df7e41c0132ebbe60abcf482a21 (patch) | |
| tree | f1f616d68e79c471076a9fc52c0b26a33f0f2876 | |
| parent | d748dc5db04f8287510984caa3ecb6465836ecc2 (diff) | |
| download | rust-1d664622b6e46df7e41c0132ebbe60abcf482a21.tar.gz rust-1d664622b6e46df7e41c0132ebbe60abcf482a21.zip | |
remove `Canonicalization` trait, which serves no purpose
| -rw-r--r-- | src/librustc/infer/canonical/canonicalizer.rs | 41 | ||||
| -rw-r--r-- | src/librustc/infer/canonical/mod.rs | 31 | ||||
| -rw-r--r-- | src/librustc/infer/canonical/query_result.rs | 8 | ||||
| -rw-r--r-- | src/librustc/traits/mod.rs | 30 | ||||
| -rw-r--r-- | src/librustc/traits/query/dropck_outlives.rs | 20 | ||||
| -rw-r--r-- | src/librustc/traits/query/evaluate_obligation.rs | 14 | ||||
| -rw-r--r-- | src/librustc/traits/query/normalize.rs | 13 | ||||
| -rw-r--r-- | src/librustc/ty/mod.rs | 11 | ||||
| -rw-r--r-- | src/librustc_traits/chalk_context.rs | 15 |
9 files changed, 32 insertions, 151 deletions
diff --git a/src/librustc/infer/canonical/canonicalizer.rs b/src/librustc/infer/canonical/canonicalizer.rs index 677063fcf88..aaa5a01e501 100644 --- a/src/librustc/infer/canonical/canonicalizer.rs +++ b/src/librustc/infer/canonical/canonicalizer.rs @@ -17,13 +17,13 @@ use infer::canonical::{ Canonical, CanonicalTyVarKind, CanonicalVarInfo, CanonicalVarKind, CanonicalVarValues, - Canonicalize, + Canonicalized, }; use infer::InferCtxt; use std::sync::atomic::Ordering; use ty::fold::{TypeFoldable, TypeFolder}; use ty::subst::Kind; -use ty::{self, CanonicalVar, Slice, Ty, TyCtxt, TypeFlags}; +use ty::{self, CanonicalVar, Lift, Slice, Ty, TyCtxt, TypeFlags}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::IndexVec; @@ -44,9 +44,12 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// out the [chapter in the rustc guide][c]. /// /// [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html#canonicalizing-the-query - pub fn canonicalize_query<V>(&self, value: &V) -> (V::Canonicalized, CanonicalVarValues<'tcx>) + pub fn canonicalize_query<V>( + &self, + value: &V, + ) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>) where - V: Canonicalize<'gcx, 'tcx>, + V: TypeFoldable<'tcx> + Lift<'gcx>, { self.tcx .sess @@ -90,9 +93,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { pub fn canonicalize_response<V>( &self, value: &V, - ) -> (V::Canonicalized, CanonicalVarValues<'tcx>) + ) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>) where - V: Canonicalize<'gcx, 'tcx>, + V: TypeFoldable<'tcx> + Lift<'gcx>, { Canonicalizer::canonicalize( value, @@ -233,9 +236,9 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> { infcx: Option<&'cx InferCtxt<'cx, 'gcx, 'tcx>>, tcx: TyCtxt<'cx, 'gcx, 'tcx>, canonicalize_all_free_regions: CanonicalizeAllFreeRegions, - ) -> (V::Canonicalized, CanonicalVarValues<'tcx>) + ) -> (Canonicalized<'gcx, V>, CanonicalVarValues<'tcx>) where - V: Canonicalize<'gcx, 'tcx>, + V: TypeFoldable<'tcx> + Lift<'gcx>, { debug_assert!( !value.has_type_flags(TypeFlags::HAS_CANONICAL_VARS), @@ -254,13 +257,10 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> { // Fast path: nothing that needs to be canonicalized. if !value.has_type_flags(needs_canonical_flags) { let out_value = gcx.lift(value).unwrap(); - let canon_value = V::intern( - gcx, - Canonical { - variables: Slice::empty(), - value: out_value, - }, - ); + let canon_value = Canonical { + variables: Slice::empty(), + value: out_value, + }; let values = CanonicalVarValues { var_values: IndexVec::default(), }; @@ -291,13 +291,10 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> { let canonical_variables = tcx.intern_canonical_var_infos(&canonicalizer.variables.raw); - let canonical_value = V::intern( - gcx, - Canonical { - variables: canonical_variables, - value: out_value, - }, - ); + let canonical_value = Canonical { + variables: canonical_variables, + value: out_value, + }; let canonical_var_values = CanonicalVarValues { var_values: canonicalizer.var_values, }; diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index 6af8fee6631..62424ff9226 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -35,7 +35,6 @@ use infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin}; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::sync::Lrc; use serialize::UseSpecializedDecodable; -use std::fmt::Debug; use std::ops::Index; use syntax::codemap::Span; use ty::fold::TypeFoldable; @@ -124,6 +123,8 @@ pub struct QueryResult<'tcx, R> { pub value: R, } +pub type Canonicalized<'gcx, V> = Canonical<'gcx, <V as Lift<'gcx>>::Lifted>; + pub type CanonicalizedQueryResult<'gcx, T> = Lrc<Canonical<'gcx, QueryResult<'gcx, <T as Lift<'gcx>>::Lifted>>>; @@ -184,19 +185,6 @@ impl<'tcx, R> Canonical<'tcx, QueryResult<'tcx, R>> { pub type QueryRegionConstraint<'tcx> = ty::Binder<ty::OutlivesPredicate<Kind<'tcx>, Region<'tcx>>>; -/// Trait implemented by values that can be canonicalized. It mainly -/// serves to identify the interning table we will use. -pub trait Canonicalize<'gcx: 'tcx, 'tcx>: TypeFoldable<'tcx> + Lift<'gcx> { - type Canonicalized: 'gcx + Debug; - - /// After a value has been fully canonicalized and lifted, this - /// method will allocate it in a global arena. - fn intern( - gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized; -} - impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// Creates a substitution S for the canonical value with fresh /// inference variables and applies it to the canonical value. @@ -344,18 +332,3 @@ impl<'tcx> Index<CanonicalVar> for CanonicalVarValues<'tcx> { &self.var_values[value] } } - -impl<'gcx: 'tcx, 'tcx, T> Canonicalize<'gcx, 'tcx> for QueryResult<'tcx, T> -where - T: TypeFoldable<'tcx> + Lift<'gcx>, -{ - // we ought to intern this, but I'm too lazy just now - type Canonicalized = Lrc<Canonical<'gcx, QueryResult<'gcx, T::Lifted>>>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - Lrc::new(value) - } -} diff --git a/src/librustc/infer/canonical/query_result.rs b/src/librustc/infer/canonical/query_result.rs index d40daf73115..3fc68994e21 100644 --- a/src/librustc/infer/canonical/query_result.rs +++ b/src/librustc/infer/canonical/query_result.rs @@ -19,13 +19,14 @@ use infer::canonical::substitute::substitute_value; use infer::canonical::{ - Canonical, CanonicalVarValues, Canonicalize, CanonicalizedQueryResult, Certainty, + Canonical, CanonicalVarValues, CanonicalizedQueryResult, Certainty, QueryRegionConstraint, QueryResult, }; use infer::region_constraints::{Constraint, RegionConstraintData}; use infer::{InferCtxt, InferOk, InferResult, RegionObligation}; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::IndexVec; +use rustc_data_structures::sync::Lrc; use std::fmt::Debug; use syntax::ast; use traits::query::NoSolution; @@ -72,7 +73,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { canonical_result ); - Ok(canonical_result) + Ok(Lrc::new(canonical_result)) } /// Helper for `make_canonicalized_query_result` that does @@ -84,8 +85,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { fulfill_cx: &mut FulfillmentContext<'tcx>, ) -> Result<QueryResult<'tcx, T>, NoSolution> where - T: Debug, - QueryResult<'tcx, T>: Canonicalize<'gcx, 'tcx>, + T: Debug + TypeFoldable<'tcx> + Lift<'gcx>, { let tcx = self.tcx; diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 15f0b8eebc1..e9e2695fa5c 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -27,7 +27,6 @@ use ty::subst::Substs; use ty::{self, AdtKind, Slice, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use ty::error::{ExpectedFound, TypeError}; use ty::fold::{TypeFolder, TypeFoldable, TypeVisitor}; -use infer::canonical::{Canonical, Canonicalize}; use infer::{InferCtxt}; use rustc_data_structures::sync::Lrc; @@ -1015,18 +1014,6 @@ pub fn provide(providers: &mut ty::query::Providers) { }; } -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, Goal<'tcx>> { - // we ought to intern this, but I'm too lazy just now - type Canonicalized = Canonical<'gcx, ty::ParamEnvAnd<'gcx, Goal<'gcx>>>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - value - } -} - pub trait ExClauseFold<'tcx> where Self: chalk_engine::context::Context + Clone, @@ -1053,20 +1040,3 @@ where tcx: TyCtxt<'a, 'gcx, 'tcx>, ) -> Option<Self::LiftedExClause>; } - -impl<'gcx: 'tcx, 'tcx, C> Canonicalize<'gcx, 'tcx> for chalk_engine::ExClause<C> -where - C: chalk_engine::context::Context + Clone, - C: ExClauseLift<'gcx> + ExClauseFold<'tcx>, - C::Substitution: Clone, - C::RegionConstraint: Clone, -{ - type Canonicalized = Canonical<'gcx, C::LiftedExClause>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - value - } -} diff --git a/src/librustc/traits/query/dropck_outlives.rs b/src/librustc/traits/query/dropck_outlives.rs index 3bce25b3eff..b843ae8f11a 100644 --- a/src/librustc/traits/query/dropck_outlives.rs +++ b/src/librustc/traits/query/dropck_outlives.rs @@ -9,12 +9,10 @@ // except according to those terms. use infer::at::At; -use infer::canonical::{Canonical, Canonicalize}; use infer::InferOk; use std::iter::FromIterator; -use traits::query::CanonicalTyGoal; -use ty::{self, Ty, TyCtxt}; use ty::subst::Kind; +use ty::{self, Ty, TyCtxt}; impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> { /// Given a type `ty` of some value being dropped, computes a set @@ -44,7 +42,10 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> { // any destructor. let tcx = self.infcx.tcx; if trivial_dropck_outlives(tcx, ty) { - return InferOk { value: vec![], obligations: vec![] }; + return InferOk { + value: vec![], + obligations: vec![], + }; } let gcx = tcx.global_tcx(); @@ -152,17 +153,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> { result } } -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, Ty<'tcx>> { - type Canonicalized = CanonicalTyGoal<'gcx>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - value - } -} - BraceStructTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for DropckOutlivesResult<'tcx> { kinds, overflows diff --git a/src/librustc/traits/query/evaluate_obligation.rs b/src/librustc/traits/query/evaluate_obligation.rs index 4e028cac49a..c81d1123d42 100644 --- a/src/librustc/traits/query/evaluate_obligation.rs +++ b/src/librustc/traits/query/evaluate_obligation.rs @@ -9,11 +9,8 @@ // except according to those terms. use infer::InferCtxt; -use infer::canonical::{Canonical, Canonicalize}; use traits::{EvaluationResult, PredicateObligation, SelectionContext, TraitQueryMode, OverflowError}; -use traits::query::CanonicalPredicateGoal; -use ty::{ParamEnvAnd, Predicate, TyCtxt}; impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { /// Evaluates whether the predicate can be satisfied (by any means) @@ -57,14 +54,3 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { } } } - -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ParamEnvAnd<'tcx, Predicate<'tcx>> { - type Canonicalized = CanonicalPredicateGoal<'gcx>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - value - } -} diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index f7ee67e810b..d459c2d82ad 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -14,11 +14,9 @@ use infer::{InferCtxt, InferOk}; use infer::at::At; -use infer::canonical::{Canonical, Canonicalize}; use middle::const_val::ConstVal; use mir::interpret::GlobalId; use traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; -use traits::query::CanonicalProjectionGoal; use traits::project::Normalized; use ty::{self, Ty, TyCtxt}; use ty::fold::{TypeFoldable, TypeFolder}; @@ -250,17 +248,6 @@ BraceStructLiftImpl! { } } -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ty::ParamEnvAnd<'tcx, ty::ProjectionTy<'tcx>> { - type Canonicalized = CanonicalProjectionGoal<'gcx>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>, - ) -> Self::Canonicalized { - value - } -} - impl_stable_hash_for!(struct NormalizationResult<'tcx> { normalized_ty }); diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index ce709831455..e89a022f818 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -21,7 +21,7 @@ use hir::map::DefPathData; use hir::svh::Svh; use ich::Fingerprint; use ich::StableHashingContext; -use infer::canonical::{Canonical, Canonicalize}; +use infer::canonical::Canonical; use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use middle::privacy::AccessLevels; use middle::resolve_lifetime::ObjectLifetimeDefault; @@ -591,15 +591,6 @@ impl<'tcx> serialize::UseSpecializedDecodable for Ty<'tcx> {} pub type CanonicalTy<'gcx> = Canonical<'gcx, Ty<'gcx>>; -impl <'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for Ty<'tcx> { - type Canonicalized = CanonicalTy<'gcx>; - - fn intern(_gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, Self::Lifted>) -> Self::Canonicalized { - value - } -} - extern { /// A dummy type used to force Slice to by unsized without requiring fat pointers type OpaqueSliceContents; diff --git a/src/librustc_traits/chalk_context.rs b/src/librustc_traits/chalk_context.rs index a1242621cb1..6062fe03e6a 100644 --- a/src/librustc_traits/chalk_context.rs +++ b/src/librustc_traits/chalk_context.rs @@ -10,9 +10,7 @@ use chalk_engine::fallible::Fallible as ChalkEngineFallible; use chalk_engine::{context, hh::HhGoal, DelayedLiteral, ExClause}; -use rustc::infer::canonical::{ - Canonical, CanonicalVarValues, Canonicalize, QueryRegionConstraint, QueryResult, -}; +use rustc::infer::canonical::{Canonical, CanonicalVarValues, QueryRegionConstraint, QueryResult}; use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; use rustc::traits::{ WellFormed, @@ -519,14 +517,3 @@ BraceStructLiftImpl! { subst, constraints } } - -impl<'gcx: 'tcx, 'tcx> Canonicalize<'gcx, 'tcx> for ConstrainedSubst<'tcx> { - type Canonicalized = Canonical<'gcx, ConstrainedSubst<'gcx>>; - - fn intern( - _gcx: TyCtxt<'_, 'gcx, 'gcx>, - value: Canonical<'gcx, ConstrainedSubst<'gcx>>, - ) -> Self::Canonicalized { - value - } -} |
