Skip to content

Commit f49d3d9

Browse files
committed
store genericargs instead of tys
1 parent 33d8bc0 commit f49d3d9

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

‎compiler/rustc_type_ir/src/flags.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ impl<I: Interner> FlagComputation<I> {
470470

471471
ty::PredicateKind::Clause(ty::ClauseKind::CompressedTrait(c)) => {
472472
// NOTE: this is correct as long as compressed trait clauses represnt trait clauses
473-
// that don't have generic parameters, in which case only computing flags of the self_ty
474-
// is correct.
475-
self.add_args(&[c.self_ty.into()]);
473+
// that don't have generic parameters other than the self_ty, in which case only computing
474+
// flags of the self_ty is correct.
475+
self.add_args(c.self_ty.as_slice());
476476
}
477477
}
478478
}

‎compiler/rustc_type_ir/src/param_env.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod iterator {
115115
fn filter_compressed_trait_helper<I, T>(
116116
trait_filter: &T,
117117
cx: I,
118-
self_ty: I::Ty,
118+
self_ty: I::GenericArgs,
119119
trait_ref_single_bit: CompressedTraitRefs,
120120
) -> Option<Binder<I, TraitClause<I>>>
121121
where
@@ -144,7 +144,7 @@ mod iterator {
144144
decompression_in_progress: CompressedTraitRefs,
145145
// self ty of the currently decompression-in-progress trait ref,
146146
// if applicable.
147-
self_ty: Option<I::Ty>,
147+
self_ty: Option<I::GenericArgs>,
148148
}
149149

150150
impl<I, Iter, P, S, T, O> Iterator
@@ -198,7 +198,7 @@ mod iterator {
198198
}
199199
// If we find a compressed trait clause, and it matches, store it in `self.compressed_elem`
200200
ClauseKind::CompressedTrait(ct)
201-
if filter.self_type_filter.allow_self_ty(ct.self_ty)
201+
if filter.self_type_filter.allow_self_ty(ct.self_ty.type_at(0))
202202
&& filter
203203
.polarity_filter
204204
.allow_polarity(ClausePolarity::Positive) =>

‎compiler/rustc_type_ir/src/predicate.rs‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -856,11 +856,13 @@ impl CompressedTraitRefs {
856856
#[inline]
857857
pub fn trait_clause_from_def_id<I: Interner>(
858858
cx: I,
859-
self_ty: I::Ty,
859+
self_ty: I::GenericArgs,
860860
def_id: I::TraitId,
861861
) -> Binder<I, TraitClause<I>> {
862+
// Note that `self_ty` is a GenericArgs, but only contains a single
863+
// argument which is the trait's self_ty. This is done for perf.
862864
Binder::dummy(TraitClause {
863-
trait_ref: TraitRef::new(cx, def_id, [self_ty]),
865+
trait_ref: TraitRef::new_from_args(cx, def_id, self_ty),
864866
polarity: ClausePolarity::Positive,
865867
})
866868
}
@@ -869,7 +871,7 @@ impl CompressedTraitRefs {
869871
pub fn trait_clause_from_single_bit<I: Interner>(
870872
self,
871873
cx: I,
872-
self_ty: I::Ty,
874+
self_ty: I::GenericArgs,
873875
) -> Binder<I, TraitClause<I>> {
874876
Self::trait_clause_from_def_id(
875877
cx,
@@ -899,7 +901,12 @@ impl CompressedTraitRefs {
899901
derive(Encodable_NoContext, Decodable_NoContext, StableHash_NoContext)
900902
)]
901903
pub struct CompressedTraitClause<I: Interner> {
902-
pub self_ty: I::Ty,
904+
// Note: always only contains a single self ty.
905+
// Storing it as `GenericArgs` makes decompression faster.
906+
// Note that some of the folds and visits we do over compressed traits
907+
// ignore the trait ref and only recurses into self_ty. This is *incorrect*
908+
// if `self_ty` ever contained more than one generic arg.
909+
pub self_ty: I::GenericArgs,
903910

904911
#[type_foldable(identity)]
905912
#[type_visitable(ignore)]
@@ -932,7 +939,10 @@ impl<I: Interner> CompressedTraitClause<I> {
932939
let compressed_trait_refs =
933940
CompressedTraitRefs::from_lang_item(cx.as_trait_lang_item(trait_ref.def_id)?)?;
934941

935-
Some(Self { self_ty: trait_ref.self_ty(), compressed_trait_refs })
942+
// The args of the trait ref should *only* contain a self ty
943+
// when used in a compressed clause.
944+
debug_assert_eq!(trait_ref.args.len(), 1);
945+
Some(Self { self_ty: trait_ref.args, compressed_trait_refs })
936946
}
937947
ClauseKind::RegionOutlives(_) => None,
938948
ClauseKind::TypeOutlives(_) => None,

0 commit comments

Comments
 (0)