Skip to content

Commit 795594c

Browse files
committed
Auto merge of #47200 - BurntPizza:query-snatp, r=nikomatsakis
Make normalize_and_test_predicates into a query From #44891. I'm not real solid on how `dep_graph` stuff works, but if a node is going to have a key (again, not sure how important that is), then the key needs to be `Copy`. So since `normalize_and_test_predicates` only had one out-of-module use, I changed that call site to use a new function, `substitute_normalize_and_test_predicates` which is the query and enables having the arguments be `Copy`. Hopefully this makes sense. r? @nikomatsakis and/or @michaelwoerister
2 parents a29461f + 766465f commit 795594c

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

src/librustc/dep_graph/dep_node.rs

+2
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ define_dep_nodes!( <'tcx>
633633
[anon] NormalizeTy,
634634
// We use this for most things when incr. comp. is turned off.
635635
[] Null,
636+
637+
[] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) },
636638
);
637639

638640
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

src/librustc/traits/mod.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,9 @@ pub fn fully_normalize_with_fulfillcx<'a, 'gcx, 'tcx, T>(
658658
/// environment. If this returns false, then either normalize
659659
/// encountered an error or one of the predicates did not hold. Used
660660
/// when creating vtables to check for unsatisfiable methods.
661-
pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
662-
predicates: Vec<ty::Predicate<'tcx>>)
663-
-> bool
661+
fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
662+
predicates: Vec<ty::Predicate<'tcx>>)
663+
-> bool
664664
{
665665
debug!("normalize_and_test_predicates(predicates={:?})",
666666
predicates);
@@ -687,6 +687,22 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
687687
result
688688
}
689689

690+
fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
691+
key: (DefId, &'tcx Substs<'tcx>))
692+
-> bool
693+
{
694+
use ty::subst::Subst;
695+
debug!("substitute_normalize_and_test_predicates(key={:?})",
696+
key);
697+
698+
let predicates = tcx.predicates_of(key.0).predicates.subst(tcx, key.1);
699+
let result = normalize_and_test_predicates(tcx, predicates);
700+
701+
debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}",
702+
key, result);
703+
result
704+
}
705+
690706
/// Given a trait `trait_ref`, iterates the vtable entries
691707
/// that come from `trait_ref`, including its supertraits.
692708
#[inline] // FIXME(#35870) Avoid closures being unexported due to impl Trait.
@@ -879,6 +895,7 @@ pub fn provide(providers: &mut ty::maps::Providers) {
879895
specializes: specialize::specializes,
880896
trans_fulfill_obligation: trans::trans_fulfill_obligation,
881897
vtable_methods,
898+
substitute_normalize_and_test_predicates,
882899
..*providers
883900
};
884901
}

src/librustc/ty/maps/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> {
625625
}
626626
}
627627

628+
impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> {
629+
fn describe(tcx: TyCtxt, key: (DefId, &'tcx Substs<'tcx>)) -> String {
630+
format!("testing substituted normalized predicates:`{}`", tcx.item_path_str(key.0))
631+
}
632+
}
633+
628634
macro_rules! impl_disk_cacheable_query(
629635
($query_name:ident, |$key:tt| $cond:expr) => {
630636
impl<'tcx> QueryDescription<'tcx> for queries::$query_name<'tcx> {

src/librustc/ty/maps/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ define_maps! { <'tcx>
360360
// however, which uses this query as a kind of cache.
361361
[] fn erase_regions_ty: erase_regions_ty(Ty<'tcx>) -> Ty<'tcx>,
362362
[] fn fully_normalize_monormophic_ty: normalize_ty_node(Ty<'tcx>) -> Ty<'tcx>,
363+
364+
[] fn substitute_normalize_and_test_predicates:
365+
substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool,
363366
}
364367

365368
//////////////////////////////////////////////////////////////////////
@@ -500,3 +503,8 @@ fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructo
500503
fn normalize_ty_node<'tcx>(_: Ty<'tcx>) -> DepConstructor<'tcx> {
501504
DepConstructor::NormalizeTy
502505
}
506+
507+
fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>))
508+
-> DepConstructor<'tcx> {
509+
DepConstructor::SubstituteNormalizeAndTestPredicates { key }
510+
}

src/librustc/ty/maps/plumbing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
760760
DepKind::VtableMethods |
761761
DepKind::EraseRegionsTy |
762762
DepKind::NormalizeTy |
763+
DepKind::SubstituteNormalizeAndTestPredicates |
763764

764765
// This one should never occur in this context
765766
DepKind::Null => {

src/librustc_mir/monomorphize/item.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ use monomorphize::Instance;
1818
use rustc::hir;
1919
use rustc::hir::def_id::DefId;
2020
use rustc::session::config::OptLevel;
21-
use rustc::traits;
2221
use rustc::ty::{self, Ty, TyCtxt};
23-
use rustc::ty::subst::{Subst, Substs};
22+
use rustc::ty::subst::Substs;
2423
use syntax::ast;
2524
use syntax::attr::{self, InlineAttr};
2625
use std::fmt::{self, Write};
@@ -214,8 +213,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug {
214213
MonoItem::GlobalAsm(..) => return true
215214
};
216215

217-
let predicates = tcx.predicates_of(def_id).predicates.subst(tcx, substs);
218-
traits::normalize_and_test_predicates(tcx, predicates)
216+
tcx.substitute_normalize_and_test_predicates((def_id, &substs))
219217
}
220218

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

0 commit comments

Comments
 (0)