This commit is contained in:
Jack Huey 2021-01-04 01:58:33 -05:00
parent 876192e8cd
commit e76476afe4
11 changed files with 35 additions and 45 deletions

View File

@ -9,7 +9,7 @@ pub fn anonymize_predicate<'tcx>(
tcx: TyCtxt<'tcx>,
pred: ty::Predicate<'tcx>,
) -> ty::Predicate<'tcx> {
let new = tcx.anonymize_late_bound_regions(pred.kind());
let new = tcx.anonymize_late_bound_regions(pred.bound_atom());
tcx.reuse_or_mk_predicate(pred, new)
}

View File

@ -46,7 +46,7 @@ impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::Predicate<'tcx> {
type Variant = ty::Binder<ty::PredicateAtom<'tcx>>;
fn variant(&self) -> &Self::Variant {
self.kind_ref()
self.bound_atom_ref()
}
}

View File

@ -133,13 +133,13 @@ impl<'tcx> CtxtInterners<'tcx> {
}
#[inline(never)]
fn intern_predicate(&self, kind: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
fn intern_predicate(&self, binder: Binder<PredicateAtom<'tcx>>) -> &'tcx PredicateInner<'tcx> {
self.predicate
.intern(kind, |kind| {
let flags = super::flags::FlagComputation::for_predicate(kind);
.intern(binder, |binder| {
let flags = super::flags::FlagComputation::for_predicate(binder);
let predicate_struct = PredicateInner {
kind,
binder,
flags: flags.flags,
outer_exclusive_binder: flags.outer_exclusive_binder,
};
@ -1936,7 +1936,7 @@ impl<'tcx> Borrow<TyKind<'tcx>> for Interned<'tcx, TyS<'tcx>> {
// N.B., an `Interned<PredicateInner>` compares and hashes as a `PredicateKind`.
impl<'tcx> PartialEq for Interned<'tcx, PredicateInner<'tcx>> {
fn eq(&self, other: &Interned<'tcx, PredicateInner<'tcx>>) -> bool {
self.0.kind == other.0.kind
self.0.binder == other.0.binder
}
}
@ -1944,13 +1944,13 @@ impl<'tcx> Eq for Interned<'tcx, PredicateInner<'tcx>> {}
impl<'tcx> Hash for Interned<'tcx, PredicateInner<'tcx>> {
fn hash<H: Hasher>(&self, s: &mut H) {
self.0.kind.hash(s)
self.0.binder.hash(s)
}
}
impl<'tcx> Borrow<Binder<PredicateAtom<'tcx>>> for Interned<'tcx, PredicateInner<'tcx>> {
fn borrow<'a>(&'a self) -> &'a Binder<PredicateAtom<'tcx>> {
&self.0.kind
&self.0.binder
}
}
@ -2085,8 +2085,8 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline]
pub fn mk_predicate(self, kind: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
let inner = self.interners.intern_predicate(kind);
pub fn mk_predicate(self, binder: Binder<PredicateAtom<'tcx>>) -> Predicate<'tcx> {
let inner = self.interners.intern_predicate(binder);
Predicate { inner }
}
@ -2094,9 +2094,9 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn reuse_or_mk_predicate(
self,
pred: Predicate<'tcx>,
kind: Binder<PredicateAtom<'tcx>>,
binder: Binder<PredicateAtom<'tcx>>,
) -> Predicate<'tcx> {
if pred.kind() != kind { self.mk_predicate(kind) } else { pred }
if pred.bound_atom() != binder { self.mk_predicate(binder) } else { pred }
}
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {

View File

@ -22,9 +22,9 @@ impl FlagComputation {
result
}
pub fn for_predicate(kind: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
pub fn for_predicate(binder: ty::Binder<ty::PredicateAtom<'_>>) -> FlagComputation {
let mut result = FlagComputation::new();
result.add_predicate_kind(kind);
result.add_predicate(binder);
result
}
@ -204,7 +204,7 @@ impl FlagComputation {
}
}
fn add_predicate_kind(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
fn add_predicate(&mut self, binder: ty::Binder<ty::PredicateAtom<'_>>) {
self.bound_computation(binder, |computation, atom| computation.add_predicate_atom(atom));
}

View File

@ -1030,7 +1030,7 @@ impl<'tcx> GenericPredicates<'tcx> {
#[derive(Debug)]
crate struct PredicateInner<'tcx> {
kind: Binder<PredicateAtom<'tcx>>,
binder: Binder<PredicateAtom<'tcx>>,
flags: TypeFlags,
/// See the comment for the corresponding field of [TyS].
outer_exclusive_binder: ty::DebruijnIndex,
@ -1060,16 +1060,6 @@ impl Hash for Predicate<'_> {
impl<'tcx> Eq for Predicate<'tcx> {}
impl<'tcx> Predicate<'tcx> {
#[inline(always)]
pub fn kind(self) -> Binder<PredicateAtom<'tcx>> {
self.inner.kind
}
#[inline(always)]
pub fn kind_ref(&self) -> &Binder<PredicateAtom<'tcx>> {
&self.inner.kind
}
/// Returns the inner `PredicateAtom`.
///
/// The returned atom may contain unbound variables bound to binders skipped in this method.
@ -1077,8 +1067,7 @@ impl<'tcx> Predicate<'tcx> {
///
/// Note that this method panics in case this predicate has unbound variables.
pub fn skip_binders(self) -> PredicateAtom<'tcx> {
let binder = self.kind();
binder.skip_binder()
self.inner.binder.skip_binder()
}
/// Returns the inner `PredicateAtom`.
@ -1088,29 +1077,30 @@ impl<'tcx> Predicate<'tcx> {
/// Rebinding the returned atom can causes the previously bound variables
/// to end up at the wrong binding level.
pub fn skip_binders_unchecked(self) -> PredicateAtom<'tcx> {
let binder = self.kind();
binder.skip_binder()
self.inner.binder.skip_binder()
}
/// Converts this to a `Binder<PredicateAtom<'tcx>>`. If the value was an
/// `Atom`, then it is not allowed to contain escaping bound vars.
pub fn bound_atom(self) -> Binder<PredicateAtom<'tcx>> {
let binder = self.kind();
binder
self.inner.binder
}
pub fn bound_atom_ref(self) -> &'tcx Binder<PredicateAtom<'tcx>> {
&self.inner.binder
}
/// Allows using a `Binder<PredicateAtom<'tcx>>` even if the given predicate previously
/// contained unbound variables by shifting these variables outwards.
pub fn bound_atom_with_opt_escaping(self, _tcx: TyCtxt<'tcx>) -> Binder<PredicateAtom<'tcx>> {
let binder = self.kind();
binder
self.inner.binder
}
}
impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let PredicateInner {
ref kind,
ref binder,
// The other fields just provide fast access to information that is
// also contained in `kind`, so no need to hash them.
@ -1118,7 +1108,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
outer_exclusive_binder: _,
} = self.inner;
kind.hash_stable(hcx, hasher);
binder.hash_stable(hcx, hasher);
}
}

View File

@ -2068,7 +2068,7 @@ define_print_and_forward_display! {
}
ty::Predicate<'tcx> {
let binder = self.kind();
let binder = self.bound_atom();
p!(print(binder))
}

View File

@ -224,7 +224,7 @@ impl fmt::Debug for ty::ProjectionPredicate<'tcx> {
impl fmt::Debug for ty::Predicate<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self.kind())
write!(f, "{:?}", self.bound_atom())
}
}
@ -1017,12 +1017,12 @@ impl<'tcx> TypeFoldable<'tcx> for ty::Region<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for ty::Predicate<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
let new = self.inner.kind.fold_with(folder);
let new = self.inner.binder.fold_with(folder);
folder.tcx().reuse_or_mk_predicate(self, new)
}
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
self.inner.kind.super_visit_with(visitor)
self.inner.binder.visit_with(visitor)
}
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {

View File

@ -345,7 +345,7 @@ impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
let infcx = self.selcx.infcx();
let binder = obligation.predicate.kind();
let binder = obligation.predicate.bound_atom();
if binder.skip_binder().has_escaping_bound_vars() {
match binder.skip_binder() {
// Evaluation will discard candidates using the leak check.

View File

@ -94,7 +94,7 @@ fn compute_implied_outlives_bounds<'tcx>(
// region relationships.
implied_bounds.extend(obligations.into_iter().flat_map(|obligation| {
assert!(!obligation.has_escaping_bound_vars());
let binder = obligation.predicate.kind();
let binder = obligation.predicate.bound_atom();
if binder.skip_binder().has_escaping_bound_vars() {
vec![]
} else {

View File

@ -31,7 +31,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate
let mut pred: Vec<String> = predicates
.iter()
.map(|(out_pred, _)| {
let binder = out_pred.kind();
let binder = out_pred.bound_atom();
match binder.skip_binder() {
ty::PredicateAtom::RegionOutlives(p) => p.to_string(),
ty::PredicateAtom::TypeOutlives(p) => p.to_string(),

View File

@ -115,7 +115,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
.filter(|p| !p.is_global())
.filter_map(|obligation| {
// Note that we do not want to deal with qualified predicates here.
let binder = obligation.predicate.kind();
let binder = obligation.predicate.bound_atom();
match binder.skip_binder() {
ty::PredicateAtom::Trait(pred, _) if !binder.has_escaping_bound_vars() => {
if pred.def_id() == sized_trait {