Skip to content

Commit 79ccf81

Browse files
committed
convert prove_predicate into a query
1 parent ef84523 commit 79ccf81

File tree

8 files changed

+92
-17
lines changed

8 files changed

+92
-17
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use std::hash::Hash;
7272
use syntax_pos::symbol::InternedString;
7373
use traits::query::{
7474
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal,
75-
CanonicalPredicateGoal,
75+
CanonicalPredicateGoal, CanonicalTypeOpProvePredicateGoal,
7676
};
7777
use ty::{TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
7878
use ty::subst::Substs;
@@ -651,6 +651,7 @@ define_dep_nodes!( <'tcx>
651651
[] EvaluateObligation(CanonicalPredicateGoal<'tcx>),
652652
[] TypeOpEq(CanonicalTypeOpEqGoal<'tcx>),
653653
[] TypeOpSubtype(CanonicalTypeOpSubtypeGoal<'tcx>),
654+
[] TypeOpProvePredicate(CanonicalTypeOpProvePredicateGoal<'tcx>),
654655

655656
[] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
656657

src/librustc/traits/query/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ pub type CanonicalTypeOpEqGoal<'tcx> =
3838
pub type CanonicalTypeOpSubtypeGoal<'tcx> =
3939
Canonical<'tcx, type_op::subtype::Subtype<'tcx>>;
4040

41+
pub type CanonicalTypeOpProvePredicateGoal<'tcx> =
42+
Canonical<'tcx, type_op::prove_predicate::ProvePredicate<'tcx>>;
43+
4144
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
4245
pub struct NoSolution;
4346

src/librustc/traits/query/type_op/prove_predicate.rs

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use infer::{InferCtxt, InferOk, InferResult};
12-
use traits::{Obligation, ObligationCause};
11+
use infer::canonical::{Canonical, CanonicalizedQueryResult};
1312
use ty::{ParamEnv, Predicate, TyCtxt};
1413

15-
#[derive(Debug)]
14+
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
1615
pub struct ProvePredicate<'tcx> {
17-
param_env: ParamEnv<'tcx>,
18-
predicate: Predicate<'tcx>,
16+
pub param_env: ParamEnv<'tcx>,
17+
pub predicate: Predicate<'tcx>,
1918
}
2019

2120
impl<'tcx> ProvePredicate<'tcx> {
@@ -27,18 +26,40 @@ impl<'tcx> ProvePredicate<'tcx> {
2726
}
2827
}
2928

30-
impl<'gcx, 'tcx> super::TypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
31-
type Output = ();
29+
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ProvePredicate<'tcx> {
30+
type QueryResult = ();
3231

33-
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::Output, Self> {
32+
fn trivial_noop(self, _tcx: TyCtxt<'_, 'gcx, 'tcx>) -> Result<Self::QueryResult, Self> {
3433
Err(self)
3534
}
3635

37-
fn perform(self, _infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output> {
38-
let obligation = Obligation::new(ObligationCause::dummy(), self.param_env, self.predicate);
39-
Ok(InferOk {
40-
value: (),
41-
obligations: vec![obligation],
42-
})
36+
fn param_env(&self) -> ParamEnv<'tcx> {
37+
self.param_env
4338
}
39+
40+
fn perform_query(
41+
tcx: TyCtxt<'_, 'gcx, 'tcx>,
42+
canonicalized: Canonical<'gcx, ProvePredicate<'gcx>>,
43+
) -> CanonicalizedQueryResult<'gcx, ()> {
44+
tcx.type_op_prove_predicate(canonicalized).unwrap()
45+
}
46+
}
47+
48+
BraceStructTypeFoldableImpl! {
49+
impl<'tcx> TypeFoldable<'tcx> for ProvePredicate<'tcx> {
50+
param_env,
51+
predicate,
52+
}
53+
}
54+
55+
BraceStructLiftImpl! {
56+
impl<'a, 'tcx> Lift<'tcx> for ProvePredicate<'a> {
57+
type Lifted = ProvePredicate<'tcx>;
58+
param_env,
59+
predicate,
60+
}
61+
}
62+
63+
impl_stable_hash_for! {
64+
struct ProvePredicate<'tcx> { param_env, predicate }
4465
}

src/librustc/ty/query/config.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use hir::def_id::{CrateNum, DefId, DefIndex};
1414
use mir::interpret::{GlobalId, ConstValue};
1515
use traits::query::{
1616
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal,
17-
CanonicalTypeOpSubtypeGoal,
17+
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
1818
};
1919
use ty::{self, ParamEnvAnd, Ty, TyCtxt};
2020
use ty::subst::Substs;
@@ -117,6 +117,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::type_op_subtype<'tcx> {
117117
}
118118
}
119119

120+
impl<'tcx> QueryDescription<'tcx> for queries::type_op_prove_predicate<'tcx> {
121+
fn describe(_tcx: TyCtxt, goal: CanonicalTypeOpProvePredicateGoal<'tcx>) -> String {
122+
format!("evaluating `type_op_prove_predicate` `{:?}`", goal)
123+
}
124+
}
125+
120126
impl<'tcx> QueryDescription<'tcx> for queries::is_copy_raw<'tcx> {
121127
fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
122128
format!("computing whether `{}` is `Copy`", env.value)

src/librustc/ty/query/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ use session::{CompileResult, CrateDisambiguator};
3434
use session::config::OutputFilenames;
3535
use traits::{self, Vtable};
3636
use traits::query::{CanonicalPredicateGoal, CanonicalProjectionGoal,
37-
CanonicalTyGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal, NoSolution};
37+
CanonicalTyGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal,
38+
CanonicalTypeOpProvePredicateGoal, NoSolution};
3839
use traits::query::dropck_outlives::{DtorckConstraint, DropckOutlivesResult};
3940
use traits::query::normalize::NormalizationResult;
4041
use traits::specialization_graph;
@@ -462,6 +463,14 @@ define_queries! { <'tcx>
462463
NoSolution,
463464
>,
464465

466+
/// Do not call this query directly: invoke `infcx.at().prove_predicates()` instead.
467+
[] fn type_op_prove_predicate: TypeOpProvePredicate(
468+
CanonicalTypeOpProvePredicateGoal<'tcx>
469+
) -> Result<
470+
Lrc<Canonical<'tcx, canonical::QueryResult<'tcx, ()>>>,
471+
NoSolution,
472+
>,
473+
465474
[] fn substitute_normalize_and_test_predicates:
466475
substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
467476

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
10301030
DepKind::EvaluateObligation |
10311031
DepKind::TypeOpEq |
10321032
DepKind::TypeOpSubtype |
1033+
DepKind::TypeOpProvePredicate |
10331034
DepKind::SubstituteNormalizeAndTestPredicates |
10341035
DepKind::InstanceDefSizeEstimate |
10351036
DepKind::ProgramClausesForEnv |

src/librustc_traits/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod normalize_projection_ty;
3535
mod normalize_erasing_regions;
3636
pub mod lowering;
3737
mod type_op_eq;
38+
mod type_op_prove_predicate;
3839
mod type_op_subtype;
3940

4041
use rustc::ty::query::Providers;
@@ -50,6 +51,7 @@ pub fn provide(p: &mut Providers) {
5051
program_clauses_for_env: lowering::program_clauses_for_env,
5152
evaluate_obligation: evaluate_obligation::evaluate_obligation,
5253
type_op_eq: type_op_eq::type_op_eq,
54+
type_op_prove_predicate: type_op_prove_predicate::type_op_prove_predicate,
5355
type_op_subtype: type_op_subtype::type_op_subtype,
5456
..*p
5557
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use rustc::infer::canonical::{Canonical, QueryResult};
12+
use rustc::traits::query::type_op::prove_predicate::ProvePredicate;
13+
use rustc::traits::query::NoSolution;
14+
use rustc::traits::{FulfillmentContext, Obligation, ObligationCause, TraitEngine};
15+
use rustc::ty::TyCtxt;
16+
use rustc_data_structures::sync::Lrc;
17+
use syntax::codemap::DUMMY_SP;
18+
19+
crate fn type_op_prove_predicate<'tcx>(
20+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
21+
canonicalized: Canonical<'tcx, ProvePredicate<'tcx>>,
22+
) -> Result<Lrc<Canonical<'tcx, QueryResult<'tcx, ()>>>, NoSolution> {
23+
let tcx = tcx.global_tcx();
24+
tcx.infer_ctxt().enter(|ref infcx| {
25+
let (ProvePredicate { param_env, predicate }, canonical_inference_vars) =
26+
infcx.instantiate_canonical_with_fresh_inference_vars(DUMMY_SP, &canonicalized);
27+
let fulfill_cx = &mut FulfillmentContext::new();
28+
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate);
29+
fulfill_cx.register_predicate_obligation(infcx, obligation);
30+
infcx.make_canonicalized_query_result(canonical_inference_vars, (), fulfill_cx)
31+
})
32+
}

0 commit comments

Comments
 (0)