Skip to content

Commit

Permalink
Use TraitEngine in enter_canonical_trait_query
Browse files Browse the repository at this point in the history
  • Loading branch information
scalexm committed Dec 27, 2018
1 parent da9467d commit 26e0ea8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
18 changes: 11 additions & 7 deletions src/librustc/infer/canonical/query_response.rs
Expand Up @@ -21,7 +21,7 @@ use rustc_data_structures::sync::Lrc;
use std::fmt::Debug;
use syntax_pos::DUMMY_SP;
use traits::query::{Fallible, NoSolution};
use traits::{FulfillmentContext, TraitEngine};
use traits::TraitEngine;
use traits::{Obligation, ObligationCause, PredicateObligation};
use ty::fold::TypeFoldable;
use ty::subst::{Kind, UnpackedKind};
Expand All @@ -48,7 +48,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
pub fn enter_canonical_trait_query<K, R>(
&'tcx mut self,
canonical_key: &Canonical<'tcx, K>,
operation: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>, &mut FulfillmentContext<'tcx>, K)
operation: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>, &mut dyn TraitEngine<'tcx>, K)
-> Fallible<R>,
) -> Fallible<CanonicalizedQueryResponse<'gcx, R>>
where
Expand All @@ -59,9 +59,13 @@ impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
DUMMY_SP,
canonical_key,
|ref infcx, key, canonical_inference_vars| {
let fulfill_cx = &mut FulfillmentContext::new();
let value = operation(infcx, fulfill_cx, key)?;
infcx.make_canonicalized_query_response(canonical_inference_vars, value, fulfill_cx)
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
let value = operation(infcx, &mut *fulfill_cx, key)?;
infcx.make_canonicalized_query_response(
canonical_inference_vars,
value,
&mut *fulfill_cx
)
},
)
}
Expand Down Expand Up @@ -91,7 +95,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
&self,
inference_vars: CanonicalVarValues<'tcx>,
answer: T,
fulfill_cx: &mut FulfillmentContext<'tcx>,
fulfill_cx: &mut dyn TraitEngine<'tcx>,
) -> Fallible<CanonicalizedQueryResponse<'gcx, T>>
where
T: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
Expand Down Expand Up @@ -138,7 +142,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
&self,
inference_vars: CanonicalVarValues<'tcx>,
answer: T,
fulfill_cx: &mut FulfillmentContext<'tcx>,
fulfill_cx: &mut dyn TraitEngine<'tcx>,
) -> Result<QueryResponse<'tcx, T>, NoSolution>
where
T: Debug + TypeFoldable<'tcx> + Lift<'gcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/mod.rs
Expand Up @@ -581,7 +581,7 @@ impl<'tcx, T> InferOk<'tcx, T> {
pub fn into_value_registering_obligations(
self,
infcx: &InferCtxt<'_, '_, 'tcx>,
fulfill_cx: &mut impl TraitEngine<'tcx>,
fulfill_cx: &mut dyn TraitEngine<'tcx>,
) -> T {
let InferOk { value, obligations } = self;
for obligation in obligations {
Expand Down
13 changes: 8 additions & 5 deletions src/librustc/traits/select.rs
Expand Up @@ -3243,11 +3243,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
trait_ref,
)?);

obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
));
// FIXME: chalk
if !self.tcx().sess.opts.debugging_opts.chalk {
obligations.push(Obligation::new(
obligation.cause.clone(),
obligation.param_env,
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
));
}

Ok(VtableClosureData {
closure_def_id,
Expand Down
10 changes: 7 additions & 3 deletions src/librustc_traits/dropck_outlives.rs
Expand Up @@ -2,7 +2,7 @@ use rustc::hir::def_id::DefId;
use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::traits::query::dropck_outlives::{DropckOutlivesResult, DtorckConstraint};
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause, TraitEngineExt};
use rustc::traits::{TraitEngine, Normalized, ObligationCause, TraitEngineExt};
use rustc::ty::query::Providers;
use rustc::ty::subst::{Subst, Substs};
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
Expand Down Expand Up @@ -78,7 +78,7 @@ fn dropck_outlives<'tcx>(
// Set used to detect infinite recursion.
let mut ty_set = FxHashSet::default();

let fulfill_cx = &mut FulfillmentContext::new();
let mut fulfill_cx = TraitEngine::new(infcx.tcx);

let cause = ObligationCause::dummy();
while let Some((ty, depth)) = ty_stack.pop() {
Expand Down Expand Up @@ -136,7 +136,11 @@ fn dropck_outlives<'tcx>(

debug!("dropck_outlives: result = {:#?}", result);

infcx.make_canonicalized_query_response(canonical_inference_vars, result, fulfill_cx)
infcx.make_canonicalized_query_response(
canonical_inference_vars,
result,
&mut *fulfill_cx
)
},
)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_traits/type_op.rs
Expand Up @@ -11,7 +11,7 @@ use rustc::traits::query::type_op::prove_predicate::ProvePredicate;
use rustc::traits::query::type_op::subtype::Subtype;
use rustc::traits::query::{Fallible, NoSolution};
use rustc::traits::{
FulfillmentContext, Normalized, Obligation, ObligationCause, TraitEngine, TraitEngineExt,
Normalized, Obligation, ObligationCause, TraitEngine, TraitEngineExt,
};
use rustc::ty::query::Providers;
use rustc::ty::subst::{Kind, Subst, UserSelfTy, UserSubsts};
Expand Down Expand Up @@ -75,7 +75,7 @@ fn type_op_ascribe_user_type<'tcx>(
struct AscribeUserTypeCx<'me, 'gcx: 'tcx, 'tcx: 'me> {
infcx: &'me InferCtxt<'me, 'gcx, 'tcx>,
param_env: ParamEnv<'tcx>,
fulfill_cx: &'me mut FulfillmentContext<'tcx>,
fulfill_cx: &'me mut dyn TraitEngine<'tcx>,
}

impl AscribeUserTypeCx<'me, 'gcx, 'tcx> {
Expand Down Expand Up @@ -231,7 +231,7 @@ fn type_op_eq<'tcx>(

fn type_op_normalize<T>(
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
fulfill_cx: &mut FulfillmentContext<'tcx>,
fulfill_cx: &mut dyn TraitEngine<'tcx>,
key: ParamEnvAnd<'tcx, Normalize<T>>,
) -> Fallible<T>
where
Expand Down

0 comments on commit 26e0ea8

Please sign in to comment.