Skip to content

Commit 3fd517a

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 88cabad commit 3fd517a

File tree

4 files changed

+9
-245
lines changed

4 files changed

+9
-245
lines changed

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub mod svh;
8181
pub mod sync;
8282
pub mod tagged_ptr;
8383
pub mod temp_dir;
84-
pub mod tiny_list;
8584
pub mod transitive_relation;
8685
pub mod unhash;
8786
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

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

128+
use smallvec::{smallvec, SmallVec};
129+
use tracing::debug;
130+
128131
use rustc_ast::LitKind;
129132
use rustc_data_structures::fx::FxHashMap;
130133
use rustc_data_structures::sync::{HashMapExt, Lock};
131-
use rustc_data_structures::tiny_list::TinyList;
132134
use rustc_errors::ErrorGuaranteed;
133135
use rustc_hir::def_id::{DefId, LocalDefId};
134136
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
@@ -266,8 +268,8 @@ type DecodingSessionId = NonZero<u32>;
266268
#[derive(Clone)]
267269
enum State {
268270
Empty,
269-
InProgressNonAlloc(TinyList<DecodingSessionId>),
270-
InProgress(TinyList<DecodingSessionId>, AllocId),
271+
InProgressNonAlloc(SmallVec<[DecodingSessionId; 1]>),
272+
InProgress(SmallVec<[DecodingSessionId; 1]>, AllocId),
271273
Done(AllocId),
272274
}
273275

@@ -337,17 +339,15 @@ impl<'s> AllocDecodingSession<'s> {
337339
// If this is an allocation, we need to reserve an
338340
// `AllocId` so we can decode cyclic graphs.
339341
let alloc_id = decoder.interner().reserve_alloc_id();
340-
*entry =
341-
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
342+
*entry = State::InProgress(smallvec![self.session_id], alloc_id);
342343
Some(alloc_id)
343344
}
344345
AllocDiscriminant::Fn
345346
| AllocDiscriminant::Static
346347
| AllocDiscriminant::VTable => {
347348
// Fns and statics cannot be cyclic, and their `AllocId`
348349
// is determined later by interning.
349-
*entry =
350-
State::InProgressNonAlloc(TinyList::new_single(self.session_id));
350+
*entry = State::InProgressNonAlloc(smallvec![self.session_id]);
351351
None
352352
}
353353
}
@@ -357,7 +357,7 @@ impl<'s> AllocDecodingSession<'s> {
357357
bug!("this should be unreachable");
358358
} else {
359359
// Start decoding concurrently.
360-
sessions.insert(self.session_id);
360+
sessions.push(self.session_id);
361361
None
362362
}
363363
}
@@ -367,7 +367,7 @@ impl<'s> AllocDecodingSession<'s> {
367367
return alloc_id;
368368
} else {
369369
// Start decoding concurrently.
370-
sessions.insert(self.session_id);
370+
sessions.push(self.session_id);
371371
Some(alloc_id)
372372
}
373373
}

0 commit comments

Comments
 (0)