Skip to content

Commit 9618da7

Browse files
committedOct 16, 2024
Auto merge of rust-lang#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 Gankra/thin-vec#66. This leads to a small (0.2-0.7%) performance gain in the latest perf run.
2 parents 9ce3675 + 8de8f46 commit 9618da7

File tree

43 files changed

+414
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+414
-255
lines changed
 

‎Cargo.lock

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is automatically @generated by Cargo.
22
# It is not intended for manual editing.
3-
version = 3
3+
version = 4
44

55
[[package]]
66
name = "addr2line"
@@ -3857,6 +3857,7 @@ dependencies = [
38573857
"rustc_target",
38583858
"rustc_type_ir",
38593859
"smallvec",
3860+
"thin-vec",
38603861
"tracing",
38613862
]
38623863

@@ -4496,6 +4497,7 @@ dependencies = [
44964497
"rustc_transmute",
44974498
"rustc_type_ir",
44984499
"smallvec",
4500+
"thin-vec",
44994501
"tracing",
45004502
]
45014503

@@ -4567,6 +4569,7 @@ dependencies = [
45674569
"rustc_span",
45684570
"rustc_type_ir_macros",
45694571
"smallvec",
4572+
"thin-vec",
45704573
"tracing",
45714574
]
45724575

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_infer::infer::region_constraints::RegionConstraintData;
1818
use rustc_infer::infer::{
1919
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
2020
};
21+
use rustc_infer::traits::PredicateObligations;
2122
use rustc_middle::mir::tcx::PlaceTy;
2223
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
2324
use rustc_middle::mir::*;
@@ -40,7 +41,6 @@ use rustc_span::source_map::Spanned;
4041
use rustc_span::symbol::sym;
4142
use rustc_span::{DUMMY_SP, Span};
4243
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
43-
use rustc_trait_selection::traits::PredicateObligation;
4444
use rustc_trait_selection::traits::query::type_op::custom::{
4545
CustomTypeOp, scrape_region_constraints,
4646
};
@@ -2940,7 +2940,7 @@ impl NormalizeLocation for Location {
29402940
pub(super) struct InstantiateOpaqueType<'tcx> {
29412941
pub base_universe: Option<ty::UniverseIndex>,
29422942
pub region_constraints: Option<RegionConstraintData<'tcx>>,
2943-
pub obligations: Vec<PredicateObligation<'tcx>>,
2943+
pub obligations: PredicateObligations<'tcx>,
29442944
}
29452945

29462946
impl<'tcx> TypeOp<'tcx> for InstantiateOpaqueType<'tcx> {

0 commit comments

Comments
 (0)