]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: redo how equality functions are generated
authorkhr@golang.org <khr@golang.org>
Sat, 29 Nov 2025 01:17:24 +0000 (20:17 -0500)
committerKeith Randall <khr@golang.org>
Sat, 24 Jan 2026 04:57:55 +0000 (20:57 -0800)
commit30dff416e42b0bd44237b7658eafc7063dda6b63
tree9203b0e241a45eceb8c4260636d2e796a0666a03
parentf8b72802d7a7dd2bcb81bdaead80be802e16351b
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>
src/cmd/compile/internal/reflectdata/alg.go
src/cmd/compile/internal/walk/compare.go
src/cmd/link/internal/ld/dwarf_test.go