Skip to content

Commit ce7c48f

Browse files
committed
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 <david@davidtw.co>
1 parent c6ed442 commit ce7c48f

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

src/librustc_middle/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'tcx> MonoItem<'tcx> {
168168
MonoItem::GlobalAsm(..) => return true,
169169
};
170170

171-
tcx.substitute_normalize_and_test_predicates((def_id, &substs))
171+
!tcx.subst_and_check_impossible_predicates((def_id, &substs))
172172
}
173173

174174
pub fn to_string(&self, tcx: TyCtxt<'tcx>, debug: bool) -> String {

src/librustc_middle/query/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,9 @@ rustc_queries! {
14611461
desc { "normalizing `{:?}`", goal }
14621462
}
14631463

1464-
query substitute_normalize_and_test_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
1464+
query subst_and_check_impossible_predicates(key: (DefId, SubstsRef<'tcx>)) -> bool {
14651465
desc { |tcx|
1466-
"testing substituted normalized predicates:`{}`",
1466+
"impossible substituted predicates:`{}`",
14671467
tcx.def_path_str(key.0)
14681468
}
14691469
}

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
116116
.predicates
117117
.iter()
118118
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
119-
if !traits::normalize_and_test_predicates(
119+
if traits::impossible_predicates(
120120
tcx,
121121
traits::elaborate_predicates(tcx, predicates).map(|o| o.predicate).collect(),
122122
) {

src/librustc_trait_selection/traits/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,14 @@ where
418418
Ok(resolved_value)
419419
}
420420

421-
/// Normalizes the predicates and checks whether they hold in an empty
422-
/// environment. If this returns false, then either normalize
423-
/// encountered an error or one of the predicates did not hold. Used
424-
/// when creating vtables to check for unsatisfiable methods.
425-
pub fn normalize_and_test_predicates<'tcx>(
421+
/// Normalizes the predicates and checks whether they hold in an empty environment. If this
422+
/// returns true, then either normalize encountered an error or one of the predicates did not
423+
/// hold. Used when creating vtables to check for unsatisfiable methods.
424+
pub fn impossible_predicates<'tcx>(
426425
tcx: TyCtxt<'tcx>,
427426
predicates: Vec<ty::Predicate<'tcx>>,
428427
) -> bool {
429-
debug!("normalize_and_test_predicates(predicates={:?})", predicates);
428+
debug!("impossible_predicates(predicates={:?})", predicates);
430429

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

446-
fulfill_cx.select_all_or_error(&infcx).is_ok()
445+
fulfill_cx.select_all_or_error(&infcx).is_err()
447446
});
448-
debug!("normalize_and_test_predicates(predicates={:?}) = {:?}", predicates, result);
447+
debug!("impossible_predicates(predicates={:?}) = {:?}", predicates, result);
449448
result
450449
}
451450

452-
fn substitute_normalize_and_test_predicates<'tcx>(
451+
fn subst_and_check_impossible_predicates<'tcx>(
453452
tcx: TyCtxt<'tcx>,
454453
key: (DefId, SubstsRef<'tcx>),
455454
) -> bool {
456-
debug!("substitute_normalize_and_test_predicates(key={:?})", key);
455+
debug!("subst_and_check_impossible_predicates(key={:?})", key);
457456

458-
let predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
459-
let result = normalize_and_test_predicates(tcx, predicates);
457+
let mut predicates = tcx.predicates_of(key.0).instantiate(tcx, key.1).predicates;
458+
predicates.retain(|predicate| !predicate.needs_subst());
459+
let result = impossible_predicates(tcx, predicates);
460460

461-
debug!("substitute_normalize_and_test_predicates(key={:?}) = {:?}", key, result);
461+
debug!("subst_and_check_impossible_predicates(key={:?}) = {:?}", key, result);
462462
result
463463
}
464464

@@ -510,7 +510,7 @@ fn vtable_methods<'tcx>(
510510
// Note that this method could then never be called, so we
511511
// do not want to try and codegen it, in that case (see #23435).
512512
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
513-
if !normalize_and_test_predicates(tcx, predicates.predicates) {
513+
if impossible_predicates(tcx, predicates.predicates) {
514514
debug!("vtable_methods: predicates do not hold");
515515
return None;
516516
}
@@ -558,8 +558,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
558558
specializes: specialize::specializes,
559559
codegen_fulfill_obligation: codegen::codegen_fulfill_obligation,
560560
vtable_methods,
561-
substitute_normalize_and_test_predicates,
562561
type_implements_trait,
562+
subst_and_check_impossible_predicates,
563563
..*providers
564564
};
565565
}

src/tools/clippy/clippy_lints/src/utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,7 @@ pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool {
13461346
.predicates
13471347
.iter()
13481348
.filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None });
1349-
!traits::normalize_and_test_predicates(
1349+
traits::impossible_predicates(
13501350
cx.tcx,
13511351
traits::elaborate_predicates(cx.tcx, predicates)
13521352
.map(|o| o.predicate)

0 commit comments

Comments
 (0)