From 62947bedd28a884b46f5df71070a9e86dad17081 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 18 Mar 2017 14:39:48 -0700 Subject: [PATCH] cmd/compile: canonicalize empty interface types 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 TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/bimport.go | 8 ++++++-- src/cmd/compile/internal/gc/dcl.go | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/bimport.go b/src/cmd/compile/internal/gc/bimport.go index d6a25515df..d7d48cb07e 100644 --- a/src/cmd/compile/internal/gc/bimport.go +++ b/src/cmd/compile/internal/gc/bimport.go @@ -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: diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index 94d18e2256..a1d6e4f0c7 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -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