]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove interfacecycles debug flag
authorRobert Griesemer <gri@golang.org>
Tue, 19 Dec 2023 02:13:30 +0000 (18:13 -0800)
committerGopher Robot <gobot@golang.org>
Tue, 19 Dec 2023 04:39:56 +0000 (04:39 +0000)
Per the discussion on the issue, since no problems related to this
appeared since Go 1.20, remove the ability to disable the check for
anonymous interface cycles permanently.

Adjust various tests accordingly.

For #56103.

Change-Id: Ica2b28752dca08934bbbc163a9b062ae1eb2a834
Reviewed-on: https://go-review.googlesource.com/c/go/+/550896
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/base/debug.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/types2/stdlib_test.go
src/go/types/stdlib_test.go
test/fixedbugs/bug398.go
test/fixedbugs/issue16369.go

index a85f0139fc3b48f254641eaf7aa87b4beaf31f01..aadd950a0a0ad6a1752c635441d7eb2793846779 100644 (file)
@@ -36,7 +36,6 @@ type DebugFlags struct {
        Gossahash             string `help:"hash value for use in debugging the compiler"`
        InlFuncsWithClosures  int    `help:"allow functions with closures to be inlined" concurrent:"ok"`
        InlStaticInit         int    `help:"allow static initialization of inlined calls" concurrent:"ok"`
-       InterfaceCycles       int    `help:"allow anonymous interface cycles"`
        Libfuzzer             int    `help:"enable coverage instrumentation for libfuzzer"`
        LoopVar               int    `help:"shared (0, default), 1 (private loop variables), 2, private + log"`
        LoopVarHash           string `help:"for debugging changes in loop behavior. Overrides experiment and loopvar flag."`
index 46511d1f9736ed737223d5223b7e51b2a53156de..d909f3467bf08d57b1e030cdb28d073243d591bc 100644 (file)
@@ -92,23 +92,22 @@ func checkFiles(m posMap, noders []*noder) (*types2.Package, *types2.Info) {
        }
 
        // Check for anonymous interface cycles (#56103).
-       if base.Debug.InterfaceCycles == 0 {
-               var f cycleFinder
-               for _, file := range files {
-                       syntax.Inspect(file, func(n syntax.Node) bool {
-                               if n, ok := n.(*syntax.InterfaceType); ok {
-                                       if f.hasCycle(n.GetTypeInfo().Type.(*types2.Interface)) {
-                                               base.ErrorfAt(m.makeXPos(n.Pos()), errors.InvalidTypeCycle, "invalid recursive type: anonymous interface refers to itself (see https://go.dev/issue/56103)")
-
-                                               for typ := range f.cyclic {
-                                                       f.cyclic[typ] = false // suppress duplicate errors
-                                               }
+       // TODO(gri) move this code into the type checkers (types2 and go/types)
+       var f cycleFinder
+       for _, file := range files {
+               syntax.Inspect(file, func(n syntax.Node) bool {
+                       if n, ok := n.(*syntax.InterfaceType); ok {
+                               if f.hasCycle(n.GetTypeInfo().Type.(*types2.Interface)) {
+                                       base.ErrorfAt(m.makeXPos(n.Pos()), errors.InvalidTypeCycle, "invalid recursive type: anonymous interface refers to itself (see https://go.dev/issue/56103)")
+
+                                       for typ := range f.cyclic {
+                                               f.cyclic[typ] = false // suppress duplicate errors
                                        }
-                                       return false
                                }
-                               return true
-                       })
-               }
+                               return false
+                       }
+                       return true
+               })
        }
        base.ExitIfErrors()
 
index 7c14e3476e7baffc157c1c491daddabaef78b634..405af78572bbab0fcbac47de6927e49c0801131a 100644 (file)
@@ -311,6 +311,7 @@ func TestStdFixed(t *testing.T) {
 
        testTestDir(t, filepath.Join(testenv.GOROOT(t), "test", "fixedbugs"),
                "bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
+               "bug398.go",      // types2 doesn't check for anonymous interface cycles (go.dev/issue/56103)
                "issue6889.go",   // gc-specific test
                "issue11362.go",  // canonical import path check
                "issue16369.go",  // types2 handles this correctly - not an issue
index f90f9388c2809fedefba8f881260216a2728e3bf..a89cd858db5be970475d94b80123dfa4ec0629fb 100644 (file)
@@ -312,6 +312,7 @@ func TestStdFixed(t *testing.T) {
 
        testTestDir(t, filepath.Join(testenv.GOROOT(t), "test", "fixedbugs"),
                "bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
+               "bug398.go",      // go/types doesn't check for anonymous interface cycles (go.dev/issue/56103)
                "issue6889.go",   // gc-specific test
                "issue11362.go",  // canonical import path check
                "issue16369.go",  // go/types handles this correctly - not an issue
index db3e43c7f965e9cab198561044c78182de6ce5dd..2b00f6074d4c39099582c5fdc85f9a609a1a51a2 100644 (file)
@@ -1,4 +1,4 @@
-// compile -d=interfacecycles
+// errorcheck
 
 // Copyright 2012 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -11,11 +11,11 @@ package p
 
 // exported interfaces
 
-type I1 interface {
+type I1 interface { // ERROR "invalid recursive type: anonymous interface refers to itself"
       F() interface{I1}
 }
 
-type I2 interface {
+type I2 interface { // ERROR "invalid recursive type: anonymous interface refers to itself"
       F() interface{I2}
 }
 
@@ -28,11 +28,11 @@ func F() bool {
 
 // non-exported interfaces
 
-type i1 interface {
+type i1 interface { // ERROR "invalid recursive type: anonymous interface refers to itself"
       F() interface{i1}
 }
 
-type i2 interface {
+type i2 interface { // ERROR "invalid recursive type: anonymous interface refers to itself"
       F() interface{i2}
 }
 
index 3a7bb7eaed6fba61abcce0193d60e4b1ce6e9a69..86d0ce645d2115c96eff74d96503cba6eca87c9f 100644 (file)
@@ -1,4 +1,4 @@
-// compile -d=interfacecycles
+// errorcheck
 
 // Copyright 2016 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
@@ -6,7 +6,7 @@
 
 package p
 
-type T interface {
+type T interface { // ERROR "invalid recursive type: anonymous interface refers to itself"
        M(interface {
                T
        })