Skip to content

Commit 8b8d01e

Browse files
Migrate caller bounds and predicates_of
1 parent 020c36e commit 8b8d01e

File tree

38 files changed

+162
-230
lines changed

38 files changed

+162
-230
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ dependencies = [
6767

6868
[[package]]
6969
name = "allocator-api2"
70-
version = "0.2.14"
70+
version = "0.2.15"
7171
source = "registry+https://github.com/rust-lang/crates.io-index"
72-
checksum = "c4f263788a35611fba42eb41ff811c5d0360c58b97402570312a350736e2542e"
72+
checksum = "56fc6cf8dc8c4158eed8649f9b8b0ea1518eb62b544fe9490d66fa0b349eafe9"
7373

7474
[[package]]
7575
name = "ammonia"

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn compare_method_predicate_entailment<'tcx>(
220220
// the new hybrid bounds we computed.
221221
let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id);
222222
let param_env = ty::ParamEnv::new(
223-
tcx.mk_predicates(&hybrid_preds.predicates),
223+
tcx.mk_clauses(&hybrid_preds.predicates),
224224
Reveal::UserFacing,
225225
hir::Constness::NotConst,
226226
);
@@ -1835,7 +1835,7 @@ fn compare_type_predicate_entailment<'tcx>(
18351835
let impl_ty_span = tcx.def_span(impl_ty_def_id);
18361836
let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_def_id);
18371837
let param_env = ty::ParamEnv::new(
1838-
tcx.mk_predicates(&hybrid_preds.predicates),
1838+
tcx.mk_clauses(&hybrid_preds.predicates),
18391839
Reveal::UserFacing,
18401840
hir::Constness::NotConst,
18411841
);
@@ -2011,7 +2011,7 @@ pub(super) fn check_type_bounds<'tcx>(
20112011
.to_predicate(tcx),
20122012
),
20132013
};
2014-
ty::ParamEnv::new(tcx.mk_predicates(&predicates), Reveal::UserFacing, param_env.constness())
2014+
ty::ParamEnv::new(tcx.mk_clauses(&predicates), Reveal::UserFacing, param_env.constness())
20152015
};
20162016
debug!(?normalize_param_env);
20172017

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ fn augment_param_env<'tcx>(
498498
return param_env;
499499
}
500500

501-
let bounds = tcx.mk_predicates_from_iter(
501+
let bounds = tcx.mk_clauses_from_iter(
502502
param_env.caller_bounds().iter().chain(new_predicates.iter().cloned()),
503503
);
504504
// FIXME(compiler-errors): Perhaps there is a case where we need to normalize this

compiler/rustc_infer/src/infer/outlives/mod.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,18 @@ pub fn explicit_outlives_bounds<'tcx>(
2020
param_env
2121
.caller_bounds()
2222
.into_iter()
23-
.map(ty::Predicate::kind)
23+
.map(ty::Clause::kind)
2424
.filter_map(ty::Binder::no_bound_vars)
2525
.filter_map(move |kind| match kind {
26-
ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
27-
| ty::PredicateKind::Clause(ty::ClauseKind::Trait(..))
28-
| ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
29-
| ty::PredicateKind::AliasRelate(..)
30-
| ty::PredicateKind::Coerce(..)
31-
| ty::PredicateKind::Subtype(..)
32-
| ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
33-
| ty::PredicateKind::ObjectSafe(..)
34-
| ty::PredicateKind::ClosureKind(..)
35-
| ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
36-
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
37-
| ty::PredicateKind::ConstEquate(..)
38-
| ty::PredicateKind::Ambiguous
39-
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
40-
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(
41-
r_a,
42-
r_b,
43-
))) => Some(OutlivesBound::RegionSubRegion(r_b, r_a)),
26+
ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r_a, r_b)) => {
27+
Some(OutlivesBound::RegionSubRegion(r_b, r_a))
28+
}
29+
ty::ClauseKind::Trait(_)
30+
| ty::ClauseKind::TypeOutlives(_)
31+
| ty::ClauseKind::Projection(_)
32+
| ty::ClauseKind::ConstArgHasType(_, _)
33+
| ty::ClauseKind::WellFormed(_)
34+
| ty::ClauseKind::ConstEvaluatable(_) => None,
4435
})
4536
}
4637

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
223223
// parameter environments are already elaborated, so we don't
224224
// have to worry about that.
225225
let c_b = self.param_env.caller_bounds();
226-
let param_bounds = self.collect_outlives_from_predicate_list(erased_ty, c_b.into_iter());
226+
let param_bounds = self.collect_outlives_from_clause_list(erased_ty, c_b.into_iter());
227227

