From dadfc80bc173ce4475bc76231de5259d797b0522 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 30 Nov 2020 20:34:25 -0800 Subject: [PATCH] [dev.regabi] cmd/compile: improve findTypeLoop 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 Run-TryBot: Matthew Dempsky Reviewed-by: Cuong Manh Le TryBot-Result: Go Bot --- src/cmd/compile/internal/gc/align.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/gc/align.go b/src/cmd/compile/internal/gc/align.go index 4f8f04d73d0..ffae8dc27b6 100644 --- a/src/cmd/compile/internal/gc/align.go +++ b/src/cmd/compile/internal/gc/align.go @@ -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 {