]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: reduce overhead of RParams in types.Type
authorDan Scales <danscales@google.com>
Thu, 8 Apr 2021 20:02:21 +0000 (13:02 -0700)
committerDan Scales <danscales@google.com>
Fri, 9 Apr 2021 12:56:04 +0000 (12:56 +0000)
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>

src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/ir/op_string.go
src/cmd/compile/internal/types/sizeof_test.go
src/cmd/compile/internal/types/type.go

index 7bce0e985c7b3a33d1c1547dd647f0fdaa28b632..b6be74296ff53fb761beb37b36b896f8e0a5b93a 100644 (file)
@@ -285,7 +285,6 @@ const (
        //   Left is nil if there is no type-switch variable
        OTYPESW
        OFUNCINST // instantiation of a generic function
-       OTYPEINST // instantiation of a generic type
 
        // types
        OTCHAN   // chan int
index 65456df356dd3d523f3a815b53068d49fdc92596..cfd36c7b3df543a029c480db257ef1fc35bb3052 100644 (file)
@@ -138,35 +138,34 @@ func _() {
        _ = x[OSWITCH-127]
        _ = x[OTYPESW-128]
        _ = x[OFUNCINST-129]
-       _ = x[OTYPEINST-130]
-       _ = x[OTCHAN-131]
-       _ = x[OTMAP-132]
-       _ = x[OTSTRUCT-133]
-       _ = x[OTINTER-134]
-       _ = x[OTFUNC-135]
-       _ = x[OTARRAY-136]
-       _ = x[OTSLICE-137]
-       _ = x[OINLCALL-138]
-       _ = x[OEFACE-139]
-       _ = x[OITAB-140]
-       _ = x[OIDATA-141]
-       _ = x[OSPTR-142]
-       _ = x[OCFUNC-143]
-       _ = x[OCHECKNIL-144]
-       _ = x[OVARDEF-145]
-       _ = x[OVARKILL-146]
-       _ = x[OVARLIVE-147]
-       _ = x[ORESULT-148]
-       _ = x[OINLMARK-149]
-       _ = x[OLINKSYMOFFSET-150]
-       _ = x[OTAILCALL-151]
-       _ = x[OGETG-152]
-       _ = x[OEND-153]
+       _ = x[OTCHAN-130]
+       _ = x[OTMAP-131]
+       _ = x[OTSTRUCT-132]
+       _ = x[OTINTER-133]
+       _ = x[OTFUNC-134]
+       _ = x[OTARRAY-135]
+       _ = x[OTSLICE-136]
+       _ = x[OINLCALL-137]
+       _ = x[OEFACE-138]
+       _ = x[OITAB-139]
+       _ = x[OIDATA-140]
+       _ = x[OSPTR-141]
+       _ = x[OCFUNC-142]
+       _ = x[OCHECKNIL-143]
+       _ = x[OVARDEF-144]
+       _ = x[OVARKILL-145]
+       _ = x[OVARLIVE-146]
+       _ = x[ORESULT-147]
+       _ = x[OINLMARK-148]
+       _ = x[OLINKSYMOFFSET-149]
+       _ = x[OTAILCALL-150]
+       _ = x[OGETG-151]
+       _ = x[OEND-152]
 }
 
-const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWFUNCINSTTYPEINSTTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETTAILCALLGETGEND"
+const _Op_name = "XXXNAMENONAMETYPEPACKLITERALNILADDSUBORXORADDSTRADDRANDANDAPPENDBYTES2STRBYTES2STRTMPRUNES2STRSTR2BYTESSTR2BYTESTMPSTR2RUNESASAS2AS2DOTTYPEAS2FUNCAS2MAPRAS2RECVASOPCALLCALLFUNCCALLMETHCALLINTERCALLPARTCAPCLOSECLOSURECOMPLITMAPLITSTRUCTLITARRAYLITSLICELITPTRLITCONVCONVIFACECONVNOPCOPYDCLDCLFUNCDCLCONSTDCLTYPEDELETEDOTDOTPTRDOTMETHDOTINTERXDOTDOTTYPEDOTTYPE2EQNELTLEGEGTDEREFINDEXINDEXMAPKEYSTRUCTKEYLENMAKEMAKECHANMAKEMAPMAKESLICEMAKESLICECOPYMULDIVMODLSHRSHANDANDNOTNEWNOTBITNOTPLUSNEGORORPANICPRINTPRINTNPARENSENDSLICESLICEARRSLICESTRSLICE3SLICE3ARRSLICEHEADERRECOVERRECVRUNESTRSELRECV2IOTAREALIMAGCOMPLEXALIGNOFOFFSETOFSIZEOFMETHEXPRSTMTEXPRBLOCKBREAKCASECONTINUEDEFERFALLFORFORUNTILGOTOIFLABELGORANGERETURNSELECTSWITCHTYPESWFUNCINSTTCHANTMAPTSTRUCTTINTERTFUNCTARRAYTSLICEINLCALLEFACEITABIDATASPTRCFUNCCHECKNILVARDEFVARKILLVARLIVERESULTINLMARKLINKSYMOFFSETTAILCALLGETGEND"
 
-var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 474, 480, 484, 487, 491, 496, 501, 507, 512, 516, 521, 529, 537, 543, 552, 563, 570, 574, 581, 589, 593, 597, 601, 608, 615, 623, 629, 637, 645, 650, 655, 659, 667, 672, 676, 679, 687, 691, 693, 698, 700, 705, 711, 717, 723, 729, 737, 745, 750, 754, 761, 767, 772, 778, 784, 791, 796, 800, 805, 809, 814, 822, 828, 835, 842, 848, 855, 868, 876, 880, 883}
+var _Op_index = [...]uint16{0, 3, 7, 13, 17, 21, 28, 31, 34, 37, 39, 42, 48, 52, 58, 64, 73, 85, 94, 103, 115, 124, 126, 129, 139, 146, 153, 160, 164, 168, 176, 184, 193, 201, 204, 209, 216, 223, 229, 238, 246, 254, 260, 264, 273, 280, 284, 287, 294, 302, 309, 315, 318, 324, 331, 339, 343, 350, 358, 360, 362, 364, 366, 368, 370, 375, 380, 388, 391, 400, 403, 407, 415, 422, 431, 444, 447, 450, 453, 456, 459, 462, 468, 471, 474, 480, 484, 487, 491, 496, 501, 507, 512, 516, 521, 529, 537, 543, 552, 563, 570, 574, 581, 589, 593, 597, 601, 608, 615, 623, 629, 637, 645, 650, 655, 659, 667, 672, 676, 679, 687, 691, 693, 698, 700, 705, 711, 717, 723, 729, 737, 742, 746, 753, 759, 764, 770, 776, 783, 788, 792, 797, 801, 806, 814, 820, 827, 834, 840, 847, 860, 868, 872, 875}
 
 func (i Op) String() string {
        if i >= Op(len(_Op_index)-1) {
index 4c3ef693467091a7369ca5413998aac2fa164d72..702893874214874080dfa1a148048303279050d9 100644 (file)
@@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
                _64bit uintptr     // size on 64bit platforms
        }{
                {Sym{}, 44, 72},
-               {Type{}, 68, 120},
+               {Type{}, 60, 104},
                {Map{}, 20, 40},
                {Forward{}, 20, 32},
                {Func{}, 28, 48},
index 969195b850d96a3a8335d071147638ce6da24047..88fc4097336500b6c66bd7f119ae7005b08227e2 100644 (file)
@@ -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
        }