Commit 62947bed authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent 872db799
...@@ -526,11 +526,15 @@ func (p *importer) typ() *Type { ...@@ -526,11 +526,15 @@ func (p *importer) typ() *Type {
functypefield0(t, nil, params, result) functypefield0(t, nil, params, result)
case interfaceTag: case interfaceTag:
t = p.newtyp(TINTER)
if p.int() != 0 { if p.int() != 0 {
formatErrorf("unexpected embedded interface") 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) checkwidth(t)
case mapTag: case mapTag:
......
...@@ -860,6 +860,9 @@ func interfacefield(n *Node) *Field { ...@@ -860,6 +860,9 @@ func interfacefield(n *Node) *Field {
} }
func tointerface(l []*Node) *Type { func tointerface(l []*Node) *Type {
if len(l) == 0 {
return Types[TINTER]
}
t := typ(TINTER) t := typ(TINTER)
tointerface0(t, l) tointerface0(t, l)
return t return t
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment