]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add support for alternative comparable semantics
authorRobert Griesemer <gri@golang.org>
Thu, 20 Oct 2022 22:56:11 +0000 (15:56 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 25 Oct 2022 20:28:23 +0000 (20:28 +0000)
Add the experimental compiler flag -altcomparable. If set, the
compiler uses alternative comparable semantics: any ordinary
(non-type parameter) interface implements the comparable
constraint.

This permits experimenting with this alternative semantics
akin to what is proposed in #52509.

For #52509.

Change-Id: I64192eee6f2a550eeb50de011079f2f0b994cf94
Reviewed-on: https://go-review.googlesource.com/c/go/+/444636
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/base/flag.go
src/cmd/compile/internal/noder/irgen.go

index 42273ea35083d6a15eb1d264994623c035766bd9..3e9d86c9bcf792e5754ab27b3b4fd3344b913d77 100644 (file)
@@ -122,7 +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
+       WB                 bool         "help:\"enable write barrier\""                    // TODO: remove
+       AltComparable      bool         "help:\"enable alternative comparable semantics\"" // experiment - remove eventually
 
        // Configuration derived from flags; not a flag itself.
        Cfg struct {
index 57872bce276e4dd0d967fe632a5ef9ad67e56841..4a15c626b908e078799f5621a734839f6206f98c 100644 (file)
@@ -55,8 +55,9 @@ func checkFiles(noders []*noder) (posMap, *types2.Package, *types2.Info) {
                        }
                        base.ErrorfAt(m.makeXPos(terr.Pos), "%s", msg)
                },
-               Importer: &importer,
-               Sizes:    &gcSizes{},
+               Importer:               &importer,
+               Sizes:                  &gcSizes{},
+               AltComparableSemantics: base.Flag.AltComparable, // experiment - remove eventually
        }
        info := &types2.Info{
                StoreTypesInSyntax: true,