aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types/type.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-04-08 13:02:21 -0700
committerDan Scales <danscales@google.com>2021-04-09 12:56:04 +0000
commit519f223aa2b55372b473d1a883435b64b9f77365 (patch)
tree82912e7f2fa02739f93e003bda8a01b3c2cefdd6 /src/cmd/compile/internal/types/type.go
parent4d7d7a4c50ea0d16879458a032f1a05db2c7ae4f (diff)
downloadgo-519f223aa2b55372b473d1a883435b64b9f77365.tar.gz
go-519f223aa2b55372b473d1a883435b64b9f77365.zip
cmd/compile: reduce overhead of RParams in types.Type
Changed RParams in types.Type to be a pointer to a slice, rather than a slice itself, in order to reduce it from three words to one words, since the large majority of types will not be generic or instantiated from a generic type. Additional cleanup: remove operation OTYPEINST, which we don't have need of, since all type instantiations are either handled by types2 or happen automatically during some form of stenciling. Both of these are useful cleanups before the Go 1.17 freeze. Change-Id: I61ad56b3c698b30d2cb5a2cdd12263202c54f49c Reviewed-on: https://go-review.googlesource.com/c/go/+/308770 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Dan Scales <danscales@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types/type.go')
-rw-r--r--src/cmd/compile/internal/types/type.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 969195b850..88fc409733 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -178,16 +178,13 @@ type Type struct {
flags bitset8
- // For defined (named) generic types, the list of type params (in order)
- // of this type that need to be instantiated. For fully-instantiated
- // generic types, this is the targs used to instantiate them (which are
- // used when generating the corresponding instantiated methods). rparams
- // is only set for named types that are generic or are fully-instantiated
- // from a generic type.
-
- // TODO(danscales): for space reasons, should probably be a pointer to a
- // slice, possibly change the name of this field.
- rparams []*Type
+ // For defined (named) generic types, a pointer to the list of type params
+ // (in order) of this type that need to be instantiated. For
+ // fully-instantiated generic types, this is the targs used to instantiate
+ // them (which are used when generating the corresponding instantiated
+ // methods). rparams is only set for named types that are generic or are
+ // fully-instantiated from a generic type, and is otherwise set to nil.
+ rparams *[]*Type
}
func (*Type) CanBeAnSSAAux() {}
@@ -244,11 +241,17 @@ func (t *Type) Pos() src.XPos {
}
func (t *Type) RParams() []*Type {
- return t.rparams
+ if t.rparams == nil {
+ return nil
+ }
+ return *t.rparams
}
func (t *Type) SetRParams(rparams []*Type) {
- t.rparams = rparams
+ if len(rparams) == 0 {
+ base.Fatalf("Setting nil or zero-length rparams")
+ }
+ t.rparams = &rparams
if t.HasTParam() {
return
}