diff options
author | Dan Scales <danscales@google.com> | 2021-04-02 16:52:58 -0700 |
---|---|---|
committer | Dan Scales <danscales@google.com> | 2021-04-05 15:30:15 +0000 |
commit | a4b8241d97fb180e1b9cb41c4828345c931d1aaf (patch) | |
tree | c38279cd1a5493824af9384b7cd8765cea58a63b /src/cmd/compile/internal/typecheck | |
parent | 6ed045b365731e59fcae48de48f1aea7a6304eb3 (diff) | |
download | go-a4b8241d97fb180e1b9cb41c4828345c931d1aaf.tar.gz go-a4b8241d97fb180e1b9cb41c4828345c931d1aaf.zip |
cmd/compile: get rid of Fields in types.Interface, use allMethods in types.Type instead
Confusingly, the set of all methods of an interface is currently set in
Fields field of types.Interface. This is true, even though there is
already an allMethods field (and AllMethods method) of types.Type.
Change so the set of all methods of an interface are stored in
Type.allMethods, and Interface.Fields is removed. Update the comments
for Methods and AllMethods.
Change-Id: Ibc32bafae86831cba62606b079a855690612c759
Reviewed-on: https://go-review.googlesource.com/c/go/+/307209
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck')
-rw-r--r-- | src/cmd/compile/internal/typecheck/subr.go | 34 | ||||
-rw-r--r-- | src/cmd/compile/internal/typecheck/typecheck.go | 6 |
2 files changed, 30 insertions, 10 deletions
diff --git a/src/cmd/compile/internal/typecheck/subr.go b/src/cmd/compile/internal/typecheck/subr.go index daf5cd72a2..76c565ebee 100644 --- a/src/cmd/compile/internal/typecheck/subr.go +++ b/src/cmd/compile/internal/typecheck/subr.go @@ -221,7 +221,7 @@ func CalcMethods(t *types.Type) { ms = append(ms, t.Methods().Slice()...) sort.Sort(types.MethodsByName(ms)) - t.AllMethods().Set(ms) + t.SetAllMethods(ms) } // adddot1 returns the number of fields or methods named s at depth d in Type t. @@ -257,7 +257,13 @@ func adddot1(s *types.Sym, t *types.Type, d int, save **types.Field, ignorecase return c, false } - for _, f := range u.Fields().Slice() { + var fields *types.Fields + if u.IsStruct() { + fields = u.Fields() + } else { + fields = u.AllMethods() + } + for _, f := range fields.Slice() { if f.Embedded == 0 || f.Sym == nil { continue } @@ -619,7 +625,7 @@ func expand0(t *types.Type) { } if u.IsInterface() { - for _, f := range u.Fields().Slice() { + for _, f := range u.AllMethods().Slice() { if f.Sym.Uniq() { continue } @@ -658,7 +664,13 @@ func expand1(t *types.Type, top bool) { } if u.IsStruct() || u.IsInterface() { - for _, f := range u.Fields().Slice() { + var fields *types.Fields + if u.IsStruct() { + fields = u.Fields() + } else { + fields = u.AllMethods() + } + for _, f := range fields.Slice() { if f.Embedded == 0 { continue } @@ -708,8 +720,8 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool if t.IsInterface() { i := 0 - tms := t.Fields().Slice() - for _, im := range iface.Fields().Slice() { + tms := t.AllMethods().Slice() + for _, im := range iface.AllMethods().Slice() { for i < len(tms) && tms[i].Sym != im.Sym { i++ } @@ -738,7 +750,7 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool tms = t.AllMethods().Slice() } i := 0 - for _, im := range iface.Fields().Slice() { + for _, im := range iface.AllMethods().Slice() { if im.Broke() { continue } @@ -806,7 +818,13 @@ func lookdot0(s *types.Sym, t *types.Type, save **types.Field, ignorecase bool) c := 0 if u.IsStruct() || u.IsInterface() { - for _, f := range u.Fields().Slice() { + var fields *types.Fields + if u.IsStruct() { + fields = u.Fields() + } else { + fields = u.AllMethods() + } + for _, f := range fields.Slice() { if f.Sym == s || (ignorecase && f.IsMethod() && strings.EqualFold(f.Sym.Name, s.Name)) { if save != nil { *save = f diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 54f7cd9efa..ab493e0caa 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -1103,7 +1103,7 @@ func typecheckMethodExpr(n *ir.SelectorExpr) (res ir.Node) { // Compute the method set for t. var ms *types.Fields if t.IsInterface() { - ms = t.Fields() + ms = t.AllMethods() } else { mt := types.ReceiverBaseType(t) if mt == nil { @@ -1170,8 +1170,10 @@ func Lookdot(n *ir.SelectorExpr, t *types.Type, dostrcmp int) *types.Field { types.CalcSize(t) var f1 *types.Field - if t.IsStruct() || t.IsInterface() { + if t.IsStruct() { f1 = Lookdot1(n, s, t, t.Fields(), dostrcmp) + } else if t.IsInterface() { + f1 = Lookdot1(n, s, t, t.AllMethods(), dostrcmp) } var f2 *types.Field |