aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link/internal
diff options
context:
space:
mode:
authorkhr@golang.org <khr@golang.org>2025-11-28 20:17:24 -0500
committerKeith Randall <khr@golang.org>2026-01-23 20:57:55 -0800
commit30dff416e42b0bd44237b7658eafc7063dda6b63 (patch)
tree9203b0e241a45eceb8c4260636d2e796a0666a03 /src/cmd/link/internal
parentf8b72802d7a7dd2bcb81bdaead80be802e16351b (diff)
downloadgo-30dff416e42b0bd44237b7658eafc7063dda6b63.tar.xz
cmd/compile: redo how equality functions are generated
Instead of generating an equality function for each type that needs it, generate one per "signature". A "signature" is a summary of the comparisons needed to check a type for equality. For instance, the type type S struct { i int32 j uint32 s string e error } Will have the signature "M8SI". M8 = 8 bytes of regular memory S = string I = nonempty interface This way, potentially many types that have the same signature can share the same equality function. The number of generated equality functions in the go binary is reduced from 634 to 286. The go binary is ~1% smaller. The generation of equality functions gets simpler (particularly, how we do inlining of sub-types, unrolling, etc.) and the generated code is probably a bit more efficient. The new function names are kind of weird, but will seldom show up for users. They will appear in cpu profiles, and in tracebacks in the situation where comparisons panic because an interface somewhere in the type being compared contains an uncomparable type (e.g. a slice). Note that this CL only affects generated comparison functions. It does not generally affect generated code for == (except when that code decides to call a comparison function as a subtask). Maybe a TODO for the future. Update #6853 Change-Id: I202bd6424cb6bf7c745a62c9603d4f01dc1a1fc8 Reviewed-on: https://go-review.googlesource.com/c/go/+/725380 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@google.com>
Diffstat (limited to 'src/cmd/link/internal')
-rw-r--r--src/cmd/link/internal/ld/dwarf_test.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go
index cc493f2c69..34855fc50c 100644
--- a/src/cmd/link/internal/ld/dwarf_test.go
+++ b/src/cmd/link/internal/ld/dwarf_test.go
@@ -893,6 +893,10 @@ func main() {
var x interface{} = &X{}
p := *(*uintptr)(unsafe.Pointer(&x))
print(p)
+ f(nil)
+}
+//go:noinline
+func f(x *X) { // Make sure that there is dwarf recorded for *X.
}
`
dir := t.TempDir()