]> Cypherpunks repositories - gostls13.git/commit
hash/maphash, cmd/compile: make Comparable[string] not escape its argument
authorCherry Mui <cherryyz@google.com>
Mon, 2 Dec 2024 04:53:23 +0000 (23:53 -0500)
committerCherry Mui <cherryyz@google.com>
Mon, 2 Dec 2024 21:27:06 +0000 (21:27 +0000)
commit50a8b3a30ec104ce00533db47e7200e01371eaa0
tree22842786e477e37d4df3bb57e1cf7b4182cc0bb2
parent7632c6e2bd67b37a943f2714f3e53eebb354e18a
hash/maphash, cmd/compile: make Comparable[string] not escape its argument

Currently, maphash.Comparable forces its argument to escape if it
contains a pointer, as we cannot hash stack pointers, which will
change when the stack moves. However, for a string, it is actually
okay if its data pointer points to the stack, as the hash depends
on only the content, not the pointer.

Currently there is no way to write this type-dependent escape
logic in Go code. So we implement it in the compiler as an
intrinsic. The compiler can also recognize not just the string
type, but types whose pointers are all string pointers, and make
them not escape.

Fixes #70560.

Change-Id: I3bf219ad71a238d2e35f0ea33de96487bc8cc231
Reviewed-on: https://go-review.googlesource.com/c/go/+/632715
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/compile/internal/escape/call.go
src/cmd/compile/internal/inline/inl.go
src/cmd/compile/internal/walk/expr.go
src/hash/maphash/maphash.go
src/hash/maphash/maphash_purego.go
src/hash/maphash/maphash_runtime.go
src/hash/maphash/maphash_test.go