228228
// Next, collect regions we scraped from the well-formedness
229229
// constraints in the fn signature. To do that, we walk the list
@@ -307,15 +307,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
307307
/// when comparing `ty` for equality, so `ty` must be something
308308
/// that does not involve inference variables and where you
309309
/// otherwise want a precise match.
310-
fn collect_outlives_from_predicate_list(
310+
fn collect_outlives_from_clause_list(
311311
&self,
312312
erased_ty: Ty<'tcx>,
313-
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
313+
clauses: impl Iterator<Item = ty::Clause<'tcx>>,
314314
) -> impl Iterator<Item = ty::Binder<'tcx, ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>>>>
315315
{
316316
let tcx = self.tcx;
317317
let param_env = self.param_env;
318-
predicates.filter_map(|p| p.to_opt_type_outlives()).filter(move |outlives_predicate| {
318+
clauses.filter_map(|p| p.as_type_outlives_clause()).filter(move |outlives_predicate| {
319319
super::test_type_match::can_match_erased_ty(
320320
tcx,
321321
param_env,

compiler/rustc_infer/src/traits/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
258258
pred = pred.without_const(tcx);
259259
}
260260
elaboratable.child_with_derived_cause(
261-
pred.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref)),
261+
pred.subst_supertrait(tcx, &bound_predicate.rebind(data.trait_ref))
262+
.as_predicate(),
262263
span,
263264
bound_predicate.rebind(data),
264265
index,
@@ -440,7 +441,7 @@ pub fn transitive_bounds_that_define_assoc_item<'tcx>(
440441
tcx.super_predicates_that_define_assoc_item((trait_ref.def_id(), assoc_name));
441442
for (super_predicate, _) in super_predicates.predicates {
442443
let subst_predicate = super_predicate.subst_supertrait(tcx, &trait_ref);
443-
if let Some(binder) = subst_predicate.to_opt_poly_trait_pred() {
444+
if let Some(binder) = subst_predicate.as_trait_clause() {
444445
stack.push(binder.map_bound(|t| t.trait_ref));
445446
}
446447
}

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,12 +636,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Symbol {
636636
}
637637
}
638638

639-
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] {
640-
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Self {
641-
ty::codec::RefDecodable::decode(d)
642-
}
643-
}
644-
645639
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [(ty::Clause<'tcx>, Span)] {
646640
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Self {
647641
ty::codec::RefDecodable::decode(d)

compiler/rustc_middle/src/query/keys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'tcx> Key for (Ty<'tcx>, Ty<'tcx>) {
420420
}
421421
}
422422

423-
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
423+
impl<'tcx> Key for &'tcx ty::List<ty::Clause<'tcx>> {
424424
type CacheSelector = DefaultCacheSelector<Self>;
425425

426426
fn default_span(&self, _: TyCtxt<'_>) -> Span {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ rustc_queries! {
21122112
desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) }
21132113
}
21142114

2115-
query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Predicate<'tcx>>) -> &'tcx ty::List<ty::Predicate<'tcx>> {
2115+
query reveal_opaque_types_in_bounds(key: &'tcx ty::List<ty::Clause<'tcx>>) -> &'tcx ty::List<ty::Clause<'tcx>> {
21162116
desc { "revealing opaque types in `{:?}`", key }
21172117
}
21182118

compiler/rustc_middle/src/query/on_disk_cache.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,6 @@ impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>>
791791
}
792792
}
793793

794-
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] {
795-
#[inline]
796-
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {
797-
RefDecodable::decode(d)
798-
}
799-
}
800-
801794
impl<'a, 'tcx> Decodable<CacheDecoder<'a, 'tcx>> for &'tcx [(ty::Clause<'tcx>, Span)] {
802795
#[inline]
803796
fn decode(d: &mut CacheDecoder<'a, 'tcx>) -> Self {

compiler/rustc_middle/src/traits/chalk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {
385385
/// A chalk environment and goal.
386386
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, TypeVisitable)]
387387
pub struct ChalkEnvironmentAndGoal<'tcx> {
388-
pub environment: &'tcx ty::List<ty::Predicate<'tcx>>,
388+
pub environment: &'tcx ty::List<ty::Clause<'tcx>>,
389389
pub goal: ty::Predicate<'tcx>,
390390
}
391391

