});
impl_stable_hash_for!(
- impl<'tcx, R> for struct infer::canonical::QueryResult<'tcx, R> {
+ impl<'tcx, R> for struct infer::canonical::QueryResponse<'tcx, R> {
var_values, region_constraints, certainty, value
}
);
mod canonicalizer;
-pub mod query_result;
+pub mod query_response;
mod substitute;
}
/// After we execute a query with a canonicalized key, we get back a
-/// `Canonical<QueryResult<..>>`. You can use
+/// `Canonical<QueryResponse<..>>`. You can use
/// `instantiate_query_result` to access the data in this result.
#[derive(Clone, Debug)]
-pub struct QueryResult<'tcx, R> {
+pub struct QueryResponse<'tcx, R> {
pub var_values: CanonicalVarValues<'tcx>,
pub region_constraints: Vec<QueryRegionConstraint<'tcx>>,
pub certainty: Certainty,
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>>>;
+pub type CanonicalizedQueryResponse<'gcx, T> =
+ Lrc<Canonical<'gcx, QueryResponse<'gcx, <T as Lift<'gcx>>::Lifted>>>;
/// Indicates whether or not we were able to prove the query to be
/// true.
}
}
-impl<'tcx, R> QueryResult<'tcx, R> {
+impl<'tcx, R> QueryResponse<'tcx, R> {
pub fn is_proven(&self) -> bool {
self.certainty.is_proven()
}
}
}
-impl<'tcx, R> Canonical<'tcx, QueryResult<'tcx, R>> {
+impl<'tcx, R> Canonical<'tcx, QueryResponse<'tcx, R>> {
pub fn is_proven(&self) -> bool {
self.value.is_proven()
}
}
BraceStructTypeFoldableImpl! {
- impl<'tcx, R> TypeFoldable<'tcx> for QueryResult<'tcx, R> {
+ impl<'tcx, R> TypeFoldable<'tcx> for QueryResponse<'tcx, R> {
var_values, region_constraints, certainty, value
} where R: TypeFoldable<'tcx>,
}
BraceStructLiftImpl! {
- impl<'a, 'tcx, R> Lift<'tcx> for QueryResult<'a, R> {
- type Lifted = QueryResult<'tcx, R::Lifted>;
+ impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
+ type Lifted = QueryResponse<'tcx, R::Lifted>;
var_values, region_constraints, certainty, value
} where R: Lift<'tcx>
}
--- /dev/null
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! This module contains the code to instantiate a "query result", and
+//! in particular to extract out the resulting region obligations and
+//! encode them therein.
+//!
+//! For an overview of what canonicaliation is and how it fits into
+//! rustc, check out the [chapter in the rustc guide][c].
+//!
+//! [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html
+
+use infer::canonical::substitute::substitute_value;
+use infer::canonical::{
+ Canonical, CanonicalVarKind, CanonicalVarValues, CanonicalizedQueryResponse, Certainty,
+ QueryRegionConstraint, QueryResponse, SmallCanonicalVarValues,
+};
+use infer::region_constraints::{Constraint, RegionConstraintData};
+use infer::InferCtxtBuilder;
+use 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 traits::query::{Fallible, NoSolution};
+use traits::{FulfillmentContext, TraitEngine};
+use traits::{Obligation, ObligationCause, PredicateObligation};
+use ty::fold::TypeFoldable;
+use ty::subst::{Kind, UnpackedKind};
+use ty::{self, CanonicalVar, Lift, Ty, TyCtxt};
+
+impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
+ /// The "main method" for a canonicalized trait query. Given the
+ /// canonical key `canonical_key`, this method will create a new
+ /// inference context, instantiate the key, and run your operation
+ /// `op`. The operation should yield up a result (of type `R`) as
+ /// well as a set of trait obligations that must be fully
+ /// satisfied. These obligations will be processed and the
+ /// canonical result created.
+ ///
+ /// Returns `NoSolution` in the event of any error.
+ ///
+ /// (It might be mildly nicer to implement this on `TyCtxt`, and
+ /// not `InferCtxtBuilder`, but that is a bit tricky right now.
+ /// In part because we would need a `for<'gcx: 'tcx>` sort of
+ /// bound for the closure and in part because it is convenient to
+ /// have `'tcx` be free on this function so that we can talk about
+ /// `K: TypeFoldable<'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)
+ -> Fallible<R>,
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, R>>
+ where
+ K: TypeFoldable<'tcx>,
+ R: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
+ {
+ self.enter_with_canonical(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)
+ })
+ }
+}
+
+impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
+ /// This method is meant to be invoked as the final step of a canonical query
+ /// implementation. It is given:
+ ///
+ /// - the instantiated variables `inference_vars` created from the query key
+ /// - the result `answer` of the query
+ /// - a fulfillment context `fulfill_cx` that may contain various obligations which
+ /// have yet to be proven.
+ ///
+ /// Given this, the function will process the obligations pending
+ /// in `fulfill_cx`:
+ ///
+ /// - If all the obligations can be proven successfully, it will
+ /// package up any resulting region obligations (extracted from
+ /// `infcx`) along with the fully resolved value `answer` into a
+ /// query result (which is then itself canonicalized).
+ /// - If some obligations can be neither proven nor disproven, then
+ /// the same thing happens, but the resulting query is marked as ambiguous.
+ /// - Finally, if any of the obligations result in a hard error,
+ /// then `Err(NoSolution)` is returned.
+ pub fn make_canonicalized_query_response<T>(
+ &self,
+ inference_vars: CanonicalVarValues<'tcx>,
+ answer: T,
+ fulfill_cx: &mut FulfillmentContext<'tcx>,
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, T>>
+ where
+ T: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
+ {
+ let query_response = self.make_query_response(inference_vars, answer, fulfill_cx)?;
+ let canonical_result = self.canonicalize_response(&query_response);
+
+ debug!(
+ "make_canonicalized_query_response: canonical_result = {:#?}",
+ canonical_result
+ );
+
+ Ok(Lrc::new(canonical_result))
+ }
+
+ /// Helper for `make_canonicalized_query_response` that does
+ /// everything up until the final canonicalization.
+ fn make_query_response<T>(
+ &self,
+ inference_vars: CanonicalVarValues<'tcx>,
+ answer: T,
+ fulfill_cx: &mut FulfillmentContext<'tcx>,
+ ) -> Result<QueryResponse<'tcx, T>, NoSolution>
+ where
+ T: Debug + TypeFoldable<'tcx> + Lift<'gcx>,
+ {
+ let tcx = self.tcx;
+
+ debug!(
+ "make_query_response(\
+ inference_vars={:?}, \
+ answer={:?})",
+ inference_vars, answer,
+ );
+
+ // Select everything, returning errors.
+ let true_errors = fulfill_cx.select_where_possible(self).err().unwrap_or_else(Vec::new);
+ debug!("true_errors = {:#?}", true_errors);
+
+ if !true_errors.is_empty() {
+ // FIXME -- we don't indicate *why* we failed to solve
+ debug!("make_query_response: true_errors={:#?}", true_errors);
+ return Err(NoSolution);
+ }
+
+ // Anything left unselected *now* must be an ambiguity.
+ let ambig_errors = fulfill_cx.select_all_or_error(self).err().unwrap_or_else(Vec::new);
+ debug!("ambig_errors = {:#?}", ambig_errors);
+
+ let region_obligations = self.take_registered_region_obligations();
+ let region_constraints = self.with_region_constraints(|region_constraints| {
+ make_query_outlives(
+ tcx,
+ region_obligations
+ .iter()
+ .map(|(_, r_o)| (r_o.sup_type, r_o.sub_region)),
+ region_constraints)
+ });
+
+ let certainty = if ambig_errors.is_empty() {
+ Certainty::Proven
+ } else {
+ Certainty::Ambiguous
+ };
+
+ Ok(QueryResponse {
+ var_values: inference_vars,
+ region_constraints,
+ certainty,
+ value: answer,
+ })
+ }
+
+ /// Given the (canonicalized) result to a canonical query,
+ /// instantiates the result so it can be used, plugging in the
+ /// values from the canonical query. (Note that the result may
+ /// have been ambiguous; you should check the certainty level of
+ /// the query before applying this function.)
+ ///
+ /// To get a good understanding of what is happening here, check
+ /// out the [chapter in the rustc guide][c].
+ ///
+ /// [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html#processing-the-canonicalized-query-result
+ pub fn instantiate_query_response_and_region_obligations<R>(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ original_values: &SmallCanonicalVarValues<'tcx>,
+ query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
+ ) -> InferResult<'tcx, R>
+ where
+ R: Debug + TypeFoldable<'tcx>,
+ {
+ let InferOk {
+ value: result_subst,
+ mut obligations,
+ } = self.query_response_substitution(cause, param_env, original_values, query_response)?;
+
+ obligations.extend(self.query_region_constraints_into_obligations(
+ cause,
+ param_env,
+ &query_response.value.region_constraints,
+ &result_subst,
+ ));
+
+ let user_result: R =
+ query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
+
+ Ok(InferOk {
+ value: user_result,
+ obligations,
+ })
+ }
+
+ /// An alternative to
+ /// `instantiate_query_response_and_region_obligations` that is more
+ /// efficient for NLL. NLL is a bit more advanced in the
+ /// "transition to chalk" than the rest of the compiler. During
+ /// the NLL type check, all of the "processing" of types and
+ /// things happens in queries -- the NLL checker itself is only
+ /// interested in the region obligations (`'a: 'b` or `T: 'b`)
+ /// that come out of these queries, which it wants to convert into
+ /// MIR-based constraints and solve. Therefore, it is most
+ /// convenient for the NLL Type Checker to **directly consume**
+ /// the `QueryRegionConstraint` values that arise from doing a
+ /// query. This is contrast to other parts of the compiler, which
+ /// would prefer for those `QueryRegionConstraint` to be converted
+ /// into the older infcx-style constraints (e.g., calls to
+ /// `sub_regions` or `register_region_obligation`).
+ ///
+ /// Therefore, `instantiate_nll_query_response_and_region_obligations` performs the same
+ /// basic operations as `instantiate_query_response_and_region_obligations` but
+ /// it returns its result differently:
+ ///
+ /// - It creates a substitution `S` that maps from the original
+ /// query variables to the values computed in the query
+ /// result. If any errors arise, they are propagated back as an
+ /// `Err` result.
+ /// - In the case of a successful substitution, we will append
+ /// `QueryRegionConstraint` values onto the
+ /// `output_query_region_constraints` vector for the solver to
+ /// use (if an error arises, some values may also be pushed, but
+ /// they should be ignored).
+ /// - It **can happen** (though it rarely does currently) that
+ /// equating types and things will give rise to subobligations
+ /// that must be processed. In this case, those subobligations
+ /// are propagated back in the return value.
+ /// - Finally, the query result (of type `R`) is propagated back,
+ /// after applying the substitution `S`.
+ pub fn instantiate_nll_query_response_and_region_obligations<R>(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ original_values: &SmallCanonicalVarValues<'tcx>,
+ query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
+ output_query_region_constraints: &mut Vec<QueryRegionConstraint<'tcx>>,
+ ) -> InferResult<'tcx, R>
+ where
+ R: Debug + TypeFoldable<'tcx>,
+ {
+ // In an NLL query, there should be no type variables in the
+ // query, only region variables.
+ debug_assert!(query_response.variables.iter().all(|v| match v.kind {
+ CanonicalVarKind::Ty(_) => false,
+ CanonicalVarKind::Region => true,
+ }));
+
+ let result_subst =
+ self.query_response_substitution_guess(cause, original_values, query_response);
+
+ // Compute `QueryRegionConstraint` values that unify each of
+ // the original values `v_o` that was canonicalized into a
+ // variable...
+ let mut obligations = vec![];
+
+ for (index, original_value) in original_values.iter().enumerate() {
+ // ...with the value `v_r` of that variable from the query.
+ let result_value = query_response.substitute_projected(self.tcx, &result_subst, |v| {
+ &v.var_values[CanonicalVar::new(index)]
+ });
+ match (original_value.unpack(), result_value.unpack()) {
+ (UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => {
+ // no action needed
+ }
+
+ (UnpackedKind::Lifetime(v_o), UnpackedKind::Lifetime(v_r)) => {
+ // To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
+ if v_o != v_r {
+ output_query_region_constraints
+ .push(ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)));
+ output_query_region_constraints
+ .push(ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)));
+ }
+ }
+
+ (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
+ let ok = self.at(cause, param_env).eq(v1, v2)?;
+ obligations.extend(ok.into_obligations());
+ }
+
+ _ => {
+ bug!(
+ "kind mismatch, cannot unify {:?} and {:?}",
+ original_value,
+ result_value
+ );
+ }
+ }
+ }
+
+ // ...also include the other query region constraints from the query.
+ output_query_region_constraints.extend(
+ query_response.value.region_constraints.iter().filter_map(|r_c| {
+ let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
+ let k1 = substitute_value(self.tcx, &result_subst, &k1);
+ let r2 = substitute_value(self.tcx, &result_subst, &r2);
+ if k1 != r2.into() {
+ Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2)))
+ } else {
+ None
+ }
+ })
+ );
+
+ let user_result: R =
+ query_response.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
+
+ Ok(InferOk {
+ value: user_result,
+ obligations,
+ })
+ }
+
+ /// Given the original values and the (canonicalized) result from
+ /// computing a query, returns a substitution that can be applied
+ /// to the query result to convert the result back into the
+ /// original namespace.
+ ///
+ /// The substitution also comes accompanied with subobligations
+ /// that arose from unification; these might occur if (for
+ /// example) we are doing lazy normalization and the value
+ /// assigned to a type variable is unified with an unnormalized
+ /// projection.
+ fn query_response_substitution<R>(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ original_values: &SmallCanonicalVarValues<'tcx>,
+ query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
+ ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
+ where
+ R: Debug + TypeFoldable<'tcx>,
+ {
+ debug!(
+ "query_response_substitution(original_values={:#?}, query_response={:#?})",
+ original_values, query_response,
+ );
+
+ let result_subst =
+ self.query_response_substitution_guess(cause, original_values, query_response);
+
+ let obligations = self.unify_query_response_substitution_guess(
+ cause,
+ param_env,
+ original_values,
+ &result_subst,
+ query_response,
+ )?
+ .into_obligations();
+
+ Ok(InferOk {
+ value: result_subst,
+ obligations,
+ })
+ }
+
+ /// Given the original values and the (canonicalized) result from
+ /// computing a query, returns a **guess** at a substitution that
+ /// can be applied to the query result to convert the result back
+ /// into the original namespace. This is called a **guess**
+ /// because it uses a quick heuristic to find the values for each
+ /// canonical variable; if that quick heuristic fails, then we
+ /// will instantiate fresh inference variables for each canonical
+ /// variable instead. Therefore, the result of this method must be
+ /// properly unified
+ fn query_response_substitution_guess<R>(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ original_values: &SmallCanonicalVarValues<'tcx>,
+ query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
+ ) -> CanonicalVarValues<'tcx>
+ where
+ R: Debug + TypeFoldable<'tcx>,
+ {
+ debug!(
+ "query_response_substitution_guess(original_values={:#?}, query_response={:#?})",
+ original_values, query_response,
+ );
+
+ // Every canonical query result includes values for each of
+ // the inputs to the query. Therefore, we begin by unifying
+ // these values with the original inputs that were
+ // canonicalized.
+ let result_values = &query_response.value.var_values;
+ assert_eq!(original_values.len(), result_values.len());
+
+ // Quickly try to find initial values for the canonical
+ // variables in the result in terms of the query. We do this
+ // by iterating down the values that the query gave to each of
+ // the canonical inputs. If we find that one of those values
+ // is directly equal to one of the canonical variables in the
+ // result, then we can type the corresponding value from the
+ // input. See the example above.
+ let mut opt_values: IndexVec<CanonicalVar, Option<Kind<'tcx>>> =
+ IndexVec::from_elem_n(None, query_response.variables.len());
+
+ // In terms of our example above, we are iterating over pairs like:
+ // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
+ for (original_value, result_value) in original_values.iter().zip(result_values) {
+ match result_value.unpack() {
+ UnpackedKind::Type(result_value) => {
+ // e.g., here `result_value` might be `?0` in the example above...
+ if let ty::Infer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
+ // in which case we would set `canonical_vars[0]` to `Some(?U)`.
+ opt_values[index] = Some(*original_value);
+ }
+ }
+ UnpackedKind::Lifetime(result_value) => {
+ // e.g., here `result_value` might be `'?1` in the example above...
+ if let &ty::RegionKind::ReCanonical(index) = result_value {
+ // in which case we would set `canonical_vars[0]` to `Some('static)`.
+ opt_values[index] = Some(*original_value);
+ }
+ }
+ }
+ }
+
+ // Create a result substitution: if we found a value for a
+ // given variable in the loop above, use that. Otherwise, use
+ // a fresh inference variable.
+ let result_subst = CanonicalVarValues {
+ var_values: query_response
+ .variables
+ .iter()
+ .enumerate()
+ .map(|(index, info)| opt_values[CanonicalVar::new(index)].unwrap_or_else(||
+ self.fresh_inference_var_for_canonical_var(cause.span, *info)
+ ))
+ .collect(),
+ };
+
+ result_subst
+ }
+
+ /// Given a "guess" at the values for the canonical variables in
+ /// the input, try to unify with the *actual* values found in the
+ /// query result. Often, but not always, this is a no-op, because
+ /// we already found the mapping in the "guessing" step.
+ ///
+ /// See also: `query_response_substitution_guess`
+ fn unify_query_response_substitution_guess<R>(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ original_values: &SmallCanonicalVarValues<'tcx>,
+ result_subst: &CanonicalVarValues<'tcx>,
+ query_response: &Canonical<'tcx, QueryResponse<'tcx, R>>,
+ ) -> InferResult<'tcx, ()>
+ where
+ R: Debug + TypeFoldable<'tcx>,
+ {
+ // A closure that yields the result value for the given
+ // canonical variable; this is taken from
+ // `query_response.var_values` after applying the substitution
+ // `result_subst`.
+ let substituted_query_response = |index: CanonicalVar| -> Kind<'tcx> {
+ query_response.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
+ };
+
+ // Unify the original value for each variable with the value
+ // taken from `query_response` (after applying `result_subst`).
+ Ok(self.unify_canonical_vars(cause, param_env, original_values, substituted_query_response)?)
+ }
+
+ /// Converts the region constraints resulting from a query into an
+ /// iterator of obligations.
+ fn query_region_constraints_into_obligations<'a>(
+ &'a self,
+ cause: &'a ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ unsubstituted_region_constraints: &'a [QueryRegionConstraint<'tcx>],
+ result_subst: &'a CanonicalVarValues<'tcx>,
+ ) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
+ Box::new(
+ unsubstituted_region_constraints
+ .iter()
+ .map(move |constraint| {
+ let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
+ let k1 = substitute_value(self.tcx, result_subst, k1);
+ let r2 = substitute_value(self.tcx, result_subst, r2);
+
+ Obligation::new(
+ cause.clone(),
+ param_env,
+ match k1.unpack() {
+ UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
+ ty::Binder::dummy(
+ ty::OutlivesPredicate(r1, r2)
+ )),
+ UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives(
+ ty::Binder::dummy(ty::OutlivesPredicate(
+ t1, r2
+ )))
+ }
+ )
+ })
+ ) as Box<dyn Iterator<Item = _>>
+ }
+
+ /// Given two sets of values for the same set of canonical variables, unify them.
+ /// The second set is produced lazilly by supplying indices from the first set.
+ fn unify_canonical_vars(
+ &self,
+ cause: &ObligationCause<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
+ variables1: &SmallCanonicalVarValues<'tcx>,
+ variables2: impl Fn(CanonicalVar) -> Kind<'tcx>,
+ ) -> InferResult<'tcx, ()> {
+ self.commit_if_ok(|_| {
+ let mut obligations = vec![];
+ for (index, value1) in variables1.iter().enumerate() {
+ let value2 = variables2(CanonicalVar::new(index));
+
+ match (value1.unpack(), value2.unpack()) {
+ (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
+ obligations
+ .extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
+ }
+ (
+ UnpackedKind::Lifetime(ty::ReErased),
+ UnpackedKind::Lifetime(ty::ReErased),
+ ) => {
+ // no action needed
+ }
+ (UnpackedKind::Lifetime(v1), UnpackedKind::Lifetime(v2)) => {
+ obligations
+ .extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
+ }
+ _ => {
+ bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
+ }
+ }
+ }
+ Ok(InferOk {
+ value: (),
+ obligations,
+ })
+ })
+ }
+}
+
+/// Given the region obligations and constraints scraped from the infcx,
+/// creates query region constraints.
+pub fn make_query_outlives<'tcx>(
+ tcx: TyCtxt<'_, '_, 'tcx>,
+ outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>)>,
+ region_constraints: &RegionConstraintData<'tcx>,
+) -> Vec<QueryRegionConstraint<'tcx>> {
+ let RegionConstraintData {
+ constraints,
+ verifys,
+ givens,
+ } = region_constraints;
+
+ assert!(verifys.is_empty());
+ assert!(givens.is_empty());
+
+ let outlives: Vec<_> = constraints
+ .into_iter()
+ .map(|(k, _)| match *k {
+ // Swap regions because we are going from sub (<=) to outlives
+ // (>=).
+ Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
+ tcx.mk_region(ty::ReVar(v2)).into(),
+ tcx.mk_region(ty::ReVar(v1)),
+ ),
+ Constraint::VarSubReg(v1, r2) => {
+ ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
+ }
+ Constraint::RegSubVar(r1, v2) => {
+ ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
+ }
+ Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
+ })
+ .map(ty::Binder::dummy) // no bound regions in the code above
+ .chain(
+ outlives_obligations
+ .map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
+ .map(ty::Binder::dummy), // no bound regions in the code above
+ )
+ .collect();
+
+ outlives
+}
+++ /dev/null
-// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! This module contains the code to instantiate a "query result", and
-//! in particular to extract out the resulting region obligations and
-//! encode them therein.
-//!
-//! For an overview of what canonicaliation is and how it fits into
-//! rustc, check out the [chapter in the rustc guide][c].
-//!
-//! [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html
-
-use infer::canonical::substitute::substitute_value;
-use infer::canonical::{
- Canonical, CanonicalVarKind, CanonicalVarValues, CanonicalizedQueryResult, Certainty,
- QueryRegionConstraint, QueryResult, SmallCanonicalVarValues,
-};
-use infer::region_constraints::{Constraint, RegionConstraintData};
-use infer::InferCtxtBuilder;
-use 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 traits::query::{Fallible, NoSolution};
-use traits::{FulfillmentContext, TraitEngine};
-use traits::{Obligation, ObligationCause, PredicateObligation};
-use ty::fold::TypeFoldable;
-use ty::subst::{Kind, UnpackedKind};
-use ty::{self, CanonicalVar, Lift, Ty, TyCtxt};
-
-impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
- /// The "main method" for a canonicalized trait query. Given the
- /// canonical key `canonical_key`, this method will create a new
- /// inference context, instantiate the key, and run your operation
- /// `op`. The operation should yield up a result (of type `R`) as
- /// well as a set of trait obligations that must be fully
- /// satisfied. These obligations will be processed and the
- /// canonical result created.
- ///
- /// Returns `NoSolution` in the event of any error.
- ///
- /// (It might be mildly nicer to implement this on `TyCtxt`, and
- /// not `InferCtxtBuilder`, but that is a bit tricky right now.
- /// In part because we would need a `for<'gcx: 'tcx>` sort of
- /// bound for the closure and in part because it is convenient to
- /// have `'tcx` be free on this function so that we can talk about
- /// `K: TypeFoldable<'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)
- -> Fallible<R>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, R>>
- where
- K: TypeFoldable<'tcx>,
- R: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
- {
- self.enter_with_canonical(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_result(canonical_inference_vars, value, fulfill_cx)
- })
- }
-}
-
-impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
- /// This method is meant to be invoked as the final step of a canonical query
- /// implementation. It is given:
- ///
- /// - the instantiated variables `inference_vars` created from the query key
- /// - the result `answer` of the query
- /// - a fulfillment context `fulfill_cx` that may contain various obligations which
- /// have yet to be proven.
- ///
- /// Given this, the function will process the obligations pending
- /// in `fulfill_cx`:
- ///
- /// - If all the obligations can be proven successfully, it will
- /// package up any resulting region obligations (extracted from
- /// `infcx`) along with the fully resolved value `answer` into a
- /// query result (which is then itself canonicalized).
- /// - If some obligations can be neither proven nor disproven, then
- /// the same thing happens, but the resulting query is marked as ambiguous.
- /// - Finally, if any of the obligations result in a hard error,
- /// then `Err(NoSolution)` is returned.
- pub fn make_canonicalized_query_result<T>(
- &self,
- inference_vars: CanonicalVarValues<'tcx>,
- answer: T,
- fulfill_cx: &mut FulfillmentContext<'tcx>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, T>>
- where
- T: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
- {
- let query_result = self.make_query_result(inference_vars, answer, fulfill_cx)?;
- let canonical_result = self.canonicalize_response(&query_result);
-
- debug!(
- "make_canonicalized_query_result: canonical_result = {:#?}",
- canonical_result
- );
-
- Ok(Lrc::new(canonical_result))
- }
-
- /// Helper for `make_canonicalized_query_result` that does
- /// everything up until the final canonicalization.
- fn make_query_result<T>(
- &self,
- inference_vars: CanonicalVarValues<'tcx>,
- answer: T,
- fulfill_cx: &mut FulfillmentContext<'tcx>,
- ) -> Result<QueryResult<'tcx, T>, NoSolution>
- where
- T: Debug + TypeFoldable<'tcx> + Lift<'gcx>,
- {
- let tcx = self.tcx;
-
- debug!(
- "make_query_result(\
- inference_vars={:?}, \
- answer={:?})",
- inference_vars, answer,
- );
-
- // Select everything, returning errors.
- let true_errors = fulfill_cx.select_where_possible(self).err().unwrap_or_else(Vec::new);
- debug!("true_errors = {:#?}", true_errors);
-
- if !true_errors.is_empty() {
- // FIXME -- we don't indicate *why* we failed to solve
- debug!("make_query_result: true_errors={:#?}", true_errors);
- return Err(NoSolution);
- }
-
- // Anything left unselected *now* must be an ambiguity.
- let ambig_errors = fulfill_cx.select_all_or_error(self).err().unwrap_or_else(Vec::new);
- debug!("ambig_errors = {:#?}", ambig_errors);
-
- let region_obligations = self.take_registered_region_obligations();
- let region_constraints = self.with_region_constraints(|region_constraints| {
- make_query_outlives(
- tcx,
- region_obligations
- .iter()
- .map(|(_, r_o)| (r_o.sup_type, r_o.sub_region)),
- region_constraints)
- });
-
- let certainty = if ambig_errors.is_empty() {
- Certainty::Proven
- } else {
- Certainty::Ambiguous
- };
-
- Ok(QueryResult {
- var_values: inference_vars,
- region_constraints,
- certainty,
- value: answer,
- })
- }
-
- /// Given the (canonicalized) result to a canonical query,
- /// instantiates the result so it can be used, plugging in the
- /// values from the canonical query. (Note that the result may
- /// have been ambiguous; you should check the certainty level of
- /// the query before applying this function.)
- ///
- /// To get a good understanding of what is happening here, check
- /// out the [chapter in the rustc guide][c].
- ///
- /// [c]: https://rust-lang-nursery.github.io/rustc-guide/traits/canonicalization.html#processing-the-canonicalized-query-result
- pub fn instantiate_query_result_and_region_obligations<R>(
- &self,
- cause: &ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- original_values: &SmallCanonicalVarValues<'tcx>,
- query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
- ) -> InferResult<'tcx, R>
- where
- R: Debug + TypeFoldable<'tcx>,
- {
- let InferOk {
- value: result_subst,
- mut obligations,
- } = self.query_result_substitution(cause, param_env, original_values, query_result)?;
-
- obligations.extend(self.query_region_constraints_into_obligations(
- cause,
- param_env,
- &query_result.value.region_constraints,
- &result_subst,
- ));
-
- let user_result: R =
- query_result.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
-
- Ok(InferOk {
- value: user_result,
- obligations,
- })
- }
-
- /// An alternative to
- /// `instantiate_query_result_and_region_obligations` that is more
- /// efficient for NLL. NLL is a bit more advanced in the
- /// "transition to chalk" than the rest of the compiler. During
- /// the NLL type check, all of the "processing" of types and
- /// things happens in queries -- the NLL checker itself is only
- /// interested in the region obligations (`'a: 'b` or `T: 'b`)
- /// that come out of these queries, which it wants to convert into
- /// MIR-based constraints and solve. Therefore, it is most
- /// convenient for the NLL Type Checker to **directly consume**
- /// the `QueryRegionConstraint` values that arise from doing a
- /// query. This is contrast to other parts of the compiler, which
- /// would prefer for those `QueryRegionConstraint` to be converted
- /// into the older infcx-style constraints (e.g., calls to
- /// `sub_regions` or `register_region_obligation`).
- ///
- /// Therefore, `instantiate_nll_query_result_and_region_obligations` performs the same
- /// basic operations as `instantiate_query_result_and_region_obligations` but
- /// it returns its result differently:
- ///
- /// - It creates a substitution `S` that maps from the original
- /// query variables to the values computed in the query
- /// result. If any errors arise, they are propagated back as an
- /// `Err` result.
- /// - In the case of a successful substitution, we will append
- /// `QueryRegionConstraint` values onto the
- /// `output_query_region_constraints` vector for the solver to
- /// use (if an error arises, some values may also be pushed, but
- /// they should be ignored).
- /// - It **can happen** (though it rarely does currently) that
- /// equating types and things will give rise to subobligations
- /// that must be processed. In this case, those subobligations
- /// are propagated back in the return value.
- /// - Finally, the query result (of type `R`) is propagated back,
- /// after applying the substitution `S`.
- pub fn instantiate_nll_query_result_and_region_obligations<R>(
- &self,
- cause: &ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- original_values: &SmallCanonicalVarValues<'tcx>,
- query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
- output_query_region_constraints: &mut Vec<QueryRegionConstraint<'tcx>>,
- ) -> InferResult<'tcx, R>
- where
- R: Debug + TypeFoldable<'tcx>,
- {
- // In an NLL query, there should be no type variables in the
- // query, only region variables.
- debug_assert!(query_result.variables.iter().all(|v| match v.kind {
- CanonicalVarKind::Ty(_) => false,
- CanonicalVarKind::Region => true,
- }));
-
- let result_subst =
- self.query_result_substitution_guess(cause, original_values, query_result);
-
- // Compute `QueryRegionConstraint` values that unify each of
- // the original values `v_o` that was canonicalized into a
- // variable...
- let mut obligations = vec![];
-
- for (index, original_value) in original_values.iter().enumerate() {
- // ...with the value `v_r` of that variable from the query.
- let result_value = query_result.substitute_projected(self.tcx, &result_subst, |v| {
- &v.var_values[CanonicalVar::new(index)]
- });
- match (original_value.unpack(), result_value.unpack()) {
- (UnpackedKind::Lifetime(ty::ReErased), UnpackedKind::Lifetime(ty::ReErased)) => {
- // no action needed
- }
-
- (UnpackedKind::Lifetime(v_o), UnpackedKind::Lifetime(v_r)) => {
- // To make `v_o = v_r`, we emit `v_o: v_r` and `v_r: v_o`.
- if v_o != v_r {
- output_query_region_constraints
- .push(ty::Binder::dummy(ty::OutlivesPredicate(v_o.into(), v_r)));
- output_query_region_constraints
- .push(ty::Binder::dummy(ty::OutlivesPredicate(v_r.into(), v_o)));
- }
- }
-
- (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
- let ok = self.at(cause, param_env).eq(v1, v2)?;
- obligations.extend(ok.into_obligations());
- }
-
- _ => {
- bug!(
- "kind mismatch, cannot unify {:?} and {:?}",
- original_value,
- result_value
- );
- }
- }
- }
-
- // ...also include the other query region constraints from the query.
- output_query_region_constraints.extend(
- query_result.value.region_constraints.iter().filter_map(|r_c| {
- let &ty::OutlivesPredicate(k1, r2) = r_c.skip_binder(); // reconstructed below
- let k1 = substitute_value(self.tcx, &result_subst, &k1);
- let r2 = substitute_value(self.tcx, &result_subst, &r2);
- if k1 != r2.into() {
- Some(ty::Binder::bind(ty::OutlivesPredicate(k1, r2)))
- } else {
- None
- }
- })
- );
-
- let user_result: R =
- query_result.substitute_projected(self.tcx, &result_subst, |q_r| &q_r.value);
-
- Ok(InferOk {
- value: user_result,
- obligations,
- })
- }
-
- /// Given the original values and the (canonicalized) result from
- /// computing a query, returns a substitution that can be applied
- /// to the query result to convert the result back into the
- /// original namespace.
- ///
- /// The substitution also comes accompanied with subobligations
- /// that arose from unification; these might occur if (for
- /// example) we are doing lazy normalization and the value
- /// assigned to a type variable is unified with an unnormalized
- /// projection.
- fn query_result_substitution<R>(
- &self,
- cause: &ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- original_values: &SmallCanonicalVarValues<'tcx>,
- query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
- ) -> InferResult<'tcx, CanonicalVarValues<'tcx>>
- where
- R: Debug + TypeFoldable<'tcx>,
- {
- debug!(
- "query_result_substitution(original_values={:#?}, query_result={:#?})",
- original_values, query_result,
- );
-
- let result_subst =
- self.query_result_substitution_guess(cause, original_values, query_result);
-
- let obligations = self.unify_query_result_substitution_guess(
- cause,
- param_env,
- original_values,
- &result_subst,
- query_result,
- )?
- .into_obligations();
-
- Ok(InferOk {
- value: result_subst,
- obligations,
- })
- }
-
- /// Given the original values and the (canonicalized) result from
- /// computing a query, returns a **guess** at a substitution that
- /// can be applied to the query result to convert the result back
- /// into the original namespace. This is called a **guess**
- /// because it uses a quick heuristic to find the values for each
- /// canonical variable; if that quick heuristic fails, then we
- /// will instantiate fresh inference variables for each canonical
- /// variable instead. Therefore, the result of this method must be
- /// properly unified
- fn query_result_substitution_guess<R>(
- &self,
- cause: &ObligationCause<'tcx>,
- original_values: &SmallCanonicalVarValues<'tcx>,
- query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
- ) -> CanonicalVarValues<'tcx>
- where
- R: Debug + TypeFoldable<'tcx>,
- {
- debug!(
- "query_result_substitution_guess(original_values={:#?}, query_result={:#?})",
- original_values, query_result,
- );
-
- // Every canonical query result includes values for each of
- // the inputs to the query. Therefore, we begin by unifying
- // these values with the original inputs that were
- // canonicalized.
- let result_values = &query_result.value.var_values;
- assert_eq!(original_values.len(), result_values.len());
-
- // Quickly try to find initial values for the canonical
- // variables in the result in terms of the query. We do this
- // by iterating down the values that the query gave to each of
- // the canonical inputs. If we find that one of those values
- // is directly equal to one of the canonical variables in the
- // result, then we can type the corresponding value from the
- // input. See the example above.
- let mut opt_values: IndexVec<CanonicalVar, Option<Kind<'tcx>>> =
- IndexVec::from_elem_n(None, query_result.variables.len());
-
- // In terms of our example above, we are iterating over pairs like:
- // [(?A, Vec<?0>), ('static, '?1), (?B, ?0)]
- for (original_value, result_value) in original_values.iter().zip(result_values) {
- match result_value.unpack() {
- UnpackedKind::Type(result_value) => {
- // e.g., here `result_value` might be `?0` in the example above...
- if let ty::Infer(ty::InferTy::CanonicalTy(index)) = result_value.sty {
- // in which case we would set `canonical_vars[0]` to `Some(?U)`.
- opt_values[index] = Some(*original_value);
- }
- }
- UnpackedKind::Lifetime(result_value) => {
- // e.g., here `result_value` might be `'?1` in the example above...
- if let &ty::RegionKind::ReCanonical(index) = result_value {
- // in which case we would set `canonical_vars[0]` to `Some('static)`.
- opt_values[index] = Some(*original_value);
- }
- }
- }
- }
-
- // Create a result substitution: if we found a value for a
- // given variable in the loop above, use that. Otherwise, use
- // a fresh inference variable.
- let result_subst = CanonicalVarValues {
- var_values: query_result
- .variables
- .iter()
- .enumerate()
- .map(|(index, info)| opt_values[CanonicalVar::new(index)].unwrap_or_else(||
- self.fresh_inference_var_for_canonical_var(cause.span, *info)
- ))
- .collect(),
- };
-
- result_subst
- }
-
- /// Given a "guess" at the values for the canonical variables in
- /// the input, try to unify with the *actual* values found in the
- /// query result. Often, but not always, this is a no-op, because
- /// we already found the mapping in the "guessing" step.
- ///
- /// See also: `query_result_substitution_guess`
- fn unify_query_result_substitution_guess<R>(
- &self,
- cause: &ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- original_values: &SmallCanonicalVarValues<'tcx>,
- result_subst: &CanonicalVarValues<'tcx>,
- query_result: &Canonical<'tcx, QueryResult<'tcx, R>>,
- ) -> InferResult<'tcx, ()>
- where
- R: Debug + TypeFoldable<'tcx>,
- {
- // A closure that yields the result value for the given
- // canonical variable; this is taken from
- // `query_result.var_values` after applying the substitution
- // `result_subst`.
- let substituted_query_result = |index: CanonicalVar| -> Kind<'tcx> {
- query_result.substitute_projected(self.tcx, &result_subst, |v| &v.var_values[index])
- };
-
- // Unify the original value for each variable with the value
- // taken from `query_result` (after applying `result_subst`).
- Ok(self.unify_canonical_vars(cause, param_env, original_values, substituted_query_result)?)
- }
-
- /// Converts the region constraints resulting from a query into an
- /// iterator of obligations.
- fn query_region_constraints_into_obligations<'a>(
- &'a self,
- cause: &'a ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- unsubstituted_region_constraints: &'a [QueryRegionConstraint<'tcx>],
- result_subst: &'a CanonicalVarValues<'tcx>,
- ) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
- Box::new(
- unsubstituted_region_constraints
- .iter()
- .map(move |constraint| {
- let ty::OutlivesPredicate(k1, r2) = constraint.skip_binder(); // restored below
- let k1 = substitute_value(self.tcx, result_subst, k1);
- let r2 = substitute_value(self.tcx, result_subst, r2);
-
- Obligation::new(
- cause.clone(),
- param_env,
- match k1.unpack() {
- UnpackedKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
- ty::Binder::dummy(
- ty::OutlivesPredicate(r1, r2)
- )),
- UnpackedKind::Type(t1) => ty::Predicate::TypeOutlives(
- ty::Binder::dummy(ty::OutlivesPredicate(
- t1, r2
- )))
- }
- )
- })
- ) as Box<dyn Iterator<Item = _>>
- }
-
- /// Given two sets of values for the same set of canonical variables, unify them.
- /// The second set is produced lazilly by supplying indices from the first set.
- fn unify_canonical_vars(
- &self,
- cause: &ObligationCause<'tcx>,
- param_env: ty::ParamEnv<'tcx>,
- variables1: &SmallCanonicalVarValues<'tcx>,
- variables2: impl Fn(CanonicalVar) -> Kind<'tcx>,
- ) -> InferResult<'tcx, ()> {
- self.commit_if_ok(|_| {
- let mut obligations = vec![];
- for (index, value1) in variables1.iter().enumerate() {
- let value2 = variables2(CanonicalVar::new(index));
-
- match (value1.unpack(), value2.unpack()) {
- (UnpackedKind::Type(v1), UnpackedKind::Type(v2)) => {
- obligations
- .extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
- }
- (
- UnpackedKind::Lifetime(ty::ReErased),
- UnpackedKind::Lifetime(ty::ReErased),
- ) => {
- // no action needed
- }
- (UnpackedKind::Lifetime(v1), UnpackedKind::Lifetime(v2)) => {
- obligations
- .extend(self.at(cause, param_env).eq(v1, v2)?.into_obligations());
- }
- _ => {
- bug!("kind mismatch, cannot unify {:?} and {:?}", value1, value2,);
- }
- }
- }
- Ok(InferOk {
- value: (),
- obligations,
- })
- })
- }
-}
-
-/// Given the region obligations and constraints scraped from the infcx,
-/// creates query region constraints.
-pub fn make_query_outlives<'tcx>(
- tcx: TyCtxt<'_, '_, 'tcx>,
- outlives_obligations: impl Iterator<Item = (Ty<'tcx>, ty::Region<'tcx>)>,
- region_constraints: &RegionConstraintData<'tcx>,
-) -> Vec<QueryRegionConstraint<'tcx>> {
- let RegionConstraintData {
- constraints,
- verifys,
- givens,
- } = region_constraints;
-
- assert!(verifys.is_empty());
- assert!(givens.is_empty());
-
- let outlives: Vec<_> = constraints
- .into_iter()
- .map(|(k, _)| match *k {
- // Swap regions because we are going from sub (<=) to outlives
- // (>=).
- Constraint::VarSubVar(v1, v2) => ty::OutlivesPredicate(
- tcx.mk_region(ty::ReVar(v2)).into(),
- tcx.mk_region(ty::ReVar(v1)),
- ),
- Constraint::VarSubReg(v1, r2) => {
- ty::OutlivesPredicate(r2.into(), tcx.mk_region(ty::ReVar(v1)))
- }
- Constraint::RegSubVar(r1, v2) => {
- ty::OutlivesPredicate(tcx.mk_region(ty::ReVar(v2)).into(), r1)
- }
- Constraint::RegSubReg(r1, r2) => ty::OutlivesPredicate(r2.into(), r1),
- })
- .map(ty::Binder::dummy) // no bound regions in the code above
- .chain(
- outlives_obligations
- .map(|(ty, r)| ty::OutlivesPredicate(ty.into(), r))
- .map(ty::Binder::dummy), // no bound regions in the code above
- )
- .collect();
-
- outlives
-}
match &gcx.dropck_outlives(c_ty) {
Ok(result) if result.is_proven() => {
if let Ok(InferOk { value, obligations }) =
- self.infcx.instantiate_query_result_and_region_obligations(
+ self.infcx.instantiate_query_response_and_region_obligations(
self.cause,
self.param_env,
&orig_values,
return ty;
}
- match self.infcx.instantiate_query_result_and_region_obligations(
+ match self.infcx.instantiate_query_response_and_region_obligations(
self.cause,
self.param_env,
&orig_values,
};
assert!(result.value.is_proven());
- let result = self.instantiate_query_result_and_region_obligations(
+ let result = self.instantiate_query_response_and_region_obligations(
&ObligationCause::misc(span, body_id), param_env, &orig_values, &result);
debug!("implied_outlives_bounds for {:?}: {:#?}", ty, result);
let result = match result {
use std::fmt;
use traits::query::Fallible;
-use infer::canonical::query_result;
+use infer::canonical::query_response;
use infer::canonical::QueryRegionConstraint;
use std::rc::Rc;
use syntax::source_map::DUMMY_SP;
let region_constraint_data = infcx.take_and_reset_region_constraints();
- let outlives = query_result::make_query_outlives(
+ let outlives = query_response::make_query_outlives(
infcx.tcx,
region_obligations
.iter()
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use traits::query::Fallible;
use ty::{ParamEnvAnd, Ty, TyCtxt};
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Eq<'tcx> {
- type QueryResult = ();
+ type QueryResponse = ();
fn try_fast_path(
_tcx: TyCtxt<'_, 'gcx, 'tcx>,
key: &ParamEnvAnd<'tcx, Eq<'tcx>>,
- ) -> Option<Self::QueryResult> {
+ ) -> Option<Self::QueryResponse> {
if key.value.a == key.value.b {
Some(())
} else {
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, ()>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
tcx.type_op_eq(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, ()>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, ()>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use traits::query::outlives_bounds::OutlivesBound;
use traits::query::Fallible;
use ty::{ParamEnvAnd, Ty, TyCtxt};
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ImpliedOutlivesBounds<'tcx> {
- type QueryResult = Vec<OutlivesBound<'tcx>>;
+ type QueryResponse = Vec<OutlivesBound<'tcx>>;
fn try_fast_path(
_tcx: TyCtxt<'_, 'gcx, 'tcx>,
_key: &ParamEnvAnd<'tcx, Self>,
- ) -> Option<Self::QueryResult> {
+ ) -> Option<Self::QueryResponse> {
None
}
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self::QueryResponse>> {
// FIXME the query should take a `ImpliedOutlivesBounds`
let Canonical {
variables,
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, Self::QueryResponse>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
v
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryRegionConstraint,
- QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryRegionConstraint,
+ QueryResponse};
use infer::{InferCtxt, InferOk};
use smallvec::SmallVec;
use std::fmt;
pub trait QueryTypeOp<'gcx: 'tcx, 'tcx>:
fmt::Debug + Sized + TypeFoldable<'tcx> + Lift<'gcx>
{
- type QueryResult: TypeFoldable<'tcx> + Lift<'gcx>;
+ type QueryResponse: TypeFoldable<'tcx> + Lift<'gcx>;
/// Give query the option for a simple fast path that never
/// actually hits the tcx cache lookup etc. Return `Some(r)` with
fn try_fast_path(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
key: &ParamEnvAnd<'tcx, Self>,
- ) -> Option<Self::QueryResult>;
+ ) -> Option<Self::QueryResponse>;
/// Performs the actual query with the canonicalized key -- the
/// real work happens here. This method is not given an `infcx`
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>>;
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self::QueryResponse>>;
/// Casts a lifted query result (which is in the gcx lifetime)
/// into the tcx lifetime. This is always just an identity cast,
/// but the generic code doesn't realize it -- put another way, in
- /// the generic code, we have a `Lifted<'gcx, Self::QueryResult>`
- /// and we want to convert that to a `Self::QueryResult`. This is
+ /// the generic code, we have a `Lifted<'gcx, Self::QueryResponse>`
+ /// and we want to convert that to a `Self::QueryResponse`. This is
/// not a priori valid, so we can't do it -- but in practice, it
/// is always a no-op (e.g., the lifted form of a type,
/// `Ty<'gcx>`, is a subtype of `Ty<'tcx>`). So we have to push
/// the operation into the impls that know more specifically what
- /// `QueryResult` is. This operation would (maybe) be nicer with
+ /// `QueryResponse` is. This operation would (maybe) be nicer with
/// something like HKTs or GATs, since then we could make
- /// `QueryResult` parametric and `'gcx` and `'tcx` etc.
+ /// `QueryResponse` parametric and `'gcx` and `'tcx` etc.
fn shrink_to_tcx_lifetime(
- lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>>;
+ lifted_query_result: &'a CanonicalizedQueryResponse<'gcx, Self::QueryResponse>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>>;
fn fully_perform_into(
query_key: ParamEnvAnd<'tcx, Self>,
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
output_query_region_constraints: &mut Vec<QueryRegionConstraint<'tcx>>,
- ) -> Fallible<Self::QueryResult> {
+ ) -> Fallible<Self::QueryResponse> {
if let Some(result) = QueryTypeOp::try_fast_path(infcx.tcx, &query_key) {
return Ok(result);
}
let param_env = query_key.param_env;
let InferOk { value, obligations } = infcx
- .instantiate_nll_query_result_and_region_obligations(
+ .instantiate_nll_query_response_and_region_obligations(
&ObligationCause::dummy(),
param_env,
&canonical_var_values,
where
Q: QueryTypeOp<'gcx, 'tcx>,
{
- type Output = Q::QueryResult;
+ type Output = Q::QueryResponse;
fn fully_perform(
self,
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use std::fmt;
use traits::query::Fallible;
use ty::fold::TypeFoldable;
where
T: Normalizable<'gcx, 'tcx>,
{
- type QueryResult = T;
+ type QueryResponse = T;
fn try_fast_path(_tcx: TyCtxt<'_, 'gcx, 'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<T> {
if !key.value.value.has_projections() {
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self::QueryResponse>> {
T::type_op_method(tcx, canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, T>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, T>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, T>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, T>> {
T::shrink_to_tcx_lifetime(v)
}
}
fn type_op_method(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self>>;
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self>>;
/// Convert from the `'gcx` (lifted) form of `Self` into the `tcx`
/// form of `Self`.
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>>;
+ v: &'a CanonicalizedQueryResponse<'gcx, Self>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>>;
}
impl Normalizable<'gcx, 'tcx> for Ty<'tcx>
fn type_op_method(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self>> {
tcx.type_op_normalize_ty(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, Self>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}
fn type_op_method(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self>> {
tcx.type_op_normalize_predicate(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, Self>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}
fn type_op_method(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self>> {
tcx.type_op_normalize_poly_fn_sig(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, Self>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}
fn type_op_method(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Normalize<Self>>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self>> {
tcx.type_op_normalize_fn_sig(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, Self>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, Self>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self>> {
v
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use traits::query::dropck_outlives::trivial_dropck_outlives;
use traits::query::dropck_outlives::DropckOutlivesResult;
use traits::query::Fallible;
where
'gcx: 'tcx,
{
- type QueryResult = DropckOutlivesResult<'tcx>;
+ type QueryResponse = DropckOutlivesResult<'tcx>;
fn try_fast_path(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
key: &ParamEnvAnd<'tcx, Self>,
- ) -> Option<Self::QueryResult> {
+ ) -> Option<Self::QueryResponse> {
if trivial_dropck_outlives(tcx, key.value.dropped_ty) {
Some(DropckOutlivesResult::default())
} else {
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, Self::QueryResponse>> {
// Subtle: note that we are not invoking
// `infcx.at(...).dropck_outlives(...)` here, but rather the
// underlying `dropck_outlives` query. This same underlying
}
fn shrink_to_tcx_lifetime(
- lifted_query_result: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> {
+ lifted_query_result: &'a CanonicalizedQueryResponse<'gcx, Self::QueryResponse>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, Self::QueryResponse>> {
lifted_query_result
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use traits::query::Fallible;
use ty::{ParamEnvAnd, Predicate, TyCtxt};
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
- type QueryResult = ();
+ type QueryResponse = ();
fn try_fast_path(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
key: &ParamEnvAnd<'tcx, Self>,
- ) -> Option<Self::QueryResult> {
+ ) -> Option<Self::QueryResponse> {
// Proving Sized, very often on "obviously sized" types like
// `&T`, accounts for about 60% percentage of the predicates
// we have to prove. No need to canonicalize and all that for
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, ()>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
tcx.type_op_prove_predicate(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, ()>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, ()>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult};
+use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResponse, QueryResponse};
use traits::query::Fallible;
use ty::{ParamEnvAnd, Ty, TyCtxt};
}
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for Subtype<'tcx> {
- type QueryResult = ();
+ type QueryResponse = ();
fn try_fast_path(_tcx: TyCtxt<'_, 'gcx, 'tcx>, key: &ParamEnvAnd<'tcx, Self>) -> Option<()> {
if key.value.sub == key.value.sup {
fn perform_query(
tcx: TyCtxt<'_, 'gcx, 'tcx>,
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>,
- ) -> Fallible<CanonicalizedQueryResult<'gcx, ()>> {
+ ) -> Fallible<CanonicalizedQueryResponse<'gcx, ()>> {
tcx.type_op_subtype(canonicalized)
}
fn shrink_to_tcx_lifetime(
- v: &'a CanonicalizedQueryResult<'gcx, ()>,
- ) -> &'a Canonical<'tcx, QueryResult<'tcx, ()>> {
+ v: &'a CanonicalizedQueryResponse<'gcx, ()>,
+ ) -> &'a Canonical<'tcx, QueryResponse<'tcx, ()>> {
v
}
}
[] fn normalize_projection_ty: NormalizeProjectionTy(
CanonicalProjectionGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, NormalizationResult<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>>,
NoSolution,
>,
[] fn implied_outlives_bounds: ImpliedOutlivesBounds(
CanonicalTyGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, Vec<OutlivesBound<'tcx>>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
NoSolution,
>,
[] fn dropck_outlives: DropckOutlives(
CanonicalTyGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, DropckOutlivesResult<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>,
NoSolution,
>,
[] fn type_op_eq: TypeOpEq(
CanonicalTypeOpEqGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
NoSolution,
>,
[] fn type_op_subtype: TypeOpSubtype(
CanonicalTypeOpSubtypeGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
NoSolution,
>,
[] fn type_op_prove_predicate: TypeOpProvePredicate(
CanonicalTypeOpProvePredicateGoal<'tcx>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ()>>>,
NoSolution,
>,
[] fn type_op_normalize_ty: TypeOpNormalizeTy(
CanonicalTypeOpNormalizeGoal<'tcx, Ty<'tcx>>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, Ty<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Ty<'tcx>>>>,
NoSolution,
>,
[] fn type_op_normalize_predicate: TypeOpNormalizePredicate(
CanonicalTypeOpNormalizeGoal<'tcx, ty::Predicate<'tcx>>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::Predicate<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::Predicate<'tcx>>>>,
NoSolution,
>,
[] fn type_op_normalize_poly_fn_sig: TypeOpNormalizePolyFnSig(
CanonicalTypeOpNormalizeGoal<'tcx, ty::PolyFnSig<'tcx>>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::PolyFnSig<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::PolyFnSig<'tcx>>>>,
NoSolution,
>,
[] fn type_op_normalize_fn_sig: TypeOpNormalizeFnSig(
CanonicalTypeOpNormalizeGoal<'tcx, ty::FnSig<'tcx>>
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ty::FnSig<'tcx>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, ty::FnSig<'tcx>>>>,
NoSolution,
>,
use chalk_engine::fallible::Fallible as ChalkEngineFallible;
use chalk_engine::{context, hh::HhGoal, DelayedLiteral, ExClause};
-use rustc::infer::canonical::{Canonical, CanonicalVarValues, QueryRegionConstraint, QueryResult};
+use rustc::infer::canonical::{Canonical, CanonicalVarValues, QueryRegionConstraint, QueryResponse};
use rustc::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
use rustc::traits::{
WellFormed,
// u-canonicalization not yet implemented
type UniverseMap = UniverseMap;
- type Solution = Canonical<'tcx, QueryResult<'tcx, ()>>;
+ type Solution = Canonical<'tcx, QueryResponse<'tcx, ()>>;
type InferenceNormalizedSubst = CanonicalVarValues<'tcx>;
&self,
_root_goal: &Canonical<'gcx, ty::ParamEnvAnd<'gcx, Goal<'gcx>>>,
_simplified_answers: impl context::AnswerStream<ChalkArenas<'gcx>>,
- ) -> Option<Canonical<'gcx, QueryResult<'gcx, ()>>> {
+ ) -> Option<Canonical<'gcx, QueryResponse<'gcx, ()>>> {
unimplemented!()
}
}
// except according to those terms.
use rustc::hir::def_id::DefId;
-use rustc::infer::canonical::{Canonical, QueryResult};
+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};
fn dropck_outlives<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonical_goal: CanonicalTyGoal<'tcx>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, DropckOutlivesResult<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, DropckOutlivesResult<'tcx>>>>, NoSolution> {
debug!("dropck_outlives(goal={:#?})", canonical_goal);
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &canonical_goal, |ref infcx, goal, canonical_inference_vars| {
debug!("dropck_outlives: result = {:#?}", result);
- infcx.make_canonicalized_query_result(canonical_inference_vars, result, fulfill_cx)
+ infcx.make_canonicalized_query_response(canonical_inference_vars, result, fulfill_cx)
})
}
tcx: TyCtxt<'_, 'tcx, 'tcx>,
goal: CanonicalTyGoal<'tcx>,
) -> Result<
- Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, Vec<OutlivesBound<'tcx>>>>>,
+ Lrc<Canonical<'tcx, canonical::QueryResponse<'tcx, Vec<OutlivesBound<'tcx>>>>>,
NoSolution,
> {
tcx.infer_ctxt()
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use rustc::infer::canonical::{Canonical, QueryResult};
+use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt};
use rustc::ty::query::Providers;
fn normalize_projection_ty<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
goal: CanonicalProjectionGoal<'tcx>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>>, NoSolution> {
debug!("normalize_provider(goal={:#?})", goal);
tcx.sess
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use rustc::infer::canonical::{Canonical, QueryResult};
+use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::infer::InferCtxt;
use rustc::traits::query::type_op::eq::Eq;
use rustc::traits::query::type_op::normalize::Normalize;
fn type_op_eq<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Eq<'tcx>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
+) -> Result<Lrc<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();
fn type_op_normalize_ty(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Ty<'tcx>>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Ty<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
fn type_op_normalize_predicate(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Predicate<'tcx>>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, Predicate<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, Predicate<'tcx>>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
fn type_op_normalize_fn_sig(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<FnSig<'tcx>>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, FnSig<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, FnSig<'tcx>>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
fn type_op_normalize_poly_fn_sig(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<PolyFnSig<'tcx>>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, PolyFnSig<'tcx>>>>, NoSolution> {
+) -> Result<Lrc<Canonical<'tcx, QueryResponse<'tcx, PolyFnSig<'tcx>>>>, NoSolution> {
tcx.infer_ctxt()
.enter_canonical_trait_query(&canonicalized, type_op_normalize)
}
fn type_op_subtype<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Subtype<'tcx>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
+) -> Result<Lrc<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();
fn type_op_prove_predicate<'tcx>(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, ProvePredicate<'tcx>>>,
-) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
+) -> Result<Lrc<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();