From 766465f0e5a64795c4fd92b31f497184b0aa61ae Mon Sep 17 00:00:00 2001 From: BurntPizza Date: Wed, 27 Dec 2017 12:32:44 -0500 Subject: [PATCH] Make normalize_and_test_predicates into a query --- src/librustc/dep_graph/dep_node.rs | 2 ++ src/librustc/traits/mod.rs | 23 ++++++++++++++++++++--- src/librustc/ty/maps/config.rs | 6 ++++++ src/librustc/ty/maps/mod.rs | 8 ++++++++ src/librustc/ty/maps/plumbing.rs | 1 + src/librustc_mir/monomorphize/item.rs | 6 ++---- 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 29839bb565bb4..ec52c6cf57bf7 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -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 { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 94605d895a554..fd47e09aad7f9 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -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>) - -> bool +fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, + predicates: Vec>) + -> bool { debug!("normalize_and_test_predicates(predicates={:?})", predicates); @@ -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. @@ -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 }; } diff --git a/src/librustc/ty/maps/config.rs b/src/librustc/ty/maps/config.rs index f2fe12dedc2ae..881c59e05aac6 100644 --- a/src/librustc/ty/maps/config.rs +++ b/src/librustc/ty/maps/config.rs @@ -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> { diff --git a/src/librustc/ty/maps/mod.rs b/src/librustc/ty/maps/mod.rs index 7c9d274e1fe06..bd8c22aab9316 100644 --- a/src/librustc/ty/maps/mod.rs +++ b/src/librustc/ty/maps/mod.rs @@ -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, } ////////////////////////////////////////////////////////////////////// @@ -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 } +} diff --git a/src/librustc/ty/maps/plumbing.rs b/src/librustc/ty/maps/plumbing.rs index ea71367d8852f..dd8b8a2e5da82 100644 --- a/src/librustc/ty/maps/plumbing.rs +++ b/src/librustc/ty/maps/plumbing.rs @@ -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 => { diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index c3fb126ea1822..07d6652355b75 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -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}; @@ -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 {