]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: make the new comparable semantics the default
authorRobert Griesemer <gri@golang.org>
Thu, 1 Dec 2022 17:39:45 +0000 (09:39 -0800)
committerRobert Griesemer <gri@google.com>
Thu, 1 Dec 2022 19:48:07 +0000 (19:48 +0000)
commit8fd2875c3e9455df722dd3c930332591eebbb3c2
treeeb7025c1a23cb59144d7d696b24d15db512857be
parentaf1a5d92871129e5fff093bcb3518b1ebfc86976
go/types, types2: make the new comparable semantics the default

Ordinary interface types now satisfy comparable constraints. This
is a fully backward-compatible change: it simply permits additional
code to be valid that wasn't valid before.

This change makes the new comparable semantics the default behavior,
depending on the Go -lang version.

It also renames the flag types2.Config.AltComparableSemantics to
types2.Config.OldComparableSemantics and inverts its meaning
(or types.Config.oldComparableSemantics respectively).

Add new predicate Satisfies (matching the predicate Implements but
for constraint satisfaction), per the proposal description.

Adjust some existing tests by setting -oldComparableSemantics
and add some new tests that verify version-dependent behavior.

The compiler flag -oldcomparable may be used to temporarily
switch back to the Go 1.18/1.19 behavior should this change
cause problems, or to identify that a problem is unrelated
to this change. The flag will be removed for Go 1.21.

For #52509.
For #56548.
For #57011.

Change-Id: I8b3b3d9d492fc24b0693567055f0053ccb5aeb42
Reviewed-on: https://go-review.googlesource.com/c/go/+/454575
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
15 files changed:
api/next/56548.txt [new file with mode: 0644]
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/instantiate.go
src/go/types/api.go
src/go/types/check_test.go
src/go/types/instantiate.go
src/internal/types/testdata/check/issues1.go
src/internal/types/testdata/fixedbugs/issue50646.go
src/internal/types/testdata/fixedbugs/issue51257.go
src/internal/types/testdata/spec/comparable.go
src/internal/types/testdata/spec/comparable1.19.go [new file with mode: 0644]
src/internal/types/testdata/spec/oldcomparable.go [new file with mode: 0644]