From: Robert Griesemer Date: Thu, 12 Jan 2023 18:32:33 +0000 (-0800) Subject: cmd/compile: remove support for old comparable semantics X-Git-Tag: go1.21rc1~1914 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=354c8fb4360ae46f0f978dab7f0b3037f9175e48;p=gostls13.git 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 --- diff --git a/src/cmd/compile/internal/base/flag.go b/src/cmd/compile/internal/base/flag.go index 25f8458e5c..eb3d34f0b1 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 b5e10236ce..dd6e89bcec 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 47075c4499..d9e6d5ad40 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 c7970c59a6..5a46a1447b 100644 --- a/src/cmd/compile/internal/types2/check_test.go +++ b/src/cmd/compile/internal/types2/check_test.go @@ -133,7 +133,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 8193682993..17cdc497bc 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 11e5dfbd04..d59e6d9b49 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 3ba26bfb5a..36809838c7 100644 --- a/src/go/types/check_test.go +++ b/src/go/types/check_test.go @@ -145,7 +145,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 f1448d69d4..8509a31e35 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 11eed7d273..72c6cf7757 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 f783e7a0f7..2c16cfcda4 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 55abb75bf7..828612b428 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 2d0e275fbe..0000000000 --- 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" */] -}