]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: canonicalize empty interface types
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 18 Mar 2017 21:39:48 +0000 (14:39 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 19 Mar 2017 05:02:07 +0000 (05:02 +0000)
Mapping all empty interfaces onto the same Type
allows better reuse of the ptrTo and sliceOf
Type caches for *interface{} and []interface{}.

This has little compiler performance impact now,
but it will be helpful in the future,
when we will eagerly populate some of those caches.

Passes toolstash-check.

Change-Id: I17daee599a129b0b2f5f3025c1be43d569d6782c
Reviewed-on: https://go-review.googlesource.com/38344
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/dcl.go

index d6a25515dff30dc4e261e66ccfcc7cafba3ea522..d7d48cb07e01b3b55ae424beefa0b90faf0d8a16 100644 (file)
@@ -526,11 +526,15 @@ func (p *importer) typ() *Type {
                functypefield0(t, nil, params, result)
 
        case interfaceTag:
-               t = p.newtyp(TINTER)
                if p.int() != 0 {
                        formatErrorf("unexpected embedded interface")
                }
-               t.SetFields(p.methodList())
+               if ml := p.methodList(); len(ml) == 0 {
+                       t = Types[TINTER]
+               } else {
+                       t = p.newtyp(TINTER)
+                       t.SetFields(ml)
+               }
                checkwidth(t)
 
        case mapTag:
index 94d18e2256ac29c5794508e413d30eaff7e959cb..a1d6e4f0c7d61a13e80e1e13e6cab53d10f4631f 100644 (file)
@@ -860,6 +860,9 @@ func interfacefield(n *Node) *Field {
 }
 
 func tointerface(l []*Node) *Type {
+       if len(l) == 0 {
+               return Types[TINTER]
+       }
        t := typ(TINTER)
        tointerface0(t, l)
        return t