Skip to content

Commit 8b26609

Browse files
committed
Auto merge of #70052 - Amanieu:hashbrown7, r=Mark-Simulacrum
Update hashbrown to 0.8.1 This update includes: - rust-lang/hashbrown#146, which improves the performance of `Clone` and implements `clone_from`. - rust-lang/hashbrown#159, which reduces the size of `HashMap` by 8 bytes. - rust-lang/hashbrown#162, which avoids creating small 1-element tables. Fixes #28481
2 parents d4c940f + e46bb17 commit 8b26609

File tree

7 files changed

+47
-66
lines changed

7 files changed

+47
-66
lines changed

Cargo.lock

+5-11
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ dependencies = [
137137
"winapi 0.3.8",
138138
]
139139

140-
[[package]]
141-
name = "autocfg"
142-
version = "0.1.7"
143-
source = "registry+https://github.com/rust-lang/crates.io-index"
144-
checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
145-
146140
[[package]]
147141
name = "autocfg"
148142
version = "1.0.0"
@@ -766,7 +760,7 @@ version = "0.7.2"
766760
source = "registry+https://github.com/rust-lang/crates.io-index"
767761
checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8"
768762
dependencies = [
769-
"autocfg 1.0.0",
763+
"autocfg",
770764
"cfg-if",
771765
"lazy_static",
772766
]
@@ -1245,11 +1239,11 @@ dependencies = [
12451239

12461240
[[package]]
12471241
name = "hashbrown"
1248-
version = "0.6.2"
1242+
version = "0.8.1"
12491243
source = "registry+https://github.com/rust-lang/crates.io-index"
1250-
checksum = "3cd9867f119b19fecb08cd5c326ad4488d7a1da4bf75b4d95d71db742525aaab"
1244+
checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb"
12511245
dependencies = [
1252-
"autocfg 0.1.7",
1246+
"autocfg",
12531247
"compiler_builtins",
12541248
"rustc-std-workspace-alloc",
12551249
"rustc-std-workspace-core",
@@ -2079,7 +2073,7 @@ version = "0.9.54"
20792073
source = "registry+https://github.com/rust-lang/crates.io-index"
20802074
checksum = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986"
20812075
dependencies = [
2082-
"autocfg 1.0.0",
2076+
"autocfg",
20832077
"cc",
20842078
"libc",
20852079
"openssl-src",

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of
2020
compiler_builtins = { version = "0.1.32" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
23-
hashbrown = { version = "0.6.2", default-features = false, features = ['rustc-dep-of-std'] }
23+
hashbrown = { version = "0.8.1", default-features = false, features = ['rustc-dep-of-std'] }
2424

2525
# Dependencies of the `backtrace` crate
2626
addr2line = { version = "0.13.0", optional = true, default-features = false }

library/std/src/collections/hash/map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ where
580580
#[inline]
581581
#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")]
582582
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
583-
self.base.try_reserve(additional).map_err(map_collection_alloc_err)
583+
self.base.try_reserve(additional).map_err(map_try_reserve_error)
584584
}
585585

586586
/// Shrinks the capacity of the map as much as possible. It will drop
@@ -2569,10 +2569,10 @@ fn map_entry<'a, K: 'a, V: 'a>(raw: base::RustcEntry<'a, K, V>) -> Entry<'a, K,
25692569
}
25702570

25712571
#[inline]
2572-
fn map_collection_alloc_err(err: hashbrown::CollectionAllocErr) -> TryReserveError {
2572+
fn map_try_reserve_error(err: hashbrown::TryReserveError) -> TryReserveError {
25732573
match err {
2574-
hashbrown::CollectionAllocErr::CapacityOverflow => TryReserveError::CapacityOverflow,
2575-
hashbrown::CollectionAllocErr::AllocErr { layout } => {
2574+
hashbrown::TryReserveError::CapacityOverflow => TryReserveError::CapacityOverflow,
2575+
hashbrown::TryReserveError::AllocError { layout } => {
25762576
TryReserveError::AllocError { layout, non_exhaustive: () }
25772577
}
25782578
}

src/etc/gdb_providers.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,13 @@ def __init__(self, valobj, show_values=True):
352352
ctrl = table["ctrl"]["pointer"]
353353

354354
self.size = int(table["items"])
355-
self.data_ptr = table["data"]["pointer"]
356-
self.pair_type = self.data_ptr.dereference().type
355+
self.pair_type = table.type.template_argument(0)
356+
357+
self.new_layout = not table.type.has_key("data")
358+
if self.new_layout:
359+
self.data_ptr = ctrl.cast(self.pair_type.pointer())
360+
else:
361+
self.data_ptr = table["data"]["pointer"]
357362

358363
self.valid_indices = []
359364
for idx in range(capacity):
@@ -374,6 +379,8 @@ def children(self):
374379

375380
for index in range(self.size):
376381
idx = self.valid_indices[index]
382+
if self.new_layout:
383+
idx = -(idx + 1)
377384
element = (pairs_start + idx).dereference()
378385
if self.show_values:
379386
yield "key{}".format(index), element[ZERO_FIELD]

src/etc/lldb_providers.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ def get_child_at_index(self, index):
514514
# type: (int) -> SBValue
515515
pairs_start = self.data_ptr.GetValueAsUnsigned()
516516
idx = self.valid_indices[index]
517+
if self.new_layout:
518+
idx = -(idx + 1)
517519
address = pairs_start + idx * self.pair_type_size
518520
element = self.data_ptr.CreateValueFromAddress("[%s]" % index, address, self.pair_type)
519521
if self.show_values:
@@ -529,10 +531,15 @@ def update(self):
529531
ctrl = table.GetChildMemberWithName("ctrl").GetChildAtIndex(0)
530532

531533
self.size = table.GetChildMemberWithName("items").GetValueAsUnsigned()
532-
self.data_ptr = table.GetChildMemberWithName("data").GetChildAtIndex(0)
533-
self.pair_type = self.data_ptr.Dereference().GetType()
534+
self.pair_type = table.type.template_args[0]
534535
self.pair_type_size = self.pair_type.GetByteSize()
535536

537+
self.new_layout = not table.GetChildMemberWithName("data").IsValid()
538+
if self.new_layout:
539+
self.data_ptr = ctrl.Cast(self.pair_type.GetPointerType())
540+
else:
541+
self.data_ptr = table.GetChildMemberWithName("data").GetChildAtIndex(0)
542+
536543
u8_type = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar)
537544
u8_type_size = self.valobj.GetTarget().GetBasicType(eBasicTypeUnsignedChar).GetByteSize()
538545

src/etc/natvis/libstd.natvis

+4-31
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<Expand>
3131
<Item Name="[size]">base.table.items</Item>
3232
<Item Name="[capacity]">base.table.items + base.table.growth_left</Item>
33+
<Item Name="[state]">base.hash_builder</Item>
3334

3435
<CustomListItems>
3536
<Variable Name="i" InitialValue="0" />
@@ -40,7 +41,7 @@
4041
<If Condition="(base.table.ctrl.pointer[i] &amp; 0x80) == 0">
4142
<!-- Bucket is populated -->
4243
<Exec>n--</Exec>
43-
<Item Name="{base.table.data.pointer[i].__0}">base.table.data.pointer[i].__1</Item>
44+
<Item Name="{static_cast&lt;tuple&lt;$T1, $T2&gt;*&gt;(base.table.ctrl.pointer)[-(i + 1)].__0}">static_cast&lt;tuple&lt;$T1, $T2&gt;*&gt;(base.table.ctrl.pointer)[-(i + 1)].__1</Item>
4445
</If>
4546
<Exec>i++</Exec>
4647
</Loop>
@@ -53,6 +54,7 @@
5354
<Expand>
5455
<Item Name="[size]">map.base.table.items</Item>
5556
<Item Name="[capacity]">map.base.table.items + map.base.table.growth_left</Item>
57+
<Item Name="[state]">map.base.hash_builder</Item>
5658

5759
<CustomListItems>
5860
<Variable Name="i" InitialValue="0" />
@@ -63,36 +65,7 @@
6365
<If Condition="(map.base.table.ctrl.pointer[i] &amp; 0x80) == 0">
6466
<!-- Bucket is populated -->
6567
<Exec>n--</Exec>
66-
<Item>map.base.table.data.pointer[i].__0</Item>
67-
</If>
68-
<Exec>i++</Exec>
69-
</Loop>
70-
</CustomListItems>
71-
</Expand>
72-
</Type>
73-
74-
<Type Name="hashbrown::raw::RawTable&lt;*&gt;">
75-
<!-- RawTable has a nice and simple layout.
76-
items Number of *populated* values in the RawTable (less than the size of ctrl.pointer / data.pointer)
77-
growth_left Remaining capacity before growth
78-
ctrl.pointer[i] & 0x80 Indicates the bucket is empty / should be skipped / doesn't count towards items.
79-
data.pointer[i] The (K,V) tuple, if not empty.
80-
-->
81-
<DisplayString>{{ size={items} }}</DisplayString>
82-
<Expand>
83-
<Item Name="[size]">items</Item>
84-
<Item Name="[capacity]">items + growth_left</Item>
85-
86-
<CustomListItems>
87-
<Variable Name="i" InitialValue="0" />
88-
<Variable Name="n" InitialValue="items" />
89-
<Size>items</Size>
90-
<Loop>
91-
<Break Condition="n == 0" />
92-
<If Condition="(ctrl.pointer[i] &amp; 0x80) == 0">
93-
<!-- Bucket is populated -->
94-
<Exec>n--</Exec>
95-
<Item>data.pointer[i]</Item>
68+
<Item>static_cast&lt;$T1*&gt;(map.base.table.ctrl.pointer)[-(i + 1)]</Item>
9669
</If>
9770
<Exec>i++</Exec>
9871
</Loop>

src/test/debuginfo/pretty-std-collections-hash.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,35 @@
99
// cdb-check:hash_set,d [...] : { size=15 } [Type: [...]::HashSet<u64, [...]>]
1010
// cdb-check: [size] : 15 [Type: [...]]
1111
// cdb-check: [capacity] : [...]
12-
// cdb-check: [[...]] [...] : 0 [Type: unsigned __int64]
12+
// cdb-check: [[...]] [...] : 0 [Type: u64]
1313
// cdb-command: dx hash_set,d
14-
// cdb-check: [[...]] [...] : 1 [Type: unsigned __int64]
14+
// cdb-check: [[...]] [...] : 1 [Type: u64]
1515
// cdb-command: dx hash_set,d
16-
// cdb-check: [[...]] [...] : 2 [Type: unsigned __int64]
16+
// cdb-check: [[...]] [...] : 2 [Type: u64]
1717
// cdb-command: dx hash_set,d
18-
// cdb-check: [[...]] [...] : 3 [Type: unsigned __int64]
18+
// cdb-check: [[...]] [...] : 3 [Type: u64]
1919
// cdb-command: dx hash_set,d
20-
// cdb-check: [[...]] [...] : 4 [Type: unsigned __int64]
20+
// cdb-check: [[...]] [...] : 4 [Type: u64]
2121
// cdb-command: dx hash_set,d
22-
// cdb-check: [[...]] [...] : 5 [Type: unsigned __int64]
22+
// cdb-check: [[...]] [...] : 5 [Type: u64]
2323
// cdb-command: dx hash_set,d
24-
// cdb-check: [[...]] [...] : 6 [Type: unsigned __int64]
24+
// cdb-check: [[...]] [...] : 6 [Type: u64]
2525
// cdb-command: dx hash_set,d
26-
// cdb-check: [[...]] [...] : 7 [Type: unsigned __int64]
26+
// cdb-check: [[...]] [...] : 7 [Type: u64]
2727
// cdb-command: dx hash_set,d
28-
// cdb-check: [[...]] [...] : 8 [Type: unsigned __int64]
28+
// cdb-check: [[...]] [...] : 8 [Type: u64]
2929
// cdb-command: dx hash_set,d
30-
// cdb-check: [[...]] [...] : 9 [Type: unsigned __int64]
30+
// cdb-check: [[...]] [...] : 9 [Type: u64]
3131
// cdb-command: dx hash_set,d
32-
// cdb-check: [[...]] [...] : 10 [Type: unsigned __int64]
32+
// cdb-check: [[...]] [...] : 10 [Type: u64]
3333
// cdb-command: dx hash_set,d
34-
// cdb-check: [[...]] [...] : 11 [Type: unsigned __int64]
34+
// cdb-check: [[...]] [...] : 11 [Type: u64]
3535
// cdb-command: dx hash_set,d
36-
// cdb-check: [[...]] [...] : 12 [Type: unsigned __int64]
36+
// cdb-check: [[...]] [...] : 12 [Type: u64]
3737
// cdb-command: dx hash_set,d
38-
// cdb-check: [[...]] [...] : 13 [Type: unsigned __int64]
38+
// cdb-check: [[...]] [...] : 13 [Type: u64]
3939
// cdb-command: dx hash_set,d
40-
// cdb-check: [[...]] [...] : 14 [Type: unsigned __int64]
40+
// cdb-check: [[...]] [...] : 14 [Type: u64]
4141

4242
// cdb-command: dx hash_map,d
4343
// cdb-check:hash_map,d [...] : { size=15 } [Type: [...]::HashMap<u64, u64, [...]>]

0 commit comments

Comments
 (0)