From 53269c7f6e6ecb30f4f11b36cf97cf82bc75fcbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 30 Nov 2018 23:37:18 +0100 Subject: [PATCH] Update trait queries --- src/librustc/arena.rs | 38 +++++++++++++++++++ src/librustc/infer/canonical/mod.rs | 3 +- .../infer/canonical/query_response.rs | 6 ++- src/librustc/query/mod.rs | 24 ++++++------ src/librustc_traits/chalk_context/mod.rs | 7 ++-- src/librustc_traits/dropck_outlives.rs | 3 +- .../implied_outlives_bounds.rs | 4 +- .../normalize_projection_ty.rs | 3 +- src/librustc_traits/type_op.rs | 17 ++++----- 9 files changed, 69 insertions(+), 36 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index bdec2dc3b9de7..1cc6500d0384f 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -20,6 +20,44 @@ macro_rules! arena_types { [] item_local_set: rustc::util::nodemap::ItemLocalSet, [decode] mir_const_qualif: rustc_data_structures::bit_set::BitSet, [] trait_impls_of: rustc::ty::trait_def::TraitImpls, + [] dropck_outlives: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, + rustc::traits::query::dropck_outlives::DropckOutlivesResult<'tcx> + > + >, + [] normalize_projection_ty: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, + rustc::traits::query::normalize::NormalizationResult<'tcx> + > + >, + [] implied_outlives_bounds: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, + Vec> + > + >, + [] type_op_subtype: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, ()> + >, + [] type_op_normalize_poly_fn_sig: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, rustc::ty::PolyFnSig<'tcx>> + >, + [] type_op_normalize_fn_sig: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, rustc::ty::FnSig<'tcx>> + >, + [] type_op_normalize_predicate: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, rustc::ty::Predicate<'tcx>> + >, + [] type_op_normalize_ty: + rustc::infer::canonical::Canonical<'tcx, + rustc::infer::canonical::QueryResponse<'tcx, rustc::ty::Ty<'tcx>> + >, ], $tcx); ) } diff --git a/src/librustc/infer/canonical/mod.rs b/src/librustc/infer/canonical/mod.rs index 39b84fabff6fb..fe6b8ac1cdc7e 100644 --- a/src/librustc/infer/canonical/mod.rs +++ b/src/librustc/infer/canonical/mod.rs @@ -23,7 +23,6 @@ use crate::infer::{InferCtxt, RegionVariableOrigin, TypeVariableOrigin}; use rustc_data_structures::indexed_vec::IndexVec; -use rustc_data_structures::sync::Lrc; use rustc_macros::HashStable; use serialize::UseSpecializedDecodable; use smallvec::SmallVec; @@ -186,7 +185,7 @@ pub struct QueryResponse<'tcx, R> { pub type Canonicalized<'gcx, V> = Canonical<'gcx, >::Lifted>; pub type CanonicalizedQueryResponse<'gcx, T> = - Lrc>::Lifted>>>; + &'gcx Canonical<'gcx, QueryResponse<'gcx, >::Lifted>>; /// Indicates whether or not we were able to prove the query to be /// true. diff --git a/src/librustc/infer/canonical/query_response.rs b/src/librustc/infer/canonical/query_response.rs index 008882fd50036..e605aae0fae0d 100644 --- a/src/librustc/infer/canonical/query_response.rs +++ b/src/librustc/infer/canonical/query_response.rs @@ -7,6 +7,7 @@ //! //! [c]: https://rust-lang.github.io/rustc-guide/traits/canonicalization.html +use crate::arena::ArenaAllocatable; use crate::infer::canonical::substitute::substitute_value; use crate::infer::canonical::{ Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty, @@ -17,7 +18,6 @@ use crate::infer::InferCtxtBuilder; use crate::infer::{InferCtxt, InferOk, InferResult}; 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_pos::DUMMY_SP; use crate::traits::query::{Fallible, NoSolution}; @@ -54,6 +54,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> { where K: TypeFoldable<'tcx>, R: Debug + Lift<'gcx> + TypeFoldable<'tcx>, + Canonical<'gcx, as Lift<'gcx>>::Lifted>: ArenaAllocatable, { self.enter_with_canonical( DUMMY_SP, @@ -99,6 +100,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { ) -> Fallible> where T: Debug + Lift<'gcx> + TypeFoldable<'tcx>, + Canonical<'gcx, as Lift<'gcx>>::Lifted>: ArenaAllocatable, { let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?; let canonical_result = self.canonicalize_response(&query_response); @@ -108,7 +110,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> { canonical_result ); - Ok(Lrc::new(canonical_result)) + Ok(self.tcx.arena.alloc(canonical_result)) } /// A version of `make_canonicalized_query_response` that does diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index b56b4046830e5..eaf9fd1bc7659 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -892,7 +892,7 @@ rustc_queries! { query normalize_projection_ty( goal: CanonicalProjectionGoal<'tcx> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution, > { no_force @@ -910,7 +910,7 @@ rustc_queries! { query implied_outlives_bounds( goal: CanonicalTyGoal<'tcx> ) -> Result< - Lrc>>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec>>>, NoSolution, > { no_force @@ -921,7 +921,7 @@ rustc_queries! { query dropck_outlives( goal: CanonicalTyGoal<'tcx> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>, NoSolution, > { no_force @@ -940,7 +940,7 @@ rustc_queries! { query evaluate_goal( goal: traits::ChalkCanonicalGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>, NoSolution > { no_force @@ -951,7 +951,7 @@ rustc_queries! { query type_op_ascribe_user_type( goal: CanonicalTypeOpAscribeUserTypeGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>, NoSolution, > { no_force @@ -962,7 +962,7 @@ rustc_queries! { query type_op_eq( goal: CanonicalTypeOpEqGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>, NoSolution, > { no_force @@ -973,7 +973,7 @@ rustc_queries! { query type_op_subtype( goal: CanonicalTypeOpSubtypeGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>, NoSolution, > { no_force @@ -984,7 +984,7 @@ rustc_queries! { query type_op_prove_predicate( goal: CanonicalTypeOpProvePredicateGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>, NoSolution, > { no_force @@ -995,7 +995,7 @@ rustc_queries! { query type_op_normalize_ty( goal: CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>, NoSolution, > { no_force @@ -1006,7 +1006,7 @@ rustc_queries! { query type_op_normalize_predicate( goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>, NoSolution, > { no_force @@ -1017,7 +1017,7 @@ rustc_queries! { query type_op_normalize_poly_fn_sig( goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>, NoSolution, > { no_force @@ -1028,7 +1028,7 @@ rustc_queries! { query type_op_normalize_fn_sig( goal: CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>> ) -> Result< - Lrc>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>, NoSolution, > { no_force diff --git a/src/librustc_traits/chalk_context/mod.rs b/src/librustc_traits/chalk_context/mod.rs index 334f510d10dad..04cd632b29793 100644 --- a/src/librustc_traits/chalk_context/mod.rs +++ b/src/librustc_traits/chalk_context/mod.rs @@ -36,7 +36,6 @@ use rustc::ty::{self, TyCtxt, InferConst}; use rustc::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; use rustc::ty::query::Providers; use rustc::ty::subst::{Kind, UnpackedKind}; -use rustc_data_structures::sync::Lrc; use rustc::mir::interpret::ConstValue; use syntax_pos::DUMMY_SP; @@ -677,7 +676,7 @@ crate fn evaluate_goal<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, goal: ChalkCanonicalGoal<'tcx> ) -> Result< - Lrc>>, + &'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, traits::query::NoSolution > { use crate::lowering::Lower; @@ -718,6 +717,6 @@ crate fn evaluate_goal<'a, 'tcx>( debug!("evaluate_goal: solution = {:?}", solution); - solution.map(|ok| Ok(Lrc::new(ok))) - .unwrap_or(Err(traits::query::NoSolution)) + solution.map(|ok| Ok(&*tcx.arena.alloc(ok))) + .unwrap_or(Err(traits::query::NoSolution)) } diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index 49fcb7cd83355..737bf6f9e84d5 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -7,7 +7,6 @@ use rustc::ty::query::Providers; use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc::util::nodemap::FxHashSet; -use rustc_data_structures::sync::Lrc; use syntax::source_map::{Span, DUMMY_SP}; crate fn provide(p: &mut Providers<'_>) { @@ -21,7 +20,7 @@ crate fn provide(p: &mut Providers<'_>) { fn dropck_outlives<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonical_goal: CanonicalTyGoal<'tcx>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>, NoSolution> { debug!("dropck_outlives(goal={:#?})", canonical_goal); tcx.infer_ctxt().enter_with_canonical( diff --git a/src/librustc_traits/implied_outlives_bounds.rs b/src/librustc_traits/implied_outlives_bounds.rs index dad45130062a4..b1688a7fbbb72 100644 --- a/src/librustc_traits/implied_outlives_bounds.rs +++ b/src/librustc_traits/implied_outlives_bounds.rs @@ -15,8 +15,6 @@ use smallvec::{SmallVec, smallvec}; use syntax::source_map::DUMMY_SP; use rustc::traits::FulfillmentContext; -use rustc_data_structures::sync::Lrc; - crate fn provide(p: &mut Providers<'_>) { *p = Providers { implied_outlives_bounds, @@ -28,7 +26,7 @@ fn implied_outlives_bounds<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: CanonicalTyGoal<'tcx>, ) -> Result< - Lrc>>>>, + &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, Vec>>>, NoSolution, > { tcx.infer_ctxt() diff --git a/src/librustc_traits/normalize_projection_ty.rs b/src/librustc_traits/normalize_projection_ty.rs index 38f7a21e66c55..3ff04bc285369 100644 --- a/src/librustc_traits/normalize_projection_ty.rs +++ b/src/librustc_traits/normalize_projection_ty.rs @@ -4,7 +4,6 @@ use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGo use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt}; use rustc::ty::query::Providers; use rustc::ty::{ParamEnvAnd, TyCtxt}; -use rustc_data_structures::sync::Lrc; use std::sync::atomic::Ordering; use syntax_pos::DUMMY_SP; @@ -18,7 +17,7 @@ crate fn provide(p: &mut Providers<'_>) { fn normalize_projection_ty<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, goal: CanonicalProjectionGoal<'tcx>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> { debug!("normalize_provider(goal={:#?})", goal); tcx.sess diff --git a/src/librustc_traits/type_op.rs b/src/librustc_traits/type_op.rs index 30fbdbdeb4433..ea37024b84f5b 100644 --- a/src/librustc_traits/type_op.rs +++ b/src/librustc_traits/type_op.rs @@ -17,7 +17,6 @@ use rustc::ty::subst::{Kind, Subst, UserSubsts, UserSelfTy}; use rustc::ty::{ FnSig, Lift, ParamEnv, ParamEnvAnd, PolyFnSig, Predicate, Ty, TyCtxt, TypeFoldable, Variance, }; -use rustc_data_structures::sync::Lrc; use std::fmt; use syntax_pos::DUMMY_SP; @@ -38,7 +37,7 @@ crate fn provide(p: &mut Providers<'_>) { fn type_op_ascribe_user_type<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, AscribeUserType<'tcx>>>, -) -> Result>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { let ( @@ -170,7 +169,7 @@ impl AscribeUserTypeCx<'me, 'gcx, 'tcx> { fn type_op_eq<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Eq<'tcx>>>, -) -> Result>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { let (param_env, Eq { a, b }) = key.into_parts(); @@ -200,7 +199,7 @@ where fn type_op_normalize_ty( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize>>>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, type_op_normalize) } @@ -208,7 +207,7 @@ fn type_op_normalize_ty( fn type_op_normalize_predicate( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize>>>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, Predicate<'tcx>>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, type_op_normalize) } @@ -216,7 +215,7 @@ fn type_op_normalize_predicate( fn type_op_normalize_fn_sig( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize>>>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, FnSig<'tcx>>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, type_op_normalize) } @@ -224,7 +223,7 @@ fn type_op_normalize_fn_sig( fn type_op_normalize_poly_fn_sig( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize>>>, -) -> Result>>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, PolyFnSig<'tcx>>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, type_op_normalize) } @@ -232,7 +231,7 @@ fn type_op_normalize_poly_fn_sig( fn type_op_subtype<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Subtype<'tcx>>>, -) -> Result>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { let (param_env, Subtype { sub, sup }) = key.into_parts(); @@ -246,7 +245,7 @@ fn type_op_subtype<'tcx>( fn type_op_prove_predicate<'tcx>( tcx: TyCtxt<'_, 'tcx, 'tcx>, canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>, -) -> Result>>, NoSolution> { +) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt() .enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { let (param_env, ProvePredicate { predicate }) = key.into_parts();