]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "go/types, types2: make the new comparable semantics the default"
authorRobert Griesemer <gri@golang.org>
Thu, 1 Dec 2022 17:09:37 +0000 (09:09 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 1 Dec 2022 18:03:33 +0000 (18:03 +0000)
The CL below was accidentally submitted, while waiting for the freeze
exception. Reverting.

This reverts commit 15e705ea963b5008112793507365e24b743606bc.

Change-Id: I4dbf92dcb01fa9245a6e6a2d1514d8aa898d0048
Reviewed-on: https://go-review.googlesource.com/c/go/+/454476
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Robert Griesemer <gri@google.com>

14 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/comparable.go
src/internal/types/testdata/spec/comparable1.19.go [deleted file]
src/internal/types/testdata/spec/oldcomparable.go [deleted file]

index 25f8458e5cf0283876bf62eab7cafdb01afbc15f..8cb7e96d14b8da62870d5bb5c6496335d0a0d730 100644 (file)
@@ -122,8 +122,8 @@ 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
+       AltComparable      bool         "help:\"enable alternative comparable semantics\"" // experiment - remove eventually
        PgoProfile         string       "help:\"read profile from `file`\""
 
        // Configuration derived from flags; not a flag itself.
index d0349260e85468066fef25b929d4282fe781ec22..c5e2a1f2d17ec3a671801e344fefee78630647a7 100644 (file)
@@ -57,7 +57,7 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
                },
                Importer:               &importer,
                Sizes:                  &gcSizes{},
