]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: improve findTypeLoop
authorMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2020 04:34:25 +0000 (20:34 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 1 Dec 2020 05:14:26 +0000 (05:14 +0000)
When checking if a defined type is part of a type loop, we can
short-circuit if it was defined in another package. We can assume any
package we import already successfully compiled, so any types it
contains cannot be part of a type loop.

This also allows us to simplify the logic for recursing into the type
used in the type declaration, because any defined type from this
package will have a properly setup node.

Change-Id: Ic024814d95533afd9e59f2103c8ddb22bd87e900
Reviewed-on: https://go-review.googlesource.com/c/go/+/274294
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/gc/align.go

index 4f8f04d73d004262e416cacfe5407aecc2da6e27..ffae8dc27b6f336815fccd1ba7d95bc384cbf303 100644 (file)
@@ -190,6 +190,13 @@ func findTypeLoop(t *types.Type, path *[]*types.Type) bool {
                // recurse on the type expression used in the type
                // declaration.
 
+               // Type imported from package, so it can't be part of
+               // a type loop (otherwise that package should have
+               // failed to compile).
+               if t.Sym.Pkg != ir.LocalPkg {
+                       return false
+               }
+
                for i, x := range *path {
                        if x == t {
                                *path = (*path)[i:]
@@ -198,10 +205,8 @@ func findTypeLoop(t *types.Type, path *[]*types.Type) bool {
                }
 
                *path = append(*path, t)
-               if n := ir.AsNode(t.Nod); n != nil {
-                       if name := n.Name(); name != nil && name.Ntype != nil && findTypeLoop(name.Ntype.Type(), path) {
-                               return true
-                       }
+               if findTypeLoop(ir.AsNode(t.Nod).Name().Ntype.Type(), path) {
+                       return true
                }
                *path = (*path)[:len(*path)-1]
        } else {