Skip to content

Commit f5d7d34

Browse files
committed
Remove TinyList.
It is optimized for lists with a single element, avoiding the need for an allocation in that case. But `SmallVec<[T; 1]>` also avoids the allocation, and is better in general: more standard, log2 number of allocations if the list exceeds one item, and a much more capable API. This commit removes `TinyList` and converts the two uses to `SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant file so they are in just two sections (`pub` and non-`pub`), ordered alphabetically, instead of many sections. (This is a relevant part of the change because I had to decide where to add a `use` item for `SmallVec`.)
1 parent d7814e7 commit f5d7d34

File tree

4 files changed

+8
-245
lines changed

4 files changed

+8
-245
lines changed

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ pub mod svh;
8282
pub mod sync;
8383
pub mod tagged_ptr;
8484
pub mod temp_dir;
85-
pub mod tiny_list;
8685
pub mod transitive_relation;
8786
pub mod unhash;
8887
pub mod unord;

compiler/rustc_data_structures/src/tiny_list.rs

-80
This file was deleted.

compiler/rustc_data_structures/src/tiny_list/tests.rs

-155
This file was deleted.

compiler/rustc_middle/src/mir/interpret/mod.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ use std::io::{Read, Write};
125125
use std::num::NonZero;
126126
use std::sync::atomic::{AtomicU32, Ordering};
127127

128+
use smallvec::{smallvec, SmallVec};
129+
128130
use rustc_ast::LitKind;
129131
use rustc_data_structures::fx::FxHashMap;
130132
use rustc_data_structures::sync::{HashMapExt, Lock};
131-
use rustc_data_structures::tiny_list::TinyList;
132133
use rustc_errors::ErrorGuaranteed;
133134
use rustc_hir::def_id::{DefId, LocalDefId};
134135
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
@@ -266,8 +267,8 @@ type DecodingSessionId = NonZero<u32>;
266267
#[derive(Clone)]
267268
enum State {
268269
Empty,
269-
InProgressNonAlloc(TinyList<DecodingSessionId>),
270-
InProgress(TinyList<DecodingSessionId>, AllocId),
270+
InProgressNonAlloc(SmallVec<[DecodingSessionId; 1]>),
271+
InProgress(SmallVec<[DecodingSessionId; 1]>, AllocId),
271272
Done(AllocId),
272273
}
273274

@@ -337,17 +338,15 @@ impl<'s> AllocDecodingSession<'s> {
337338
// If this is an allocation, we need to reserve an
338339
// `AllocId` so we can decode cyclic graphs.
339340
let alloc_id = decoder.interner().reserve_alloc_id();
340-
*entry =
341-
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
341+
*entry = State::InProgress(smallvec![self.session_id], alloc_id);
342342
Some(alloc_id)
343343
}
344344
AllocDiscriminant::Fn
345345
| AllocDiscriminant::Static
346346
| AllocDiscriminant::VTable => {
347347
// Fns and statics cannot be cyclic, and their `AllocId`
348348
// is determined later by interning.
349-
*entry =
350-
State::InProgressNonAlloc(TinyList::new_single(self.session_id));
349+
*entry = State::InProgressNonAlloc(smallvec![self.session_id]);
351350
None
352351
}
353352
}
@@ -357,7 +356,7 @@ impl<'s> AllocDecodingSession<'s> {
357356
bug!("this should be unreachable");
358357
} else {
359358
// Start decoding concurrently.
360-
sessions.insert(self.session_id);
359+
sessions.push(self.session_id);
361360
None
362361
}
363362
}
@@ -367,7 +366,7 @@ impl<'s> AllocDecodingSession<'s> {
367366
return alloc_id;
368367
} else {
369368
// Start decoding concurrently.
370-
sessions.insert(self.session_id);
369+
sessions.push(self.session_id);
371370
Some(alloc_id)
372371
}
373372
}

0 commit comments

Comments
 (0)