-               OldComparableSemantics: base.Flag.OldComparable, // default is new comparable semantics
+               AltComparableSemantics: base.Flag.AltComparable, // experiment - remove eventually
        }
        info := &types2.Info{
                StoreTypesInSyntax: true,
index 0befee36912c3c5cc3e6b1e47a8e5820cd3f5fc6..f1b8a2045641475f05995641bc0997485ebc400b 100644 (file)
@@ -168,10 +168,9 @@ type Config struct {
        // 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
+       // If AltComparableSemantics is set, ordinary (non-type parameter)
+       // interfaces satisfy the comparable constraint.
+       AltComparableSemantics bool
 }
 
 func srcimporter_setUsesCgo(conf *Config) {
index c4c28cc04ddbd111d1a2b3cf1c0b11eab8d0e7b4..9a7aef7ac49ce7614f1c768a2fb5564f878dfc40 100644 (file)
@@ -130,7 +130,7 @@ 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, "")
+       flags.BoolVar(&conf.AltComparableSemantics, "altComparableSemantics", false, "")
        if err := parseFlags(filenames[0], nil, flags); err != nil {
                t.Fatal(err)
        }
index 52f60d79a6c9792b18a469900a9c0fa9dffefc65..ff8b70f8a2836d345cd6586efc3fad15e5155470 100644 (file)
@@ -245,39 +245,18 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool
 
        // Only check comparability if we don't have a more specific error.
        checkComparability := func() bool {
-               if !Ti.IsComparable() {
-                       return true
-               }
                // If T is comparable, V must be comparable.
-               // If V is strictly comparable, we're done.
-               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 {
+               // For constraint satisfaction, use dynamic comparability for the
+               // alternative comparable semantics such that ordinary, non-type
+               // parameter interfaces implement comparable.
+               dynamic := constraint && check != nil && check.conf.AltComparableSemantics
+               if Ti.IsComparable() && !comparable(V, dynamic, nil, nil) {
                        if cause != nil {
                                *cause = check.sprintf("%s does not implement comparable", V)
                        }
                        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) {
-                       // V is comparable if we are at Go 1.20 or higher.
-                       if check == nil || check.allowVersion(check.pkg, 1, 20) {
-                               return true
-                       }
-                       if cause != nil {
-                               *cause = check.sprintf("%s to implement comparable requires go1.20 or later", V)
-                       }
-                       return false
-               }
-               if cause != nil {
-                       *cause = check.sprintf("%s does not implement comparable", V)
-               }
-               return false
+               return true
        }
 
        // V must also be in the set of types of T, if any.
index 15e73ba5b70f07be37873ee351feebfa166379aa..06a5cd8c2b9bcf51621fee7719fa2271d36a02eb 100644 (file)
@@ -168,10 +168,9 @@ type Config struct {
        // 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
+       // If altComparableSemantics is set, ordinary (non-type parameter)
+       // interfaces satisfy the comparable constraint.
+       altComparableSemantics bool
 }
 
 func srcimporter_setUsesCgo(conf *Config) {
index 215a836333eb00631dd8f25b0b60a4730e657336..201cf14f3556f52166123d38559416509e6e3721 100644 (file)
@@ -217,7 +217,7 @@ 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(addrOldComparableSemantics(&conf), "oldComparableSemantics", false, "")
+       flags.BoolVar(addrAltComparableSemantics(&conf), "altComparableSemantics", false, "")
        if err := parseFlags(filenames[0], srcs[0], flags); err != nil {
                t.Fatal(err)
        }
@@ -294,10 +294,10 @@ func readCode(err Error) int {
        return int(v.FieldByName("go116code").Int())
 }
 
-// addrOldComparableSemantics(conf) returns &conf.oldComparableSemantics (unexported field).
-func addrOldComparableSemantics(conf *Config) *bool {
+// addrAltComparableSemantics(conf) returns &conf.altComparableSemantics (unexported field).
+func addrAltComparableSemantics(conf *Config) *bool {
        v := reflect.Indirect(reflect.ValueOf(conf))
-       return (*bool)(v.FieldByName("oldComparableSemantics").Addr().UnsafePointer())
+       return (*bool)(v.FieldByName("altComparableSemantics").Addr().UnsafePointer())
 }
 
 // TestManual is for manual testing of a package - either provided
index 59ac1009f51116f9935ce6ba0c9b8102efbb42ac..3b50c6ce33f9d7878ea25d8f462a726663b3880a 100644 (file)
@@ -245,39 +245,18 @@ func (check *Checker) implements(V, T Type, constraint bool, cause *string) bool
 
        // Only check comparability if we don't have a more specific error.
        checkComparability := func() bool {
-               if !Ti.IsComparable() {
-                       return true
-               }
                // If T is comparable, V must be comparable.
-               // If V is strictly comparable, we're done.
-               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 {
+               // For constraint satisfaction, use dynamic comparability for the
+               // alternative comparable semantics such that ordinary, non-type
+               // parameter interfaces implement comparable.
+               dynamic := constraint && check != nil && check.conf.altComparableSemantics
+               if Ti.IsComparable() && !comparable(V, dynamic, nil, nil) {
                        if cause != nil {
                                *cause = check.sprintf("%s does not implement comparable", V)
                        }
                        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) {
-                       // V is comparable if we are at Go 1.20 or higher.
-                       if check == nil || check.allowVersion(check.pkg, 1, 20) {
-                               return true
-                       }
-                       if cause != nil {
-                               *cause = check.sprintf("%s to implement comparable requires go1.20 or later", V)
-                       }
-                       return false
-               }
-               if cause != nil {
-                       *cause = check.sprintf("%s does not implement comparable", V)
-               }
-               return false
+               return true
        }
 
        // V must also be in the set of types of T, if any.
index 02ad822e0f57eabdcf54bb4f9c70148ec1c208c6..b986023cc196a58e58f44423f87799e1e661dccc 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.
index bc53700704b98278077cca7cd8d1884dcf6ac516..3bdba1113a3b473404272353a4ed7d7d43e63719 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.
index 4730c98e2f0c509eddd10e77482136d540130119..8a3eb3278de9b462534e9b82876bc3951b353c0f 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.
index 03c8471393b014af22cbd58fc7ca6aa193b7bc3a..8dbbb4e33795e5b379390b1ca5638e601406d7c6 100644 (file)
@@ -1,3 +1,5 @@
+// -altComparableSemantics
+
 // 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.
diff --git a/src/internal/types/testdata/spec/comparable1.19.go b/src/internal/types/testdata/spec/comparable1.19.go
deleted file mode 100644 (file)
index c9c87e4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-// -lang=go1.19
-
-// 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 to implement comparable requires go1\.20 or later */]
-       _ = f1[any /* ERROR any to implement comparable requires go1\.20 or later */]
-       _ = f1[P]
-       _ = f1[Q]
-       _ = f1[R /* ERROR R does not implement comparable */]
-
-       _ = f2[int]
-       _ = f2[T /* ERROR T to implement comparable requires go1\.20 or later */]
-       _ = f2[any /* ERROR any to implement comparable requires go1\.20 or later */]
-       _ = f2[P]
-       _ = f2[Q]
-       _ = f2[R /* ERROR R does not implement comparable */]
-}
diff --git a/src/internal/types/testdata/spec/oldcomparable.go b/src/internal/types/testdata/spec/oldcomparable.go
deleted file mode 100644 (file)
index 9f6cf74..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 implement comparable */]
-       _ = f1[any /* ERROR any does not implement comparable */]
-       _ = f1[P]
-       _ = f1[Q]
-       _ = f1[R /* ERROR R does not implement comparable */]
-
-       _ = f2[int]
-       _ = f2[T /* ERROR T does not implement comparable */]
-       _ = f2[any /* ERROR any does not implement comparable */]
-       _ = f2[P]
-       _ = f2[Q]
-       _ = f2[R /* ERROR R does not implement comparable */]
-}