Remove some allocs

This commit is contained in:
Lukas Wirth 2024-04-06 13:40:15 +02:00
parent 13890697eb
commit 336dee3415
2 changed files with 16 additions and 16 deletions

View File

@ -603,15 +603,17 @@ pub enum ImplTraitId {
} }
impl_intern_value_trivial!(ImplTraitId); impl_intern_value_trivial!(ImplTraitId);
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(PartialEq, Eq, Debug, Hash)]
pub struct ImplTraits { pub struct ImplTraits {
pub(crate) impl_traits: Arena<ImplTrait>, pub(crate) impl_traits: Arena<ImplTrait>,
} }
has_interner!(ImplTraits); has_interner!(ImplTraits);
#[derive(Clone, PartialEq, Eq, Debug, Hash)] #[derive(PartialEq, Eq, Debug, Hash)]
pub struct ImplTrait { pub struct ImplTrait {
// FIXME: Should be Arc<[QuantifiedWhereClause]>, but the HasInterner impl for Arc is missing a
// ?Sized bound
pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>, pub(crate) bounds: Binders<Vec<QuantifiedWhereClause>>,
} }

View File

@ -316,7 +316,7 @@ pub fn lower_ty_ext(&self, type_ref: &TypeRef) -> (Ty, Option<TypeNs>) {
// place even if we encounter more opaque types while // place even if we encounter more opaque types while
// lowering the bounds // lowering the bounds
let idx = opaque_type_data.borrow_mut().alloc(ImplTrait { let idx = opaque_type_data.borrow_mut().alloc(ImplTrait {
bounds: crate::make_single_type_binders(Vec::new()), bounds: crate::make_single_type_binders(Vec::default()),
}); });
// We don't want to lower the bounds inside the binders // We don't want to lower the bounds inside the binders
// we're currently in, because they don't end up inside // we're currently in, because they don't end up inside
@ -1007,11 +1007,11 @@ fn trait_ref_substs_from_path(
self.substs_from_path_segment(segment, Some(resolved.into()), false, explicit_self_ty) self.substs_from_path_segment(segment, Some(resolved.into()), false, explicit_self_ty)
} }
pub(crate) fn lower_where_predicate( pub(crate) fn lower_where_predicate<'b>(
&self, &'b self,
where_predicate: &WherePredicate, where_predicate: &'b WherePredicate,
ignore_bindings: bool, ignore_bindings: bool,
) -> impl Iterator<Item = QuantifiedWhereClause> { ) -> impl Iterator<Item = QuantifiedWhereClause> + 'b {
match where_predicate { match where_predicate {
WherePredicate::ForLifetime { target, bound, .. } WherePredicate::ForLifetime { target, bound, .. }
| WherePredicate::TypeBound { target, bound } => { | WherePredicate::TypeBound { target, bound } => {
@ -1034,18 +1034,16 @@ pub(crate) fn lower_where_predicate(
.intern(Interner) .intern(Interner)
} }
}; };
self.lower_type_bound(bound, self_ty, ignore_bindings) Either::Left(self.lower_type_bound(bound, self_ty, ignore_bindings))
.collect::<Vec<_>>()
.into_iter()
} }
WherePredicate::Lifetime { bound, target } => { WherePredicate::Lifetime { bound, target } => Either::Right(iter::once(
vec![crate::wrap_empty_binders(WhereClause::LifetimeOutlives(LifetimeOutlives { crate::wrap_empty_binders(WhereClause::LifetimeOutlives(LifetimeOutlives {
a: self.lower_lifetime(bound), a: self.lower_lifetime(bound),
b: self.lower_lifetime(target), b: self.lower_lifetime(target),
}))] })),
.into_iter() )),
}
} }
.into_iter()
} }
pub(crate) fn lower_type_bound( pub(crate) fn lower_type_bound(
@ -1380,8 +1378,8 @@ fn lower_impl_trait(&self, bounds: &[Interned<TypeBound>], krate: CrateId) -> Im
crate::wrap_empty_binders(clause) crate::wrap_empty_binders(clause)
}); });
predicates.extend(sized_clause); predicates.extend(sized_clause);
predicates.shrink_to_fit();
} }
predicates.shrink_to_fit();
predicates predicates
}); });
ImplTrait { bounds: crate::make_single_type_binders(predicates) } ImplTrait { bounds: crate::make_single_type_binders(predicates) }