Imports #
"internal/abi"
isync "internal/sync"
"runtime"
"sync"
"unsafe"
"weak"
"internal/abi"
"internal/stringslite"
"unsafe"
"internal/abi"
isync "internal/sync"
"runtime"
"sync"
"unsafe"
"weak"
"internal/abi"
"internal/stringslite"
"unsafe"
var cleanupFuncs []func()
var cleanupFuncsMu sync.Mutex
cleanupFuncs are functions that clean up dead weak pointers in type-specific maps in uniqueMaps. We express cleanup this way because there's no way to iterate over the sync.Map and call functions on the type-specific data structures otherwise. These cleanup funcs each close over one of these type-specific maps. cleanupMu protects cleanupNotify and is held across the entire cleanup. Used for testing. cleanupNotify is a test-only mechanism that allow tests to wait for the cleanup to run.
var cleanupMu sync.Mutex
var cleanupNotify []func()
setupMake is used to perform initial setup for unique.Make.
var setupMake sync.Once
singleStringClone describes how to clone a single string.
var singleStringClone = cloneSeq{...}
uniqueMaps is an index of type-specific concurrent maps used for unique.Make. The two-level map might seem odd at first since the HashTrieMap could have "any" as its key type, but the issue is escape analysis. We do not want to force lookups to escape the argument, and using a type-specific map allows us to avoid that where possible (for example, for strings and plain-ol'-data structs). We also get the benefit of not cramming every different type into a single map, but that's certainly not enough to outweigh the cost of two map lookups. What is worth it though, is saving on those allocations.
var uniqueMaps *ast.IndexListExpr
var zero uintptr
Handle is a globally unique identity for some value of type T. Two handles compare equal exactly if the two values used to create the handles would have also compared equal. The comparison of two handles is trivial and typically much more efficient than comparing the values used to create them.
type Handle struct {
value *T
}
cloneSeq describes how to clone a value of a particular type.
type cloneSeq struct {
stringOffsets []uintptr
}
type uniqueMap struct {
*ast.IndexListExpr
cloneSeq
}
Make returns a globally unique handle for a value of type T. Handles are equal if and only if the values used to produce them are equal. Make is safe for concurrent use by multiple goroutines.
func Make(value T) *ast.IndexExpr
Value returns a shallow copy of the T value that produced the Handle. Value is safe for concurrent use by multiple goroutines.
func (h *ast.IndexExpr) Value() T
func addUniqueMap(typ *abi.Type) **ast.IndexExpr
buildArrayCloneSeq populates a cloneSeq for an abi.Type that has Kind abi.Array.
func buildArrayCloneSeq(typ *abi.Type, seq *cloneSeq, baseOffset uintptr)
buildStructCloneSeq populates a cloneSeq for an abi.Type that has Kind abi.Struct.
func buildStructCloneSeq(typ *abi.Type, seq *cloneSeq, baseOffset uintptr)
clone makes a copy of value, and may update string values found in value with a cloned version of those strings. The purpose of explicitly cloning strings is to avoid accidentally giving a large string a long lifetime. Note that this will clone strings in structs and arrays found in value, and will clone value if it itself is a string. It will not, however, clone strings if value is of interface or slice type (that is, found via an indirection).
func clone(value T, seq *cloneSeq) T
makeCloneSeq creates a cloneSeq for a type.
func makeCloneSeq(typ *abi.Type) cloneSeq
startBackgroundCleanup sets up a background goroutine to occasionally call cleanupFuncs.
func registerCleanup()
go:linkname runtime_registerUniqueMapCleanup
func runtime_registerUniqueMapCleanup(cleanup func())
Generated with Arrow