From 63661b7251f1e42c6ccc673fa6530c62e2fbd7ac Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 24 Jul 2019 17:02:05 -0700 Subject: [PATCH] cmd/compile: refactor checkdupfields API 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 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/align.go | 2 +- src/cmd/compile/internal/gc/dcl.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/align.go b/src/cmd/compile/internal/gc/align.go index 17c549d252..b45fd47253 100644 --- a/src/cmd/compile/internal/gc/align.go +++ b/src/cmd/compile/internal/gc/align.go @@ -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) } diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index 12875e798e..012f993d69 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -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) -- 2.50.0