aboutsummaryrefslogtreecommitdiff
path: root/src/strings
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2024-03-22 21:42:02 +0000
committerGopher Robot <gobot@golang.org>2024-04-17 21:09:59 +0000
commit4742c52e101ecf4aacebe5148a1cb172bdadb1d4 (patch)
tree7e405c1591233beaca9c0e75d945e9386183001c /src/strings
parent2073b35e07ce9cea47ee1fbe763b304d2371954f (diff)
downloadgo-4742c52e101ecf4aacebe5148a1cb172bdadb1d4.tar.xz
internal/abi: define EmptyInterface, TypeOf, and NoEscape
This change defines two commonly-defined functions and a commonly-defined type in internal/abi to try and deduplicate some definitions. This is motivated by a follow-up CL which will want access to TypeOf in yet another package. There still exist duplicate definitions of all three of these things in the runtime, and this CL doesn't try to handle that yet. There are far too many uses in the runtime to handle manually in a way that feels comfortable; automated refactoring will help. For #62483. Change-Id: I02fc64a28f11af618f6071f94d27f45c135fa8ac Reviewed-on: https://go-review.googlesource.com/c/go/+/573955 Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/strings')
-rw-r--r--src/strings/builder.go16
1 files changed, 2 insertions, 14 deletions
diff --git a/src/strings/builder.go b/src/strings/builder.go
index 7c9b686241..e6df08c6f4 100644
--- a/src/strings/builder.go
+++ b/src/strings/builder.go
@@ -5,6 +5,7 @@
package strings
import (
+ "internal/abi"
"internal/bytealg"
"unicode/utf8"
"unsafe"
@@ -22,19 +23,6 @@ type Builder struct {
buf []byte
}
-// noescape hides a pointer from escape analysis. It is the identity function
-// but escape analysis doesn't think the output depends on the input.
-// noescape is inlined and currently compiles down to zero instructions.
-// USE CAREFULLY!
-// This was copied from the runtime; see issues 23382 and 7921.
-//
-//go:nosplit
-//go:nocheckptr
-func noescape(p unsafe.Pointer) unsafe.Pointer {
- x := uintptr(p)
- return unsafe.Pointer(x ^ 0)
-}
-
func (b *Builder) copyCheck() {
if b.addr == nil {
// This hack works around a failing of Go's escape analysis
@@ -42,7 +30,7 @@ func (b *Builder) copyCheck() {
// See issue 23382.
// TODO: once issue 7921 is fixed, this should be reverted to
// just "b.addr = b".
- b.addr = (*Builder)(noescape(unsafe.Pointer(b)))
+ b.addr = (*Builder)(abi.NoEscape(unsafe.Pointer(b)))
} else if b.addr != b {
panic("strings: illegal use of non-zero Builder copied by value")
}