Skip to content

Commit

Permalink
Make normalize_and_test_predicates into a query
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntPizza committed Dec 27, 2017
1 parent 63efff5 commit 766465f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Expand Up @@ -633,6 +633,8 @@ define_dep_nodes!( <'tcx>
[anon] NormalizeTy,
// We use this for most things when incr. comp. is turned off.
[] Null,

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

trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
Expand Down
23 changes: 20 additions & 3 deletions src/librustc/traits/mod.rs
Expand Up @@ -658,9 +658,9 @@ pub fn fully_normalize_with_fulfillcx<'a, 'gcx, 'tcx, T>(
/// environment. If this returns false, then either normalize
/// encountered an error or one of the predicates did not hold. Used
/// when creating vtables to check for unsatisfiable methods.
pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
predicates: Vec<ty::Predicate<'tcx>>)
-> bool
fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
predicates: Vec<ty::Predicate<'tcx>>)
-> bool
{
debug!("normalize_and_test_predicates(predicates={:?})",
predicates);
Expand All @@ -687,6 +687,22 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
result
}

fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
key: (DefId, &'tcx Substs<'tcx>))
-> bool
{
use ty::subst::Subst;
debug!("substitute_normalize_and_test_predicates(key={:?})",
key);

let predicates = tcx.predicates_of(key.0).predicates.subst(tcx, key.1);
let result = normalize_and_test_predicates(tcx, predicates);

debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}",
key, result);
result
}

/// Given a trait `trait_ref`, iterates the vtable entries
/// that come from `trait_ref`, including its supertraits.
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
Expand Down Expand Up @@ -879,6 +895,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
specializes: specialize::specializes,
trans_fulfill_obligation: trans::trans_fulfill_obligation,
vtable_methods,
substitute_normalize_and_test_predicates,
..*providers
};
}
6 changes: 6 additions & 0 deletions src/librustc/ty/maps/config.rs
Expand Up @@ -625,6 +625,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
fn describe(tcx: TyCtxt, key: (DefId, &'tcx Substs<'tcx>)) -> String {
format!("testing substituted normalized predicates:`{}`", tcx.item_path_str(key.0))
}
}

macro_rules! impl_disk_cacheable_query(
($query_name:ident, |$key:tt| $cond:expr) => {
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/ty/maps/mod.rs
Expand Up @@ -360,6 +360,9 @@ define_maps! { <'tcx>
// however, which uses this query as a kind of cache.
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
[] fn fully_normalize_monormophic_ty: normalize_ty_node(Ty<'tcx>) -> Ty<'tcx>,

[] fn substitute_normalize_and_test_predicates:
substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
}

//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -500,3 +503,8 @@ fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructo
fn normalize_ty_node<'tcx>(_: Ty<'tcx>) -> DepConstructor<'tcx> {
DepConstructor::NormalizeTy
}

fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
-> DepConstructor<'tcx> {
DepConstructor::SubstituteNormalizeAndTestPredicates { key }
}
1 change: 1 addition & 0 deletions src/librustc/ty/maps/plumbing.rs
Expand Up @@ -760,6 +760,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::VtableMethods |
DepKind::EraseRegionsTy |
DepKind::NormalizeTy |
DepKind::SubstituteNormalizeAndTestPredicates |

// This one should never occur in this context
DepKind::Null => {
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/monomorphize/item.rs
Expand Up @@ -18,9 +18,8 @@ use monomorphize::Instance;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::session::config::OptLevel;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::subst::{Subst, Substs};
use rustc::ty::subst::Substs;
use syntax::ast;
use syntax::attr::{self, InlineAttr};
use std::fmt::{self, Write};
Expand Down Expand Up @@ -214,8 +213,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
MonoItem::GlobalAsm(..) => return true
};

let predicates = tcx.predicates_of(def_id).predicates.subst(tcx, substs);
traits::normalize_and_test_predicates(tcx, predicates)
tcx.substitute_normalize_and_test_predicates((def_id, &substs))
}

fn to_string(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> String {
Expand Down

0 comments on commit 766465f

Please sign in to comment.