]> Cypherpunks repositories - gostls13.git/commitdiff
internal/concurrent: remove dependency on math/rand/v2
authorMichael Anthony Knyszek <mknyszek@google.com>
Fri, 21 Jun 2024 17:07:28 +0000 (17:07 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 18 Nov 2024 19:59:59 +0000 (19:59 +0000)
This change uses linkname for the one random function
internal/concurrent needs to avoid taking a dependency on math/rand/v2.
This lowers the bar to using this package.

Change-Id: I9dba1121b66ba35f56521643937f220936ea5321
Reviewed-on: https://go-review.googlesource.com/c/go/+/594057
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

src/go/build/deps_test.go
src/internal/concurrent/hashtriemap.go

index 6a311804188e51a4ee29353289a19d62ec4679c9..dd824471c71b55e7268371765c79ee4ba64b6606 100644 (file)
@@ -103,7 +103,8 @@ var depsRules = `
        < internal/godebug
        < internal/reflectlite
        < errors
-       < internal/oserror;
+       < internal/oserror
+       < internal/concurrent;
 
        cmp, runtime, math/bits
        < iter
@@ -164,9 +165,6 @@ var depsRules = `
        MATH
        < runtime/metrics;
 
-       RUNTIME, math/rand/v2
-       < internal/concurrent;
-
        MATH, unicode/utf8
        < strconv;
 
index fb9223fa29467285f98f88c8def25fe9930a6082..be74a608fa76d8ff2e30634ae9d2b5c5330ffef9 100644 (file)
@@ -7,7 +7,6 @@ package concurrent
 import (
        "internal/abi"
        "internal/goarch"
-       "math/rand/v2"
        "sync"
        "sync/atomic"
        "unsafe"
@@ -34,7 +33,7 @@ func NewHashTrieMap[K, V comparable]() *HashTrieMap[K, V] {
                keyHash:  mapType.Hasher,
                keyEqual: mapType.Key.Equal,
                valEqual: mapType.Elem.Equal,
-               seed:     uintptr(rand.Uint64()),
+               seed:     uintptr(runtime_rand()),
        }
        return ht
 }
@@ -406,3 +405,9 @@ func (n *node[K, V]) indirect() *indirect[K, V] {
        }
        return (*indirect[K, V])(unsafe.Pointer(n))
 }
+
+// Pull in runtime.rand so that we don't need to take a dependency
+// on math/rand/v2.
+//
+//go:linkname runtime_rand runtime.rand
+func runtime_rand() uint64