]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove support for old comparable semantics
authorRobert Griesemer <gri@golang.org>
Thu, 12 Jan 2023 18:32:33 +0000 (10:32 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 17 Jan 2023 19:56:37 +0000 (19:56 +0000)
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>

12 files changed:
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/oldcomparable.go [deleted file]

index 25f8458e5cf0283876bf62eab7cafdb01afbc15f..eb3d34f0b1e39bd155ebb57b7d746c8dba6016ee 100644 (file)
@@ -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.
index b5e10236ce8978b27e5510d313fb79d0d013c510..dd6e89bceca60669b0d07f07c72bfd1f3f8b8627 100644 (file)
@@ -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,
index 47075c4499ab2b0eff506948f4219d6278342855..d9e6d5ad40e9749e397e25a8138ca94fa081f766 100644 (file)
@@ -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) {
index c7970c59a6da235b8824cf7ced3b40f102606cf4..5a46a1447b47c634b98261ccbd2a432f24639bdb 100644 (file)
@@ -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)
        }
index 819368299386078856154283b68f5e210cc07ffd..17cdc497bcd2c5c7288ae278db9c06430514d017 100644 (file)
@@ -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) {
index 11e5dfbd0431f9d65d54e22ff897fd6575c8e09c..d59e6d9b490f7b6ee6b5917fa3f399970119cca7 100644 (file)
@@ -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) {
index 3ba26bfb5a6fdbd07e22788aa889778093b0f332..36809838c7c988cb75ce080e3086731788792345 100644 (file)
@@ -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)
        }
index f1448d69d4bf2c4ea06d8d72673db2bf7dc1988f..8509a31e35e55fdda3ee71e964894a62a0c100b2 100644 (file)
@@ -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) {
index 11eed7d27374154d7adee84b7c154d673e74243e..72c6cf775746ed968ae5af68db95f3087303dfac 100644 (file)
@@ -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)
index f783e7a0f7ddfd81dd3822615de80209dde2eda5..2c16cfcda46f012f17622975c6edef55338fe582 100644 (file)
@@ -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" */]
index 55abb75bf7b6ed642d0d6400796ab7bca1556b06..828612b4283f2b605b17e06831d055637cf7334a 100644 (file)
@@ -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 (file)
index 2d0e275..0000000
+++ /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" */]
-}