Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
trait_sel: only test predicates w/ no substs
This commit modifies the `substitute_normalize_and_test_predicates`
query, renaming it to `impossible_predicates` and only checking
predicates which do not require substs. By making this change,
polymorphization doesn't have to explicitly support vtables.

Signed-off-by: David Wood <[email protected]>
  • Loading branch information
davidtwco committed Jul 20, 2020
commit ce7c48fa156a4641d2f89a20e9e14cc050b40388
2 changes: 1 addition & 1 deletion src/librustc_middle/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<'tcx> MonoItem<'tcx> {
MonoItem::GlobalAsm(..) => return true,
};

tcx.substitute_normalize_and_test_predicates((def_id, &substs))
!tcx.subst_and_check_impossible_predicates((def_id, &substs))
}

pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1461,9 +1461,9 @@ rustc_queries! {
desc { "normalizing `{:?}`", goal }
}

query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
desc { |tcx|
"testing substituted normalized predicates:`{}`",
"impossible substituted predicates:`{}`",
tcx.def_path_str(key.0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
if !traits::normalize_and_test_predicates(
if traits::impossible_predicates(
tcx,
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
) {
Expand Down
30 changes: 15 additions & 15 deletions src/librustc_trait_selection/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,14 @@ where
Ok(resolved_value)
}

/// Normalizes the predicates and checks whether they hold in an empty
/// 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<'tcx>(
/// Normalizes the predicates and checks whether they hold in an empty environment. If this
/// returns true, 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 impossible_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: Vec<ty::Predicate<'tcx>>,
) -> bool {
debug!("normalize_and_test_predicates(predicates={:?})", predicates);
debug!("impossible_predicates(predicates={:?})", predicates);

let result = tcx.infer_ctxt().enter(|infcx| {
let param_env = ty::ParamEnv::reveal_all();
Expand All @@ -443,22 +442,23 @@ pub fn normalize_and_test_predicates<'tcx>(
fulfill_cx.register_predicate_obligation(&infcx, obligation);
}

fulfill_cx.select_all_or_error(&infcx).is_ok()
fulfill_cx.select_all_or_error(&infcx).is_err()
});
debug!("normalize_and_test_predicates(predicates={:?}) = {:?}", predicates, result);
debug!("impossible_predicates(predicates={:?}) = {:?}", predicates, result);
result
}

fn substitute_normalize_and_test_predicates<'tcx>(
fn subst_and_check_impossible_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
key: (DefId, SubstsRef<'tcx>),
) -> bool {
debug!("substitute_normalize_and_test_predicates(key={:?})", key);
debug!("subst_and_check_impossible_predicates(key={:?})", key);

let predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
let result = normalize_and_test_predicates(tcx, predicates);
let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
predicates.retain(|predicate| !predicate.needs_subst());
let result = impossible_predicates(tcx, predicates);

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

Expand Down Expand Up @@ -510,7 +510,7 @@ fn vtable_methods<'tcx>(
// Note that this method could then never be called, so we
// do not want to try and codegen it, in that case (see #23435).
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
if !normalize_and_test_predicates(tcx, predicates.predicates) {
if impossible_predicates(tcx, predicates.predicates) {
debug!("vtable_methods: predicates do not hold");
return None;
}
Expand Down Expand Up @@ -558,8 +558,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
specializes: specialize::specializes,
codegen_fulfill_obligation: codegen::codegen_fulfill_obligation,
vtable_methods,
substitute_normalize_and_test_predicates,
type_implements_trait,
subst_and_check_impossible_predicates,
..*providers
};
}
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
.predicates
.iter()
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
!traits::normalize_and_test_predicates(
traits::impossible_predicates(
cx.tcx,
traits::elaborate_predicates(cx.tcx, predicates)
.map(|o| o.predicate)
Expand Down