Skip to content

Commit b2e6d9a

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 de1868c commit b2e6d9a

File tree

4 files changed

+30
-273
lines changed

4 files changed

+30
-273
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

+30-37
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,10 @@ mod pointer;
119119
mod queries;
120120
mod value;
121121

122-
use std::fmt;
123-
use std::io;
124-
use std::io::{Read, Write};
125-
use std::num::NonZero;
126-
use std::sync::atomic::{AtomicU32, Ordering};
127-
128-
use rustc_ast::LitKind;
129-
use rustc_data_structures::fx::FxHashMap;
130-
use rustc_data_structures::sync::{HashMapExt, Lock};
131-
use rustc_data_structures::tiny_list::TinyList;
132-
use rustc_errors::ErrorGuaranteed;
133-
use rustc_hir::def_id::{DefId, LocalDefId};
134-
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
135-
use rustc_middle::ty::print::with_no_trimmed_paths;
136-
use rustc_serialize::{Decodable, Encodable};
137-
use rustc_target::abi::{AddressSpace, Endian, HasDataLayout};
138-
139-
use crate::mir;
140-
use crate::ty::codec::{TyDecoder, TyEncoder};
141-
use crate::ty::GenericArgKind;
142-
use crate::ty::{self, Instance, Ty, TyCtxt};
143-
122+
pub use self::allocation::{
123+
alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation,
124+
InitChunk, InitChunkIter,
125+
};
144126
pub use self::error::{
145127
BadBytesAccess, CheckAlignMsg, CheckInAllocMsg, ErrorHandled, EvalStaticInitializerRawResult,
146128
EvalToAllocationRawResult, EvalToConstValueResult, EvalToValTreeResult, ExpectedKind,
@@ -149,15 +131,28 @@ pub use self::error::{
149131
ScalarSizeMismatch, UndefinedBehaviorInfo, UnsupportedOpInfo, ValidationErrorInfo,
150132
ValidationErrorKind,
151133
};
152-
134+
pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance};
153135
pub use self::value::Scalar;
154136

155-
pub use self::allocation::{
156-
alloc_range, AllocBytes, AllocError, AllocRange, AllocResult, Allocation, ConstAllocation,
157-
InitChunk, InitChunkIter,
158-
};
159-
160-
pub use self::pointer::{CtfeProvenance, Pointer, PointerArithmetic, Provenance};
137+
use crate::mir;
138+
use crate::ty::codec::{TyDecoder, TyEncoder};
139+
use crate::ty::GenericArgKind;
140+
use crate::ty::{self, Instance, Ty, TyCtxt};
141+
use rustc_ast::LitKind;
142+
use rustc_data_structures::fx::FxHashMap;
143+
use rustc_data_structures::sync::{HashMapExt, Lock};
144+
use rustc_errors::ErrorGuaranteed;
145+
use rustc_hir::def_id::{DefId, LocalDefId};
146+
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
147+
use rustc_middle::ty::print::with_no_trimmed_paths;
148+
use rustc_serialize::{Decodable, Encodable};
149+
use rustc_target::abi::{AddressSpace, Endian, HasDataLayout};
150+
use smallvec::{smallvec, SmallVec};
151+
use std::fmt;
152+
use std::io;
153+
use std::io::{Read, Write};
154+
use std::num::NonZero;
155+
use std::sync::atomic::{AtomicU32, Ordering};
161156

162157
/// Uniquely identifies one of the following:
163158
/// - A constant
@@ -266,8 +261,8 @@ type DecodingSessionId = NonZero<u32>;
266261
#[derive(Clone)]
267262
enum State {
268263
Empty,
269-
InProgressNonAlloc(TinyList<DecodingSessionId>),
270-
InProgress(TinyList<DecodingSessionId>, AllocId),
264+
InProgressNonAlloc(SmallVec<[DecodingSessionId; 1]>),
265+
InProgress(SmallVec<[DecodingSessionId; 1]>, AllocId),
271266
Done(AllocId),
272267
}
273268

@@ -337,17 +332,15 @@ impl<'s> AllocDecodingSession<'s> {
337332
// If this is an allocation, we need to reserve an
338333
// `AllocId` so we can decode cyclic graphs.
339334
let alloc_id = decoder.interner().reserve_alloc_id();
340-
*entry =
341-
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
335+
*entry = State::InProgress(smallvec![self.session_id], alloc_id);
342336
Some(alloc_id)
343337
}
344338
AllocDiscriminant::Fn
345339
| AllocDiscriminant::Static
346340
| AllocDiscriminant::VTable => {
347341
// Fns and statics cannot be cyclic, and their `AllocId`
348342
// is determined later by interning.
349-
*entry =
350-
State::InProgressNonAlloc(TinyList::new_single(self.session_id));
343+
*entry = State::InProgressNonAlloc(smallvec![self.session_id]);
351344
None
352345
}
353346
}
@@ -357,7 +350,7 @@ impl<'s> AllocDecodingSession<'s> {
357350
bug!("this should be unreachable");
358351
} else {
359352
// Start decoding concurrently.
360-
sessions.insert(self.session_id);
353+
sessions.insert(0, self.session_id);
361354
None
362355
}
363356
}
@@ -367,7 +360,7 @@ impl<'s> AllocDecodingSession<'s> {
367360
return alloc_id;
368361
} else {
369362
// Start decoding concurrently.
370-
sessions.insert(self.session_id);
363+
sessions.insert(0, self.session_id);
371364
Some(alloc_id)
372365
}
373366
}

0 commit comments

Comments
 (0)