mirror of
https://github.com/golang/go
synced 2024-11-23 13:40:04 -07:00
[dev.typeparams] cmd/compile: cache mapped types during irgen
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>
This commit is contained in:
parent
3c0a39c964
commit
90bfc73071
@ -79,6 +79,7 @@ func check2(noders []*noder) {
|
||||
info: &info,
|
||||
posMap: m,
|
||||
objs: make(map[types2.Object]*ir.Name),
|
||||
typs: make(map[types2.Type]*types.Type),
|
||||
}
|
||||
g.generate(noders)
|
||||
|
||||
@ -94,6 +95,7 @@ type irgen struct {
|
||||
|
||||
posMap
|
||||
objs map[types2.Object]*ir.Name
|
||||
typs map[types2.Type]*types.Type
|
||||
marker dwarfgen.ScopeMarker
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,20 @@ func (g *irgen) pkg(pkg *types2.Package) *types.Pkg {
|
||||
}
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user