compiler/rustc_middle/src/traits/util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ impl<'tcx> Elaborator<'tcx> {
2525
.super_predicates_of(trait_ref.def_id())
2626
.predicates
2727
.into_iter()
28-
.flat_map(|(pred, _)| {
29-
pred.subst_supertrait(self.tcx, &trait_ref).to_opt_poly_trait_pred()
30-
})
28+
.flat_map(|(pred, _)| pred.subst_supertrait(self.tcx, &trait_ref).as_trait_clause())
3129
.map(|t| t.map_bound(|pred| pred.trait_ref))
3230
.filter(|supertrait_ref| self.visited.insert(*supertrait_ref));
3331

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty
416416
}
417417
}
418418

419-
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::Predicate<'tcx>> {
419+
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::Clause<'tcx>> {
420420
fn decode(decoder: &mut D) -> &'tcx Self {
421421
let len = decoder.read_usize();
422-
decoder.interner().mk_predicates_from_iter(
423-
(0..len).map::<ty::Predicate<'tcx>, _>(|_| Decodable::decode(decoder)),
422+
decoder.interner().mk_clauses_from_iter(
423+
(0..len).map::<ty::Clause<'tcx>, _>(|_| Decodable::decode(decoder)),
424424
)
425425
}
426426
}
@@ -444,7 +444,7 @@ impl_decodable_via_ref! {
444444
&'tcx mir::BorrowCheckResult<'tcx>,
445445
&'tcx mir::coverage::CodeRegion,
446446
&'tcx ty::List<ty::BoundVariableKind>,
447-
&'tcx ty::List<ty::Predicate<'tcx>>,
447+
&'tcx ty::List<ty::Clause<'tcx>>,
448448
&'tcx ty::List<FieldIdx>,
449449
}
450450

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ pub struct CtxtInterners<'tcx> {
141141
region: InternedSet<'tcx, RegionKind<'tcx>>,
142142
poly_existential_predicates: InternedSet<'tcx, List<PolyExistentialPredicate<'tcx>>>,
143143
predicate: InternedSet<'tcx, WithCachedTypeInfo<ty::Binder<'tcx, PredicateKind<'tcx>>>>,
144-
// FIXME: remove this when all usages are moved to predicate
145-
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
146144
clauses: InternedSet<'tcx, List<Clause<'tcx>>>,
147145
projs: InternedSet<'tcx, List<ProjectionKind>>,
148146
place_elems: InternedSet<'tcx, List<PlaceElem<'tcx>>>,
@@ -168,7 +166,6 @@ impl<'tcx> CtxtInterners<'tcx> {
168166
poly_existential_predicates: Default::default(),
169167
canonical_var_infos: Default::default(),
170168
predicate: Default::default(),
171-
predicates: Default::default(),
172169
clauses: Default::default(),
173170
projs: Default::default(),
174171
place_elems: Default::default(),
@@ -1254,10 +1251,11 @@ nop_lift! {region; Region<'a> => Region<'tcx>}
12541251
nop_lift! {const_; Const<'a> => Const<'tcx>}
12551252
nop_lift! {const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx>}
12561253
nop_lift! {predicate; Predicate<'a> => Predicate<'tcx>}
1254+
nop_lift! {predicate; Clause<'a> => Clause<'tcx>}
12571255

12581256
nop_list_lift! {type_lists; Ty<'a> => Ty<'tcx>}
12591257
nop_list_lift! {poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>}
1260-
nop_list_lift! {predicates; Predicate<'a> => Predicate<'tcx>}
1258+
nop_list_lift! {clauses; Clause<'a> => Clause<'tcx>}
12611259
nop_list_lift! {canonical_var_infos; CanonicalVarInfo<'a> => CanonicalVarInfo<'tcx>}
12621260
nop_list_lift! {projs; ProjectionKind => ProjectionKind}
12631261
nop_list_lift! {bound_variable_kinds; ty::BoundVariableKind => ty::BoundVariableKind}
@@ -1535,7 +1533,6 @@ slice_interners!(
15351533
type_lists: pub mk_type_list(Ty<'tcx>),
15361534
canonical_var_infos: pub mk_canonical_var_infos(CanonicalVarInfo<'tcx>),
15371535
poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>),
1538-
predicates: intern_predicates(Predicate<'tcx>),
15391536
clauses: intern_clauses(Clause<'tcx>),
15401537
projs: pub mk_projs(ProjectionKind),
15411538
place_elems: pub mk_place_elems(PlaceElem<'tcx>),
@@ -1591,9 +1588,7 @@ impl<'tcx> TyCtxt<'tcx> {
15911588
let generic_predicates = self.super_predicates_of(trait_did);
15921589

15931590
for (predicate, _) in generic_predicates.predicates {
1594-
if let ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) =
1595-
predicate.kind().skip_binder()
1596-
{
1591+
if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() {
15971592
if set.insert(data.def_id()) {
15981593
stack.push(data.def_id());
15991594
}
@@ -2081,13 +2076,6 @@ impl<'tcx> TyCtxt<'tcx> {
20812076
self.intern_poly_existential_predicates(eps)
20822077
}
20832078

2084-
pub fn mk_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List<Predicate<'tcx>> {
2085-
// FIXME consider asking the input slice to be sorted to avoid
2086-
// re-interning permutations, in which case that would be asserted
2087-
// here.
2088-
self.intern_predicates(preds)
2089-
}
2090-
20912079
pub fn mk_clauses(self, preds: &[Clause<'tcx>]) -> &'tcx List<Clause<'tcx>> {
20922080
// FIXME consider asking the input slice to be sorted to avoid
20932081
// re-interning permutations, in which case that would be asserted
@@ -2138,14 +2126,6 @@ impl<'tcx> TyCtxt<'tcx> {
21382126
T::collect_and_apply(iter, |xs| self.mk_poly_existential_predicates(xs))
21392127
}
21402128

2141-
pub fn mk_predicates_from_iter<I, T>(self, iter: I) -> T::Output
2142-
where
2143-
I: Iterator<Item = T>,
2144-
T: CollectAndApply<Predicate<'tcx>, &'tcx List<Predicate<'tcx>>>,
2145-
{
2146-
T::collect_and_apply(iter, |xs| self.mk_predicates(xs))
2147-
}
2148-
21492129
pub fn mk_clauses_from_iter<I, T>(self, iter: I) -> T::Output
21502130
where
21512131
I: Iterator<Item = T>,

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::DefId;
66
use rustc_span::symbol::{kw, Symbol};
77
use rustc_span::Span;
88

9-
use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predicate, TyCtxt};
9+
use super::{Clause, EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, TyCtxt};
1010

1111
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
1212
pub enum GenericParamDefKind {
@@ -323,7 +323,7 @@ impl<'tcx> Generics {
323323
#[derive(Copy, Clone, Default, Debug, TyEncodable, TyDecodable, HashStable)]
324324
pub struct GenericPredicates<'tcx> {
325325
pub parent: Option<DefId>,
326-
pub predicates: &'tcx [(Predicate<'tcx>, Span)],
326+
pub predicates: &'tcx [(Clause<'tcx>, Span)],
327327
}
328328

329329
impl<'tcx> GenericPredicates<'tcx> {
@@ -341,8 +341,7 @@ impl<'tcx> GenericPredicates<'tcx> {
341341
&self,
342342
tcx: TyCtxt<'tcx>,
343343
substs: SubstsRef<'tcx>,
344-
) -> impl Iterator<Item = (Predicate<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator
345-
{
344+
) -> impl Iterator<Item = (Clause<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator {
346345
EarlyBinder::bind(self.predicates).subst_iter_copied(tcx, substs)
347346
}
348347

0 commit comments

Comments
 (0)