]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: refactor checkdupfields API
authorMatthew Dempsky <mdempsky@google.com>
Thu, 25 Jul 2019 00:02:05 +0000 (17:02 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 26 Aug 2019 19:38:51 +0000 (19:38 +0000)
Allows avoiding the Type.Fields call, which affects prevents
checkdupfields from being called at the more natural point during
dowidth.

Change-Id: I724789c860e7fffba1e8e876e2d74dcfba85d75c
Reviewed-on: https://go-review.googlesource.com/c/go/+/187517
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

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

index 17c549d2528d5e03ccd05876c165c7df33293938..b45fd472531948130ec7bb7287e176b993058db0 100644 (file)
@@ -385,7 +385,7 @@ func dowidth(t *types.Type) {
                // We defer calling these functions until after
                // setting t.Width and t.Align so the recursive calls
                // to dowidth within t.Fields() will succeed.
-               checkdupfields("method", t)
+               checkdupfields("method", t.FieldSlice())
                offmod(t)
        }
 
index 12875e798eb9b4ce6e5dd51b32f529870fc85edc..012f993d69d8d58c4c8c758cf9ec71257d423316 100644 (file)
@@ -576,10 +576,10 @@ func structfield(n *Node) *types.Field {
 
 // checkdupfields emits errors for duplicately named fields or methods in
 // a list of struct or interface types.
-func checkdupfields(what string, ts ...*types.Type) {
+func checkdupfields(what string, fss ...[]*types.Field) {
        seen := make(map[*types.Sym]bool)
-       for _, t := range ts {
-               for _, f := range t.Fields().Slice() {
+       for _, fs := range fss {
+               for _, f := range fs {
                        if f.Sym == nil || f.Sym.IsBlank() {
                                continue
                        }
@@ -615,7 +615,7 @@ func tostruct0(t *types.Type, l []*Node) {
        }
        t.SetFields(fields)
 
-       checkdupfields("field", t)
+       checkdupfields("field", t.FieldSlice())
 
        if !t.Broke() {
                checkwidth(t)
@@ -747,7 +747,7 @@ func functype0(t *types.Type, this *Node, in, out []*Node) {
        t.FuncType().Params = tofunargs(in, types.FunargParams)
        t.FuncType().Results = tofunargs(out, types.FunargResults)
 
-       checkdupfields("argument", t.Recvs(), t.Params(), t.Results())
+       checkdupfields("argument", t.Recvs().FieldSlice(), t.Params().FieldSlice(), t.Results().FieldSlice())
 
        if t.Recvs().Broke() || t.Results().Broke() || t.Params().Broke() {
                t.SetBroke(true)