Skip to content

Commit 1e65e04

Browse files
griesemereric
authored andcommitted
cmd/compile: remove support for old comparable semantics
Change-Id: I730da5082ea6de1510482aabaa2915e83d3819a5 Reviewed-on: https://go-review.googlesource.com/c/go/+/461607 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com>
1 parent 8ea978c commit 1e65e04

File tree

12 files changed

+11
-77
lines changed

12 files changed

+11
-77
lines changed

src/cmd/compile/internal/base/flag.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ type CmdFlags struct {
122122
SymABIs string "help:\"read symbol ABIs from `file`\""
123123
TraceProfile string "help:\"write an execution trace to `file`\""
124124
TrimPath string "help:\"remove `prefix` from recorded source file paths\""
125-
WB bool "help:\"enable write barrier\"" // TODO: remove
126-
OldComparable bool "help:\"enable old comparable semantics\"" // TODO: remove for Go 1.21
125+
WB bool "help:\"enable write barrier\"" // TODO: remove
127126
PgoProfile string "help:\"read profile from `file`\""
128127

129128
// Configuration derived from flags; not a flag itself.

src/cmd/compile/internal/noder/irgen.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
5555
}
5656
base.ErrorfAt(m.makeXPos(terr.Pos), "%s", msg)
5757
},
58-
Importer: &importer,
59-
Sizes: &gcSizes{},
60-
OldComparableSemantics: base.Flag.OldComparable, // default is new comparable semantics
58+
Importer: &importer,
59+
Sizes: &gcSizes{},
6160
}
6261
info := &types2.Info{
6362
StoreTypesInSyntax: true,

src/cmd/compile/internal/types2/api.go

-5
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,6 @@ type Config struct {
167167
// If DisableUnusedImportCheck is set, packages are not checked
168168
// for unused imports.
169169
DisableUnusedImportCheck bool
170-
171-
// If OldComparableSemantics is set, ordinary (non-type parameter)
172-
// interfaces do not satisfy the comparable constraint.
173-
// TODO(gri) remove this flag for Go 1.21
174-
OldComparableSemantics bool
175170
}
176171

177172
func srcimporter_setUsesCgo(conf *Config) {

src/cmd/compile/internal/types2/check_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
126126
flags := flag.NewFlagSet("", flag.PanicOnError)
127127
flags.StringVar(&conf.GoVersion, "lang", "", "")
128128
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
129-
flags.BoolVar(&conf.OldComparableSemantics, "oldComparableSemantics", false, "")
130129
if err := parseFlags(filenames[0], nil, flags); err != nil {
131130
t.Fatal(err)
132131
}

src/cmd/compile/internal/types2/instantiate.go

-9
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,6 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool
258258
if comparable(V, false /* strict comparability */, nil, nil) {
259259
return true
260260
}
261-
// If check.conf.OldComparableSemantics is set (by the compiler or
262-
// a test), we only consider strict comparability and we're done.
263-
// TODO(gri) remove this check for Go 1.21
264-
if check != nil && check.conf.OldComparableSemantics {
265-
if cause != nil {
266-
*cause = check.sprintf("%s does not %s comparable", V, verb)
267-
}
268-
return false
269-
}
270261
// For constraint satisfaction, use dynamic (spec) comparability
271262
// so that ordinary, non-type parameter interfaces implement comparable.
272263
if constraint && comparable(V, true /* spec comparability */, nil, nil) {

src/go/types/api.go

-5
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@ type Config struct {
170170
// If DisableUnusedImportCheck is set, packages are not checked
171171
// for unused imports.
172172
DisableUnusedImportCheck bool
173-
174-
// If oldComparableSemantics is set, ordinary (non-type parameter)
175-
// interfaces do not satisfy the comparable constraint.
176-
// TODO(gri) remove this flag for Go 1.21
177-
oldComparableSemantics bool
178173
}
179174

180175
func srcimporter_setUsesCgo(conf *Config) {

src/go/types/check_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man
138138
flags := flag.NewFlagSet("", flag.PanicOnError)
139139
flags.StringVar(&conf.GoVersion, "lang", "", "")
140140
flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "")
141-
flags.BoolVar(boolFieldAddr(&conf, "oldComparableSemantics"), "oldComparableSemantics", false, "")
142141
if err := parseFlags(filenames[0], srcs[0], flags); err != nil {
143142
t.Fatal(err)
144143
}

src/go/types/instantiate.go

-9
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,6 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool
258258
if comparable(V, false /* strict comparability */, nil, nil) {
259259
return true
260260
}
261-
// If check.conf.OldComparableSemantics is set (by the compiler or
262-
// a test), we only consider strict comparability and we're done.
263-
// TODO(gri) remove this check for Go 1.21
264-
if check != nil && check.conf.oldComparableSemantics {
265-
if cause != nil {
266-
*cause = check.sprintf("%s does not %s comparable", V, verb)
267-
}
268-
return false
269-
}
270261
// For constraint satisfaction, use dynamic (spec) comparability
271262
// so that ordinary, non-type parameter interfaces implement comparable.
272263
if constraint && comparable(V, true /* spec comparability */, nil, nil) {

src/internal/types/testdata/check/issues1.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// -oldComparableSemantics
2-
31
// Copyright 2020 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
@@ -22,7 +20,7 @@ func _[X comparable, Y interface{comparable; m()}]() {
2220
eql(x, x)
2321
eql(y, y)
2422
eql(y, nil /* ERROR "cannot use nil as Y value in argument to eql" */ )
25-
eql[io /* ERROR "does not satisfy comparable" */ .Reader](nil, nil)
23+
eql[io.Reader](nil, nil)
2624
}
2725

2826
// If we have a receiver of pointer to type parameter type (below: *T)

src/internal/types/testdata/fixedbugs/issue50646.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// -oldComparableSemantics
2-
31
// Copyright 2022 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
@@ -13,15 +11,15 @@ type T interface{ m() }
1311

1412
func _[P comparable, Q ~int, R any]() {
1513
_ = f1[int]
16-
_ = f1[T /* ERROR "T does not satisfy comparable" */ ]
17-
_ = f1[any /* ERROR "any does not satisfy comparable" */ ]
14+
_ = f1[T]
15+
_ = f1[any]
1816
_ = f1[P]
1917
_ = f1[Q]
2018
_ = f1[R /* ERROR "R does not satisfy comparable" */]
2119

2220
_ = f2[int]
23-
_ = f2[T /* ERROR "T does not satisfy comparable" */ ]
24-
_ = f2[any /* ERROR "any does not satisfy comparable" */ ]
21+
_ = f2[T]
22+
_ = f2[any]
2523
_ = f2[P]
2624
_ = f2[Q]
2725
_ = f2[R /* ERROR "R does not satisfy comparable" */]

src/internal/types/testdata/fixedbugs/issue51257.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// -oldComparableSemantics
2-
31
// Copyright 2022 The Go Authors. All rights reserved.
42
// Use of this source code is governed by a BSD-style
53
// license that can be found in the LICENSE file.
@@ -14,8 +12,8 @@ type S3 struct{ x [10]interface{ m() } }
1412

1513
func _[P1 comparable, P2 S2]() {
1614
_ = f[S1]
17-
_ = f[S2 /* ERROR "S2 does not satisfy comparable" */ ]
18-
_ = f[S3 /* ERROR "S3 does not satisfy comparable" */ ]
15+
_ = f[S2]
16+
_ = f[S3]
1917

2018
type L1 struct { x P1 }
2119
type L2 struct { x P2 }
@@ -41,7 +39,7 @@ func NewSetFromSlice[T comparable](items []T) *Set[T] {
4139
type T struct{ x any }
4240

4341
func main() {
44-
NewSetFromSlice /* ERROR "T does not satisfy comparable" */ ([]T{
42+
NewSetFromSlice([]T{
4543
{"foo"},
4644
{5},
4745
})

src/internal/types/testdata/spec/oldcomparable.go

-28
This file was deleted.

0 commit comments

Comments
 (0)