Skip to content

Commit bbe3d8f

Browse files
matthiaskrgrgitbot
authored and
gitbot
committed
Rollup merge of rust-lang#84083 - ltratt:threadid_doc_tweak, r=dtolnay
Clarify the guarantees that ThreadId does and doesn't make. The existing documentation does not spell out whether `ThreadId`s are unique during the lifetime of a thread or of a process. I had to examine the source code to realise (pleasingly!) that they're unique for the lifetime of a process. That seems worth documenting clearly, as it's a strong guarantee. Examining the way `ThreadId`s are created also made me realise that the `as_u64` method on `ThreadId` could be a trap for the unwary on those platforms where the platform's notion of a thread identifier is also a 64 bit integer (particularly if they happen to use a similar identifier scheme to `ThreadId`). I therefore think it's worth being even clearer that there's no relationship between the two.
2 parents 7eec4b2 + 78fc550 commit bbe3d8f

File tree

1,528 files changed

+230068
-88769
lines changed

Some content is hidden

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

1,528 files changed

+230068
-88769
lines changed

Cargo.lock

+503
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[workspace]
2+
resolver = "1"
3+
members = [
4+
"std",
5+
"sysroot",
6+
]
7+
8+
exclude = [
9+
# stdarch has its own Cargo workspace
10+
"stdarch",
11+
"windows_targets"
12+
]
13+
14+
[profile.release.package.compiler_builtins]
15+
# For compiler-builtins we always use a high number of codegen units.
16+
# The goal here is to place every single intrinsic into its own object
17+
# file to avoid symbol clashes with the system libgcc if possible. Note
18+
# that this number doesn't actually produce this many object files, we
19+
# just don't create more than this number of object files.
20+
#
21+
# It's a bit of a bummer that we have to pass this here, unfortunately.
22+
# Ideally this would be specified through an env var to Cargo so Cargo
23+
# knows how many CGUs are for this specific crate, but for now
24+
# per-crate configuration isn't specifiable in the environment.
25+
codegen-units = 10000
26+
27+
# These dependencies of the standard library implement symbolication for
28+
# backtraces on most platforms. Their debuginfo causes both linking to be slower
29+
# (more data to chew through) and binaries to be larger without really all that
30+
# much benefit. This section turns them all to down to have no debuginfo which
31+
# helps to improve link times a little bit.
32+
[profile.release.package]
33+
addr2line.debug = 0
34+
addr2line.opt-level = "s"
35+
adler.debug = 0
36+
gimli.debug = 0
37+
gimli.opt-level = "s"
38+
miniz_oxide.debug = 0
39+
object.debug = 0
40+
rustc-demangle.debug = 0
41+
42+
[patch.crates-io]
43+
# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
44+
# here
45+
rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
46+
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
47+
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }

alloc/Cargo.toml

+25-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
[package]
2-
authors = ["The Rust Project Developers"]
32
name = "alloc"
43
version = "0.0.0"
54
license = "MIT OR Apache-2.0"
65
repository = "https://github.com/rust-lang/rust.git"
76
description = "The Rust core allocation and collections library"
87
autotests = false
98
autobenches = false
10-
edition = "2018"
9+
edition = "2021"
1110

1211
[dependencies]
1312
core = { path = "../core" }
14-
compiler_builtins = { version = "0.1.40", features = ['rustc-dep-of-std'] }
13+
compiler_builtins = { version = "=0.1.138", features = ['rustc-dep-of-std'] }
1514

1615
[dev-dependencies]
17-
rand = "0.7"
18-
rand_xorshift = "0.2"
16+
rand = { version = "0.8.5", default-features = false, features = ["alloc"] }
17+
rand_xorshift = "0.3.0"
1918

2019
[[test]]
21-
name = "collectionstests"
20+
name = "alloctests"
2221
path = "tests/lib.rs"
2322

23+
[[test]]
24+
name = "vec_deque_alloc_error"
25+
path = "tests/vec_deque_alloc_error.rs"
26+
2427
[[bench]]
25-
name = "collectionsbenches"
28+
name = "allocbenches"
2629
path = "benches/lib.rs"
2730
test = true
2831

@@ -35,4 +38,19 @@ harness = false
3538
compiler-builtins-mem = ['compiler_builtins/mem']
3639
compiler-builtins-c = ["compiler_builtins/c"]
3740
compiler-builtins-no-asm = ["compiler_builtins/no-asm"]
41+
compiler-builtins-no-f16-f128 = ["compiler_builtins/no-f16-f128"]
3842
compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"]
43+
# Make panics and failed asserts immediately abort without formatting any message
44+
panic_immediate_abort = ["core/panic_immediate_abort"]
45+
# Choose algorithms that are optimized for binary size instead of runtime performance
46+
optimize_for_size = ["core/optimize_for_size"]
47+
48+
[lints.rust.unexpected_cfgs]
49+
level = "warn"
50+
check-cfg = [
51+
'cfg(bootstrap)',
52+
'cfg(no_global_oom_handling)',
53+
'cfg(no_rc)',
54+
'cfg(no_sync)',
55+
'cfg(randomized_layouts)',
56+
]

alloc/benches/binary_heap.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::collections::BinaryHeap;
22

3-
use rand::{seq::SliceRandom, thread_rng};
4-
use test::{black_box, Bencher};
3+
use rand::seq::SliceRandom;
4+
use test::{Bencher, black_box};
55

66
#[bench]
77
fn bench_find_smallest_1000(b: &mut Bencher) {
8-
let mut rng = thread_rng();
8+
let mut rng = crate::bench_rng();
99
let mut vec: Vec<u32> = (0..100_000).collect();
1010
vec.shuffle(&mut rng);
1111

@@ -36,7 +36,7 @@ fn bench_peek_mut_deref_mut(b: &mut Bencher) {
3636
let mut peek_mut = bheap.peek_mut().unwrap();
3737
// The compiler shouldn't be able to optimize away the `sift_down`
3838
// assignment in `PeekMut`'s `DerefMut` implementation since
39-
// the loop may not run.
39+
// the loop might not run.
4040
for &i in vec.iter() {
4141
*peek_mut = i;
4242
}
@@ -47,7 +47,7 @@ fn bench_peek_mut_deref_mut(b: &mut Bencher) {
4747

4848
#[bench]
4949
fn bench_from_vec(b: &mut Bencher) {
50-
let mut rng = thread_rng();
50+
let mut rng = crate::bench_rng();
5151
let mut vec: Vec<u32> = (0..100_000).collect();
5252
vec.shuffle(&mut rng);
5353

@@ -64,7 +64,7 @@ fn bench_into_sorted_vec(b: &mut Bencher) {
6464
#[bench]
6565
fn bench_push(b: &mut Bencher) {
6666
let mut bheap = BinaryHeap::with_capacity(50_000);
67-
let mut rng = thread_rng();
67+
let mut rng = crate::bench_rng();
6868
let mut vec: Vec<u32> = (0..50_000).collect();
6969
vec.shuffle(&mut rng);
7070

alloc/benches/btree/map.rs

+65-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::collections::BTreeMap;
2-
use std::iter::Iterator;
32
use std::ops::RangeBounds;
4-
use std::vec::Vec;
53

6-
use rand::{seq::SliceRandom, thread_rng, Rng};
7-
use test::{black_box, Bencher};
4+
use rand::Rng;
5+
use rand::seq::SliceRandom;
6+
use test::{Bencher, black_box};
87

98
macro_rules! map_insert_rand_bench {
109
($name: ident, $n: expr, $map: ident) => {
@@ -13,7 +12,7 @@ macro_rules! map_insert_rand_bench {
1312
let n: usize = $n;
1413
let mut map = $map::new();
1514
// setup
16-
let mut rng = thread_rng();
15+
let mut rng = crate::bench_rng();
1716

1817
for _ in 0..n {
1918
let i = rng.gen::<usize>() % n;
@@ -54,6 +53,50 @@ macro_rules! map_insert_seq_bench {
5453
};
5554
}
5655

56+
macro_rules! map_from_iter_rand_bench {
57+
($name: ident, $n: expr, $map: ident) => {
58+
#[bench]
59+
pub fn $name(b: &mut Bencher) {
60+
let n: usize = $n;
61+
// setup
62+
let mut rng = crate::bench_rng();
63+
let mut vec = Vec::with_capacity(n);
64+
65+
for _ in 0..n {
66+
let i = rng.gen::<usize>() % n;
67+
vec.push((i, i));
68+
}
69+
70+
// measure
71+
b.iter(|| {
72+
let map: $map<_, _> = vec.iter().copied().collect();
73+
black_box(map);
74+
});
75+
}
76+
};
77+
}
78+
79+
macro_rules! map_from_iter_seq_bench {
80+
($name: ident, $n: expr, $map: ident) => {
81+
#[bench]
82+
pub fn $name(b: &mut Bencher) {
83+
let n: usize = $n;
84+
// setup
85+
let mut vec = Vec::with_capacity(n);
86+
87+
for i in 0..n {
88+
vec.push((i, i));
89+
}
90+
91+
// measure
92+
b.iter(|| {
93+
let map: $map<_, _> = vec.iter().copied().collect();
94+
black_box(map);
95+
});
96+
}
97+
};
98+
}
99+
57100
macro_rules! map_find_rand_bench {
58101
($name: ident, $n: expr, $map: ident) => {
59102
#[bench]
@@ -62,7 +105,7 @@ macro_rules! map_find_rand_bench {
62105
let n: usize = $n;
63106

64107
// setup
65-
let mut rng = thread_rng();
108+
let mut rng = crate::bench_rng();
66109
let mut keys: Vec<_> = (0..n).map(|_| rng.gen::<usize>() % n).collect();
67110

68111
for &k in &keys {
@@ -111,6 +154,12 @@ map_insert_rand_bench! {insert_rand_10_000, 10_000, BTreeMap}
111154
map_insert_seq_bench! {insert_seq_100, 100, BTreeMap}
112155
map_insert_seq_bench! {insert_seq_10_000, 10_000, BTreeMap}
113156

157+
map_from_iter_rand_bench! {from_iter_rand_100, 100, BTreeMap}
158+
map_from_iter_rand_bench! {from_iter_rand_10_000, 10_000, BTreeMap}
159+
160+
map_from_iter_seq_bench! {from_iter_seq_100, 100, BTreeMap}
161+
map_from_iter_seq_bench! {from_iter_seq_10_000, 10_000, BTreeMap}
162+
114163
map_find_rand_bench! {find_rand_100, 100, BTreeMap}
115164
map_find_rand_bench! {find_rand_10_000, 10_000, BTreeMap}
116165

@@ -119,7 +168,7 @@ map_find_seq_bench! {find_seq_10_000, 10_000, BTreeMap}
119168

120169
fn bench_iteration(b: &mut Bencher, size: i32) {
121170
let mut map = BTreeMap::<i32, i32>::new();
122-
let mut rng = thread_rng();
171+
let mut rng = crate::bench_rng();
123172

124173
for _ in 0..size {
125174
map.insert(rng.gen(), rng.gen());
@@ -149,7 +198,7 @@ pub fn iteration_100000(b: &mut Bencher) {
149198

150199
fn bench_iteration_mut(b: &mut Bencher, size: i32) {
151200
let mut map = BTreeMap::<i32, i32>::new();
152-
let mut rng = thread_rng();
201+
let mut rng = crate::bench_rng();
153202

154203
for _ in 0..size {
155204
map.insert(rng.gen(), rng.gen());
@@ -240,7 +289,7 @@ where
240289
let mut c = 0;
241290
for i in 0..BENCH_RANGE_SIZE {
242291
for j in i + 1..BENCH_RANGE_SIZE {
243-
black_box(map.range(f(i, j)));
292+
let _ = black_box(map.range(f(i, j)));
244293
c += 1;
245294
}
246295
}
@@ -272,7 +321,7 @@ fn bench_iter(b: &mut Bencher, repeats: i32, size: i32) {
272321
let map: BTreeMap<_, _> = (0..size).map(|i| (i, i)).collect();
273322
b.iter(|| {
274323
for _ in 0..repeats {
275-
black_box(map.iter());
324+
let _ = black_box(map.iter());
276325
}
277326
});
278327
}
@@ -336,15 +385,15 @@ pub fn clone_slim_100_and_clear(b: &mut Bencher) {
336385
#[bench]
337386
pub fn clone_slim_100_and_drain_all(b: &mut Bencher) {
338387
let src = slim_map(100);
339-
b.iter(|| src.clone().drain_filter(|_, _| true).count())
388+
b.iter(|| src.clone().extract_if(|_, _| true).count())
340389
}
341390

342391
#[bench]
343392
pub fn clone_slim_100_and_drain_half(b: &mut Bencher) {
344393
let src = slim_map(100);
345394
b.iter(|| {
346395
let mut map = src.clone();
347-
assert_eq!(map.drain_filter(|i, _| i % 2 == 0).count(), 100 / 2);
396+
assert_eq!(map.extract_if(|i, _| i % 2 == 0).count(), 100 / 2);
348397
assert_eq!(map.len(), 100 / 2);
349398
})
350399
}
@@ -407,15 +456,15 @@ pub fn clone_slim_10k_and_clear(b: &mut Bencher) {
407456
#[bench]
408457
pub fn clone_slim_10k_and_drain_all(b: &mut Bencher) {
409458
let src = slim_map(10_000);
410-
b.iter(|| src.clone().drain_filter(|_, _| true).count())
459+
b.iter(|| src.clone().extract_if(|_, _| true).count())
411460
}
412461

413462
#[bench]
414463
pub fn clone_slim_10k_and_drain_half(b: &mut Bencher) {
415464
let src = slim_map(10_000);
416465
b.iter(|| {
417466
let mut map = src.clone();
418-
assert_eq!(map.drain_filter(|i, _| i % 2 == 0).count(), 10_000 / 2);
467+
assert_eq!(map.extract_if(|i, _| i % 2 == 0).count(), 10_000 / 2);
419468
assert_eq!(map.len(), 10_000 / 2);
420469
})
421470
}
@@ -478,15 +527,15 @@ pub fn clone_fat_val_100_and_clear(b: &mut Bencher) {
478527
#[bench]
479528
pub fn clone_fat_val_100_and_drain_all(b: &mut Bencher) {
480529
let src = fat_val_map(100);
481-
b.iter(|| src.clone().drain_filter(|_, _| true).count())
530+
b.iter(|| src.clone().extract_if(|_, _| true).count())
482531
}
483532

484533
#[bench]
485534
pub fn clone_fat_val_100_and_drain_half(b: &mut Bencher) {
486535
let src = fat_val_map(100);
487536
b.iter(|| {
488537
let mut map = src.clone();
489-
assert_eq!(map.drain_filter(|i, _| i % 2 == 0).count(), 100 / 2);
538+
assert_eq!(map.extract_if(|i, _| i % 2 == 0).count(), 100 / 2);
490539
assert_eq!(map.len(), 100 / 2);
491540
})
492541
}

alloc/benches/btree/set.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::collections::BTreeSet;
22

3-
use rand::{thread_rng, Rng};
3+
use rand::Rng;
44
use test::Bencher;
55

66
fn random(n: usize) -> BTreeSet<usize> {
7-
let mut rng = thread_rng();
7+
let mut rng = crate::bench_rng();
88
let mut set = BTreeSet::new();
99
while set.len() < n {
1010
set.insert(rng.gen());
@@ -69,15 +69,15 @@ pub fn clone_100_and_clear(b: &mut Bencher) {
6969
#[bench]
7070
pub fn clone_100_and_drain_all(b: &mut Bencher) {
7171
let src = slim_set(100);
72-
b.iter(|| src.clone().drain_filter(|_| true).count())
72+
b.iter(|| src.clone().extract_if(|_| true).count())
7373
}
7474

7575
#[bench]
7676
pub fn clone_100_and_drain_half(b: &mut Bencher) {
7777
let src = slim_set(100);
7878
b.iter(|| {
7979
let mut set = src.clone();
80-
assert_eq!(set.drain_filter(|i| i % 2 == 0).count(), 100 / 2);
80+
assert_eq!(set.extract_if(|i| i % 2 == 0).count(), 100 / 2);
8181
assert_eq!(set.len(), 100 / 2);
8282
})
8383
}
@@ -140,15 +140,15 @@ pub fn clone_10k_and_clear(b: &mut Bencher) {
140140
#[bench]
141141
pub fn clone_10k_and_drain_all(b: &mut Bencher) {
142142
let src = slim_set(10_000);
143-
b.iter(|| src.clone().drain_filter(|_| true).count())
143+
b.iter(|| src.clone().extract_if(|_| true).count())
144144
}
145145

146146
#[bench]
147147
pub fn clone_10k_and_drain_half(b: &mut Bencher) {
148148
let src = slim_set(10_000);
149149
b.iter(|| {
150150
let mut set = src.clone();
151-
assert_eq!(set.drain_filter(|i| i % 2 == 0).count(), 10_000 / 2);
151+
assert_eq!(set.extract_if(|i| i % 2 == 0).count(), 10_000 / 2);
152152
assert_eq!(set.len(), 10_000 / 2);
153153
})
154154
}

0 commit comments

Comments
 (0)