Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ebd15e7

Browse files
committedSep 9, 2020
Implement HashSet in terms of hashbrown::HashSet
1 parent 15ccdeb commit ebd15e7

File tree

7 files changed

+90
-72
lines changed

7 files changed

+90
-72
lines changed
 

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ fn map_entry<'a, K: 'a, V: 'a>(raw: base::RustcEntry<'a, K, V>) -> Entry<'a, K,
26982698
}
26992699

27002700
#[inline]
2701-
fn map_try_reserve_error(err: hashbrown::TryReserveError) -> TryReserveError {
2701+
pub(super) fn map_try_reserve_error(err: hashbrown::TryReserveError) -> TryReserveError {
27022702
match err {
27032703
hashbrown::TryReserveError::CapacityOverflow => TryReserveError::CapacityOverflow,
27042704
hashbrown::TryReserveError::AllocError { layout } => {

‎library/std/src/collections/hash/set.rs

Lines changed: 52 additions & 57 deletions
Large diffs are not rendered by default.

‎src/etc/gdb_lookup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def lookup(valobj):
6969
else:
7070
return StdOldHashMapProvider(valobj)
7171
if rust_type == RustType.STD_HASH_SET:
72-
hash_map = valobj["map"]
72+
hash_map = valobj[valobj.type.fields()[0]]
7373
if is_hashbrown_hashmap(hash_map):
74-
return StdHashMapProvider(hash_map, show_values=False)
74+
return StdHashMapProvider(valobj, show_values=False)
7575
else:
7676
return StdOldHashMapProvider(hash_map, show_values=False)
7777

‎src/etc/gdb_providers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def __init__(self, valobj, show_values=True):
347347
self.valobj = valobj
348348
self.show_values = show_values
349349

350-
table = self.valobj["base"]["table"]
350+
table = self.table()
351351
capacity = int(table["bucket_mask"]) + 1
352352
ctrl = table["ctrl"]["pointer"]
353353

@@ -368,6 +368,18 @@ def __init__(self, valobj, show_values=True):
368368
if is_presented:
369369
self.valid_indices.append(idx)
370370

371+
def table(self):
372+
if self.show_values:
373+
hashbrown_hashmap = self.valobj["base"]
374+
elif self.valobj.type.fields()[0].name == "map":
375+
# BACKCOMPAT: rust 1.47
376+
# HashSet wraps std::collections::HashMap, which wraps hashbrown::HashMap
377+
hashbrown_hashmap = self.valobj["map"]["base"]
378+
else:
379+
# HashSet wraps hashbrown::HashSet, which wraps hashbrown::HashMap
380+
hashbrown_hashmap = self.valobj["base"]["map"]
381+
return hashbrown_hashmap["table"]
382+
371383
def to_string(self):
372384
if self.show_values:
373385
return "HashMap(size={})".format(self.size)

‎src/etc/lldb_lookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def synthetic_lookup(valobj, dict):
9494
if rust_type == RustType.STD_HASH_SET:
9595
hash_map = valobj.GetChildAtIndex(0)
9696
if is_hashbrown_hashmap(hash_map):
97-
return StdHashMapSyntheticProvider(hash_map, dict, show_values=False)
97+
return StdHashMapSyntheticProvider(valobj, dict, show_values=False)
9898
else:
9999
return StdOldHashMapSyntheticProvider(hash_map, dict, show_values=False)
100100

‎src/etc/lldb_providers.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def get_child_at_index(self, index):
526526

527527
def update(self):
528528
# type: () -> None
529-
table = self.valobj.GetChildMemberWithName("base").GetChildMemberWithName("table")
529+
table = self.table()
530530
capacity = table.GetChildMemberWithName("bucket_mask").GetValueAsUnsigned() + 1
531531
ctrl = table.GetChildMemberWithName("ctrl").GetChildAtIndex(0)
532532

@@ -552,6 +552,17 @@ def update(self):
552552
if is_present:
553553
self.valid_indices.append(idx)
554554

555+
def table(self):
556+
# type: () -> SBValue
557+
if self.show_values:
558+
hashbrown_hashmap = self.valobj.GetChildMemberWithName("base")
559+
else:
560+
# BACKCOMPAT: rust 1.47
561+
# HashSet wraps either std HashMap or hashbrown::HashSet, which both
562+
# wrap hashbrown::HashMap, so either way we "unwrap" twice.
563+
hashbrown_hashmap = self.valobj.GetChildAtIndex(0).GetChildAtIndex(0)
564+
return hashbrown_hashmap.GetChildMemberWithName("table")
565+
555566
def has_children(self):
556567
# type: () -> bool
557568
return True

‎src/etc/natvis/libstd.natvis

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Current std impls:
77
std::collections::hash::set::HashSet<K, S> is implemented in terms of...
8-
std::collections::hash::map::HashMap<K, V, S> is implemented in terms of...
8+
hashbrown::set::HashSet<K, S> is implemented in terms of...
99
hashbrown::map::HashMap<K, V, S> is implemented in terms of...
1010
hashbrown::raw::RawTable<(K, V)>
1111
@@ -50,22 +50,22 @@
5050
</Type>
5151

5252
<Type Name="std::collections::hash::set::HashSet&lt;*,*&gt;">
53-
<DisplayString>{{ size={map.base.table.items} }}</DisplayString>
53+
<DisplayString>{{ size={base.map.table.items} }}</DisplayString>
5454
<Expand>
55-
<Item Name="[size]">map.base.table.items</Item>
56-
<Item Name="[capacity]">map.base.table.items + map.base.table.growth_left</Item>
57-
<Item Name="[state]">map.base.hash_builder</Item>
55+
<Item Name="[size]">base.map.table.items</Item>
56+
<Item Name="[capacity]">base.map.table.items + base.map.table.growth_left</Item>
57+
<Item Name="[state]">base.map.hash_builder</Item>
5858

5959
<CustomListItems>
6060
<Variable Name="i" InitialValue="0" />
61-
<Variable Name="n" InitialValue="map.base.table.items" />
62-
<Size>map.base.table.items</Size>
61+
<Variable Name="n" InitialValue="base.map.table.items" />
62+
<Size>base.map.table.items</Size>
6363
<Loop>
6464
<Break Condition="n == 0" />
65-
<If Condition="(map.base.table.ctrl.pointer[i] &amp; 0x80) == 0">
65+
<If Condition="(base.map.table.ctrl.pointer[i] &amp; 0x80) == 0">
6666
<!-- Bucket is populated -->
6767
<Exec>n--</Exec>
68-
<Item>(($T1*)map.base.table.ctrl.pointer)[-(i + 1)]</Item>
68+
<Item>(($T1*)base.map.table.ctrl.pointer)[-(i + 1)]</Item>
6969
</If>
7070
<Exec>i++</Exec>
7171
</Loop>

0 commit comments

Comments
 (0)
Please sign in to comment.