Skip to content

Commit

Permalink
Inline evaluate_obligation instead of going through the query system
Browse files Browse the repository at this point in the history
There are several reasons I changed this:

- `evaluate_obligation` is only used in one place in
  `rustc_trait_selection`, and in fact warns you against using it
  anywhere else.
- The implementation in `rustc_traits` was considerably more complicated
  than necessary, because it didn't have the context available in
  `rustc_trait_selection`.
- It allows moving OverflowError into rustc_trait_selection, making
  rust-lang#81091 simpler (in particular,
  it allows holding an `Obligation` in OverflowError, which is only
  defined in `rustc_infer` and not available in rustc_middle).

The only reason to keep the previous behavior is if the cache from the
query system made it significantly faster.
  • Loading branch information
jyn514 committed Jan 18, 2021
1 parent 1f0fc02 commit 1548e0f
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 56 deletions.
14 changes: 3 additions & 11 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::dep_graph::SerializedDepNodeIndex;
use crate::mir::interpret::{GlobalId, LitToConstInput};
use crate::traits;
use crate::traits::query::{
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal,
CanonicalTypeOpSubtypeGoal,
};
use crate::ty::query::queries;
use crate::ty::subst::{GenericArg, SubstsRef};
Expand Down Expand Up @@ -1531,14 +1531,6 @@ rustc_queries! {
desc { "computing dropck types for `{:?}`", goal }
}

/// Do not call this query directly: invoke `infcx.predicate_may_hold()` or
/// `infcx.predicate_must_hold()` instead.
query evaluate_obligation(
goal: CanonicalPredicateGoal<'tcx>
) -> Result<traits::EvaluationResult, traits::OverflowError> {
desc { "evaluating trait selection obligation `{}`", goal.value.value }
}

query evaluate_goal(
goal: traits::CanonicalChalkEnvironmentAndGoal<'tcx>
) -> Result<
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::mir::interpret::{ConstValue, EvalToAllocationRawResult, EvalToConstVa
use crate::mir::interpret::{LitToConstError, LitToConstInput};
use crate::mir::mono::CodegenUnit;
use crate::traits::query::{
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal, NoSolution,
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpAscribeUserTypeGoal,
CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal,
CanonicalTypeOpSubtypeGoal, NoSolution,
};
use crate::traits::query::{
DropckOutlivesResult, DtorckConstraint, MethodAutoderefStepsResult, NormalizationResult,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferCtxt;
use crate::traits::{
EvaluationResult, OverflowError, PredicateObligation, SelectionContext, TraitQueryMode,
Expand Down Expand Up @@ -63,13 +62,8 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
&self,
obligation: &PredicateObligation<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
let mut _orig_values = OriginalQueryValues::default();
let c_pred = self
.canonicalize_query(obligation.param_env.and(obligation.predicate), &mut _orig_values);
// Run canonical query. If overflow occurs, rerun from scratch but this time
// in standard trait query mode so that overflow is handled appropriately
// within `SelectionContext`.
self.tcx.evaluate_obligation(c_pred)
let mut selcx = SelectionContext::with_query_mode(self, TraitQueryMode::Canonical);
selcx.evaluate_root_obligation(&obligation)
}

// Helper function that canonicalizes and runs the query. If an
Expand Down
32 changes: 0 additions & 32 deletions compiler/rustc_traits/src/evaluate_obligation.rs

This file was deleted.

2 changes: 0 additions & 2 deletions compiler/rustc_traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ extern crate rustc_middle;

mod chalk;
mod dropck_outlives;
mod evaluate_obligation;
mod implied_outlives_bounds;
mod normalize_erasing_regions;
mod normalize_projection_ty;
Expand All @@ -24,7 +23,6 @@ use rustc_middle::ty::query::Providers;

pub fn provide(p: &mut Providers) {
dropck_outlives::provide(p);
evaluate_obligation::provide(p);
implied_outlives_bounds::provide(p);
chalk::provide(p);
normalize_projection_ty::provide(p);
Expand Down

0 comments on commit 1548e0f

Please sign in to comment.