If we see the exact same types2.Type a second time, we can map it to
the same *types.Type instance. Not strictly necessary, but reduces
memory usage and plays better with the rest of the compiler given the
current state of things.
Change-Id: I53686d072c7c7834b0c97417bc8d5f2cd24572b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/284692
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
info: &info,
posMap: m,
objs: make(map[types2.Object]*ir.Name),
+ typs: make(map[types2.Type]*types.Type),
}
g.generate(noders)
posMap
objs map[types2.Object]*ir.Name
+ typs map[types2.Type]*types.Type
marker dwarfgen.ScopeMarker
}
}
func (g *irgen) typ(typ types2.Type) *types.Type {
+ // Caching type mappings isn't strictly needed, because typ0 preserves
+ // type identity; but caching minimizes memory blow-up from mapping the
+ // same composite type multiple times, and also plays better with the
+ // current state of cmd/compile (e.g., haphazard calculation of type
+ // sizes).
+ res, ok := g.typs[typ]
+ if !ok {
+ res = g.typ0(typ)
+ g.typs[typ] = res
+ }
+ return res
+}
+
+func (g *irgen) typ0(typ types2.Type) *types.Type {
switch typ := typ.(type) {
case *types2.Basic:
return g.basic(typ)