Skip to content

Commit 1718828

Browse files
committed
internal/sync: warn about incorrect unsafe usage in HashTrieMap
When the HashTrieMap expand method runs out of bits, it can be because the user mutated a key after insertion using unsafe or similar in violation of the HashTrieMap invariants. Adjust the panic message to help triage and debugging by more directly suggesting unsafe code might be at fault. CL 694635 is a follow-up change that attempts to detect and report illegally mutated keys sooner and more precisely. Updates #74948 Updates #73427 Change-Id: Ib2bca067f0e212b8765c61183f59ac229513a823 Reviewed-on: https://go-review.googlesource.com/c/go/+/694376 Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 084c0f8 commit 1718828

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/internal/sync/hashtriemap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (ht *HashTrieMap[K, V]) expand(oldEntry, newEntry *entry[K, V], newHash uin
178178
top := newIndirect
179179
for {
180180
if hashShift == 0 {
181-
panic("internal/sync.HashTrieMap: ran out of hash bits while inserting")
181+
panic("internal/sync.HashTrieMap: ran out of hash bits while inserting (incorrect use of unsafe or cgo, or data race?)")
182182
}
183183
hashShift -= nChildrenLog2 // hashShift is for the level parent is at. We need to go deeper.
184184
oi := (oldHash >> hashShift) & nChildrenMask

0 commit comments

Comments
 (0)