Auto merge of #131422 - GnomedDev:smallvec-predicate-obligations, r=compiler-errors
Use `ThinVec` for PredicateObligation storage ~~I noticed while profiling clippy on a project that a large amount of time is being spent allocating `Vec`s for `PredicateObligation`, and the `Vec`s are often quite small. This is an attempt to optimise this by using SmallVec to avoid heap allocations for these common small Vecs.~~ This PR turns all the `Vec<PredicateObligation>` into a single type alias while avoiding referring to `Vec` around it, then swaps the type over to `ThinVec<PredicateObligation>` and fixes the fallout. This also contains an implementation of `ThinVec::extract_if`, copied from `Vec::extract_if` and currently being upstreamed to https://github.com/Gankra/thin-vec/pull/66. This leads to a small (0.2-0.7%) performance gain in the latest perf run.
This commit is contained in:
commit
9618da7c99
43 changed files with 414 additions and 255 deletions
|
@ -25,6 +25,7 @@ use rustc_span::{DUMMY_SP, Span};
|
|||
// FIXME: Remove this import and import via `solve::`
|
||||
pub use rustc_type_ir::solve::{BuiltinImplSource, Reveal};
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
|
||||
use crate::mir::ConstraintCategory;
|
||||
|
@ -625,14 +626,14 @@ pub enum ImplSource<'tcx, N> {
|
|||
/// for some type parameter. The `Vec<N>` represents the
|
||||
/// obligations incurred from normalizing the where-clause (if
|
||||
/// any).
|
||||
Param(Vec<N>),
|
||||
Param(ThinVec<N>),
|
||||
|
||||
/// Successful resolution for a builtin impl.
|
||||
Builtin(BuiltinImplSource, Vec<N>),
|
||||
Builtin(BuiltinImplSource, ThinVec<N>),
|
||||
}
|
||||
|
||||
impl<'tcx, N> ImplSource<'tcx, N> {
|
||||
pub fn nested_obligations(self) -> Vec<N> {
|
||||
pub fn nested_obligations(self) -> ThinVec<N> {
|
||||
match self {
|
||||
ImplSource::UserDefined(i) => i.nested,
|
||||
ImplSource::Param(n) | ImplSource::Builtin(_, n) => n,
|
||||
|
@ -686,7 +687,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
|
|||
pub struct ImplSourceUserDefinedData<'tcx, N> {
|
||||
pub impl_def_id: DefId,
|
||||
pub args: GenericArgsRef<'tcx>,
|
||||
pub nested: Vec<N>,
|
||||
pub nested: ThinVec<N>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue