Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: enable new comparable behavior by default [freeze exception] #57011

Closed
griesemer opened this issue Nov 30, 2022 · 4 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Milestone

Comments

@griesemer
Copy link
Contributor

griesemer commented Nov 30, 2022

Proposal #56548 which allows ordinary interfaces to implement comparable has been accepted today. We would like to incorporate this into 1.20 as it will directly influence the kind of generic code people will be able to write.

The respective change was implemented a while ago in go/types, types2, and the compiler, and could be enabled with a compiler flag: -altcomparable (see CL 444635 and CL 444636). By default, the feature was disabled.

I would like to request a freeze exception to enable the feature by default.

CL 454575 makes the new behavior the default and Go 1.20 version dependent, and provides error messages reporting version issues, and adds more tests.

Safety of the change:
If there are any suspected problems with the change, a) by setting the compiler flag -oldcomparable we can confirm if there's an issue related to this change in the first place; and b) if we decide to roll back, all we need to do is to change the flag default (or roll back the CL).

Finally, I note that the new behavior for comparable is in fact the behavior we had implemented until about 6 weeks before the release of Go 1.18, when people perceived an apparent inconsistency (see issue #50646 which was closed on Feb 1, 2022). To err on the side of caution we deliberately restricted what types would satisfy comparable. At this point, and after many proposals and discussions (for a list see #56548), we agreed that the original behavior was in fact what people expect. With the changes here we simply re-establish this original behavior.

cc: golang/release

@griesemer griesemer added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker labels Nov 30, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Nov 30, 2022
@griesemer griesemer changed the title cmd/compile: enable new comparable behavior by default [freeze exception] cmd/compile: enable new comparable behavior by default [freeze exception] Nov 30, 2022
@ianlancetaylor
Copy link
Contributor

CC @golang/release

@ianlancetaylor ianlancetaylor added this to the Go1.20 milestone Nov 30, 2022
@heschi
Copy link
Contributor

heschi commented Dec 1, 2022

Approved after offline discussion. In the future, if it looks like there's going to be trouble with the timeline for a feature like this please let us know and we'll try to see if we can smooth things over.

@gopherbot
Copy link

Change https://go.dev/cl/454575 mentions this issue: go/types, types2: make the new comparable semantics the default

gopherbot pushed a commit that referenced this issue Dec 1, 2022
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>
@griesemer
Copy link
Contributor Author

This change has been submitted. Closing.

@golang golang locked and limited conversation to collaborators Dec 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants