[ty] Use ThinVec for sub segments in PlaceExpr (#19470)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks-instrumented (push) Blocked by required conditions
CI / benchmarks-walltime (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

This commit is contained in:
Micha Reiser 2025-07-22 20:39:39 +02:00 committed by GitHub
parent 7673d46b71
commit dc10ab81bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 7 deletions

View file

@ -41,7 +41,16 @@ impl PlaceExprSubSegment {
#[derive(Eq, PartialEq, Debug, get_size2::GetSize)]
pub struct PlaceExpr {
root_name: Name,
sub_segments: SmallVec<[PlaceExprSubSegment; 1]>,
#[get_size(size_fn=sub_segments_size)]
sub_segments: thin_vec::ThinVec<PlaceExprSubSegment>,
}
fn sub_segments_size(segments: &thin_vec::ThinVec<PlaceExprSubSegment>) -> usize {
segments.capacity() * std::mem::size_of::<PlaceExprSubSegment>()
+ segments
.iter()
.map(get_size2::GetSize::get_heap_size)
.sum::<usize>()
}
impl std::fmt::Display for PlaceExpr {
@ -162,10 +171,10 @@ impl TryFrom<ast::ExprRef<'_>> for PlaceExpr {
}
impl PlaceExpr {
pub(crate) const fn name(name: Name) -> Self {
pub(crate) fn name(name: Name) -> Self {
Self {
root_name: name,
sub_segments: SmallVec::new_const(),
sub_segments: thin_vec::ThinVec::new(),
}
}
@ -652,6 +661,8 @@ pub struct PlaceTable {
impl PlaceTable {
fn shrink_to_fit(&mut self) {
self.places.shrink_to_fit();
self.place_set
.shrink_to_fit(|id| PlaceTable::hash_place_expr(&self.places[*id].expr));
}
pub(crate) fn place_expr(&self, place_id: impl Into<ScopedPlaceId>) -> &PlaceExprWithFlags {
@ -775,7 +786,7 @@ impl std::fmt::Debug for PlaceTable {
pub(super) struct PlaceTableBuilder {
table: PlaceTable,
associated_place_ids: IndexVec<ScopedPlaceId, Vec<ScopedPlaceId>>,
associated_place_ids: IndexVec<ScopedPlaceId, SmallVec<[ScopedPlaceId; 4]>>,
}
impl PlaceTableBuilder {
@ -794,14 +805,17 @@ impl PlaceTableBuilder {
let id = self.table.places.push(symbol);
entry.insert(id);
let new_id = self.associated_place_ids.push(vec![]);
let new_id = self.associated_place_ids.push(SmallVec::new_const());
debug_assert_eq!(new_id, id);
(id, true)
}
}
}
pub(super) fn add_place(&mut self, place_expr: PlaceExprWithFlags) -> (ScopedPlaceId, bool) {
pub(super) fn add_place(
&mut self,
mut place_expr: PlaceExprWithFlags,
) -> (ScopedPlaceId, bool) {
let hash = PlaceTable::hash_place_expr(&place_expr.expr);
let entry = self.table.place_set.entry(
hash,
@ -812,9 +826,10 @@ impl PlaceTableBuilder {
match entry {
Entry::Occupied(entry) => (*entry.get(), false),
Entry::Vacant(entry) => {
place_expr.expr.sub_segments.shrink_to_fit();
let id = self.table.places.push(place_expr);
entry.insert(id);
let new_id = self.associated_place_ids.push(vec![]);
let new_id = self.associated_place_ids.push(SmallVec::new_const());
debug_assert_eq!(new_id, id);
for root in self.table.places[id].expr.root_exprs() {
if let Some(root_id) = self.table.place_id_by_expr(root) {