From e9b6264ec08ee1ab818779d522a91d850837b17e Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 12 Jan 2023 10:32:33 -0800 Subject: [PATCH] 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 Auto-Submit: Robert Griesemer Reviewed-by: Robert Findley TryBot-Result: Gopher Robot Run-TryBot: Robert Griesemer --- src/cmd/compile/internal/base/flag.go | 3 +- src/cmd/compile/internal/noder/irgen.go | 5 ++-- src/cmd/compile/internal/types2/api.go | 5 ---- src/cmd/compile/internal/types2/check_test.go | 1 - .../compile/internal/types2/instantiate.go | 9 ------ src/go/types/api.go | 5 ---- src/go/types/check_test.go | 1 - src/go/types/instantiate.go | 9 ------ src/internal/types/testdata/check/issues1.go | 4 +-- .../types/testdata/fixedbugs/issue50646.go | 10 +++---- .../types/testdata/fixedbugs/issue51257.go | 8 ++---- .../types/testdata/spec/oldcomparable.go | 28 ------------------- 12 files changed, 11 insertions(+), 77 deletions(-) delete mode 100644 src/internal/types/testdata/spec/oldcomparable.go diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index be555c3d060cb..84a89feb4c2e8 100644 --- a/src/cmd/compile/internal/base/flag.go +++ b/src/cmd/compile/internal/base/flag.go @@ -122,8 +122,7 @@ type CmdFlags struct { SymABIs string "help:\"read symbol ABIs from `file`\"" TraceProfile string "help:\"write an execution trace to `file`\"" TrimPath string "help:\"remove `prefix` from recorded source file paths\"" - WB bool "help:\"enable write barrier\"" // TODO: remove - OldComparable bool "help:\"enable old comparable semantics\"" // TODO: remove for Go 1.21 + WB bool "help:\"enable write barrier\"" // TODO: remove PgoProfile string "help:\"read profile from `file`\"" // Configuration derived from flags; not a flag itself. diff --git a/src/cmd/compile/internal/noder/irgen.go b/src/cmd/compile/internal/noder/irgen.go index d0349260e8546..1b0161a1a7a98 100644 --- a/src/cmd/compile/internal/noder/irgen.go +++ b/src/cmd/compile/internal/noder/irgen.go @@ -55,9 +55,8 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) { } base.ErrorfAt(m.makeXPos(terr.Pos), "%s", msg) }, - Importer: &importer, - Sizes: &gcSizes{}, - OldComparableSemantics: base.Flag.OldComparable, // default is new comparable semantics + Importer: &importer, + Sizes: &gcSizes{}, } info := &types2.Info{ StoreTypesInSyntax: true, diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go index 47075c4499ab2..d9e6d5ad40e97 100644 --- a/src/cmd/compile/internal/types2/api.go +++ b/src/cmd/compile/internal/types2/api.go @@ -167,11 +167,6 @@ type Config struct { // If DisableUnusedImportCheck is set, packages are not checked // for unused imports. DisableUnusedImportCheck bool - - // If OldComparableSemantics is set, ordinary (non-type parameter) - // interfaces do not satisfy the comparable constraint. - // TODO(gri) remove this flag for Go 1.21 - OldComparableSemantics bool } func srcimporter_setUsesCgo(conf *Config) { diff --git a/src/cmd/compile/internal/types2/check_test.go b/src/cmd/compile/internal/types2/check_test.go index a33ae8e8217a0..80dc22ba904b4 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -126,7 +126,6 @@ func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) { flags := flag.NewFlagSet("", flag.PanicOnError) flags.StringVar(&conf.GoVersion, "lang", "", "") flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "") - flags.BoolVar(&conf.OldComparableSemantics, "oldComparableSemantics", false, "") if err := parseFlags(filenames[0], nil, flags); err != nil { t.Fatal(err) } diff --git a/src/cmd/compile/internal/types2/instantiate.go b/src/cmd/compile/internal/types2/instantiate.go index 8193682993860..17cdc497bcd2c 100644 --- a/src/cmd/compile/internal/types2/instantiate.go +++ b/src/cmd/compile/internal/types2/instantiate.go @@ -258,15 +258,6 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool if comparable(V, false /* strict comparability */, nil, nil) { return true } - // If check.conf.OldComparableSemantics is set (by the compiler or - // a test), we only consider strict comparability and we're done. - // TODO(gri) remove this check for Go 1.21 - if check != nil && check.conf.OldComparableSemantics { - if cause != nil { - *cause = check.sprintf("%s does not %s comparable", V, verb) - } - return false - } // For constraint satisfaction, use dynamic (spec) comparability // so that ordinary, non-type parameter interfaces implement comparable. if constraint && comparable(V, true /* spec comparability */, nil, nil) { diff --git a/src/go/types/api.go b/src/go/types/api.go index d9d561c25dc73..d95f1fd12d1dc 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -170,11 +170,6 @@ type Config struct { // If DisableUnusedImportCheck is set, packages are not checked // for unused imports. DisableUnusedImportCheck bool - - // If oldComparableSemantics is set, ordinary (non-type parameter) - // interfaces do not satisfy the comparable constraint. - // TODO(gri) remove this flag for Go 1.21 - oldComparableSemantics bool } func srcimporter_setUsesCgo(conf *Config) { diff --git a/src/go/types/check_test.go b/src/go/types/check_test.go index c73b04d3d8ad7..89a0ae6e5aaec 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -138,7 +138,6 @@ func testFiles(t *testing.T, sizes Sizes, filenames []string, srcs [][]byte, man flags := flag.NewFlagSet("", flag.PanicOnError) flags.StringVar(&conf.GoVersion, "lang", "", "") flags.BoolVar(&conf.FakeImportC, "fakeImportC", false, "") - flags.BoolVar(boolFieldAddr(&conf, "oldComparableSemantics"), "oldComparableSemantics", false, "") if err := parseFlags(filenames[0], srcs[0], flags); err != nil { t.Fatal(err) } diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 2cf48c17d298d..0b5b607287ac9 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -258,15 +258,6 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool if comparable(V, false /* strict comparability */, nil, nil) { return true } - // If check.conf.OldComparableSemantics is set (by the compiler or - // a test), we only consider strict comparability and we're done. - // TODO(gri) remove this check for Go 1.21 - if check != nil && check.conf.oldComparableSemantics { - if cause != nil { - *cause = check.sprintf("%s does not %s comparable", V, verb) - } - return false - } // For constraint satisfaction, use dynamic (spec) comparability // so that ordinary, non-type parameter interfaces implement comparable. if constraint && comparable(V, true /* spec comparability */, nil, nil) { diff --git a/src/internal/types/testdata/check/issues1.go b/src/internal/types/testdata/check/issues1.go index efde922cd28af..76c691e0d3df6 100644 --- a/src/internal/types/testdata/check/issues1.go +++ b/src/internal/types/testdata/check/issues1.go @@ -1,5 +1,3 @@ -// -oldComparableSemantics - // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -22,7 +20,7 @@ func _[X comparable, Y interface{comparable; m()}]() { eql(x, x) eql(y, y) eql(y, nil /* ERROR "cannot use nil as Y value in argument to eql" */ ) - eql[io /* ERROR "does not satisfy comparable" */ .Reader](nil, nil) + eql[io.Reader](nil, nil) } // If we have a receiver of pointer to type parameter type (below: *T) diff --git a/src/internal/types/testdata/fixedbugs/issue50646.go b/src/internal/types/testdata/fixedbugs/issue50646.go index f783e7a0f7ddf..2c16cfcda46f0 100644 --- a/src/internal/types/testdata/fixedbugs/issue50646.go +++ b/src/internal/types/testdata/fixedbugs/issue50646.go @@ -1,5 +1,3 @@ -// -oldComparableSemantics - // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -13,15 +11,15 @@ type T interface{ m() } func _[P comparable, Q ~int, R any]() { _ = f1[int] - _ = f1[T /* ERROR "T does not satisfy comparable" */ ] - _ = f1[any /* ERROR "any does not satisfy comparable" */ ] + _ = f1[T] + _ = f1[any] _ = f1[P] _ = f1[Q] _ = f1[R /* ERROR "R does not satisfy comparable" */] _ = f2[int] - _ = f2[T /* ERROR "T does not satisfy comparable" */ ] - _ = f2[any /* ERROR "any does not satisfy comparable" */ ] + _ = f2[T] + _ = f2[any] _ = f2[P] _ = f2[Q] _ = f2[R /* ERROR "R does not satisfy comparable" */] diff --git a/src/internal/types/testdata/fixedbugs/issue51257.go b/src/internal/types/testdata/fixedbugs/issue51257.go index 55abb75bf7b6e..828612b4283f2 100644 --- a/src/internal/types/testdata/fixedbugs/issue51257.go +++ b/src/internal/types/testdata/fixedbugs/issue51257.go @@ -1,5 +1,3 @@ -// -oldComparableSemantics - // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -14,8 +12,8 @@ type S3 struct{ x [10]interface{ m() } } func _[P1 comparable, P2 S2]() { _ = f[S1] - _ = f[S2 /* ERROR "S2 does not satisfy comparable" */ ] - _ = f[S3 /* ERROR "S3 does not satisfy comparable" */ ] + _ = f[S2] + _ = f[S3] type L1 struct { x P1 } type L2 struct { x P2 } @@ -41,7 +39,7 @@ func NewSetFromSlice[T comparable](items []T) *Set[T] { type T struct{ x any } func main() { - NewSetFromSlice /* ERROR "T does not satisfy comparable" */ ([]T{ + NewSetFromSlice([]T{ {"foo"}, {5}, }) diff --git a/src/internal/types/testdata/spec/oldcomparable.go b/src/internal/types/testdata/spec/oldcomparable.go deleted file mode 100644 index 2d0e275fbe96f..0000000000000 --- a/src/internal/types/testdata/spec/oldcomparable.go +++ /dev/null @@ -1,28 +0,0 @@ -// -oldComparableSemantics - -// Copyright 2022 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package p - -func f1[_ comparable]() {} -func f2[_ interface{ comparable }]() {} - -type T interface{ m() } - -func _[P comparable, Q ~int, R any]() { - _ = f1[int] - _ = f1[T /* ERROR "T does not satisfy comparable" */] - _ = f1[any /* ERROR "any does not satisfy comparable" */] - _ = f1[P] - _ = f1[Q] - _ = f1[R /* ERROR "R does not satisfy comparable" */] - - _ = f2[int] - _ = f2[T /* ERROR "T does not satisfy comparable" */] - _ = f2[any /* ERROR "any does not satisfy comparable" */] - _ = f2[P] - _ = f2[Q] - _ = f2[R /* ERROR "R does not satisfy comparable" */] -}