mirror of
https://github.com/golang/go
synced 2024-11-26 05:37:57 -07:00
[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 <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>
This commit is contained in:
parent
45f3b646d4
commit
dadfc80bc1
@ -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,11 +205,9 @@ 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) {
|
||||
if findTypeLoop(ir.AsNode(t.Nod).Name().Ntype.Type(), path) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
*path = (*path)[:len(*path)-1]
|
||||
} else {
|
||||
// Anonymous type. Recurse on contained types.
|
||||
|
Loading…
Reference in New Issue
Block a user