From 1718828c81f2bad44b51b13fb4b34540a9c2c096 Mon Sep 17 00:00:00 2001 From: thepudds Date: Sat, 9 Aug 2025 17:25:14 -0400 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Dmitri Shuralyov --- src/internal/sync/hashtriemap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/sync/hashtriemap.go b/src/internal/sync/hashtriemap.go index dbf4c3473e..db83297427 100644 --- a/src/internal/sync/hashtriemap.go +++ b/src/internal/sync/hashtriemap.go @@ -178,7 +178,7 @@ func (ht *HashTrieMap[K, V]) expand(oldEntry, newEntry *entry[K, V], newHash uin top := newIndirect for { if hashShift == 0 { - panic("internal/sync.HashTrieMap: ran out of hash bits while inserting") + panic("internal/sync.HashTrieMap: ran out of hash bits while inserting (incorrect use of unsafe or cgo, or data race?)") } hashShift -= nChildrenLog2 // hashShift is for the level parent is at. We need to go deeper. oi := (oldHash >> hashShift) & nChildrenMask -- 2.51.0