Skip to content

Commit

Permalink
cmd/compile: remove support for old comparable semantics
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
griesemer authored and eric committed Sep 7, 2023
1 parent 8ea978c commit 1e65e04
Show file tree
Hide file tree
Showing 12 changed files with 11 additions and 77 deletions.
3 changes: 1 addition & 2 deletions src/cmd/compile/internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/compile/internal/noder/irgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/cmd/compile/internal/types2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/cmd/compile/internal/types2/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 0 additions & 9 deletions src/cmd/compile/internal/types2/instantiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions src/go/types/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/go/types/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 0 additions & 9 deletions src/go/types/instantiate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/internal/types/testdata/check/issues1.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions src/internal/types/testdata/fixedbugs/issue50646.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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" */]
Expand Down
8 changes: 3 additions & 5 deletions src/internal/types/testdata/fixedbugs/issue51257.go
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 }
Expand All @@ -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},
})
Expand Down
28 changes: 0 additions & 28 deletions src/internal/types/testdata/spec/oldcomparable.go

This file was deleted.

0 comments on commit 1e65e04

Please sign in to comment.