khr@golang.org 30dff416e4 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>
2026-01-23 20:57:55 -08:00
2024-08-09 14:54:31 +00:00
2010-12-06 16:31:59 -05:00
2024-07-22 17:45:27 +00:00

The Go Programming Language

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

Gopher image Gopher image by Renee French, licensed under Creative Commons 4.0 Attribution license.

Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.

Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.

Download and Install

Binary Distributions

Official binary distributions are available at https://go.dev/dl/.

After downloading a binary release, visit https://go.dev/doc/install for installation instructions.

Install From Source

If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.

Contributing

Go is the work of thousands of contributors. We appreciate your help!

To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.

Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.

Description
Languages
Go 94.7%
Assembly 4.9%
C 0.2%
Shell 0.1%