]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove types.Type rparams field
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 5 Sep 2024 16:09:08 +0000 (23:09 +0700)
committerGopher Robot <gobot@golang.org>
Wed, 11 Sep 2024 16:48:39 +0000 (16:48 +0000)
This field is present during the initial development of generic support
inside compiler, and indicating whether a type is fully instantiated is
the solely purpose at this moment. Further, its name is also confused,
and there have been a TODO to chose a better name for it.

Instead, just using a bit to track whether a type is fully instantiated,
then this rparams field can be removed to simplify the code.

Change-Id: Ia29c6dd5792487c440b83b0f3b77bd60917c2019
Reviewed-on: https://go-review.googlesource.com/c/go/+/611255
Reviewed-by: Tim King <taking@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/noder/reader.go
src/cmd/compile/internal/types/sizeof_test.go
src/cmd/compile/internal/types/type.go

index ce4cc1cc4e474f3ef02e8b0b79b298a2ac8d2449..55fbf860dfd00fbb327ca16e900e76bc81e561d4 100644 (file)
@@ -1190,13 +1190,16 @@ func (r *reader) typeExt(name *ir.Name) {
        typ := name.Type()
 
        if r.hasTypeParams() {
-               // Set "RParams" (really type arguments here, not parameters) so
-               // this type is treated as "fully instantiated". This ensures the
-               // type descriptor is written out as DUPOK and method wrappers are
-               // generated even for imported types.
-               var targs []*types.Type
-               targs = append(targs, r.dict.targs...)
-               typ.SetRParams(targs)
+               // Mark type as fully instantiated to ensure the type descriptor is written
+               // out as DUPOK and method wrappers are generated even for imported types.
+               typ.SetIsFullyInstantiated(true)
+               // HasShape should be set if any type argument is or has a shape type.
+               for _, targ := range r.dict.targs {
+                       if targ.HasShape() {
+                               typ.SetHasShape(true)
+                               break
+                       }
+               }
        }
 
        name.SetPragma(r.pragmaFlag())
index 27845fbd2dac78eeb84f608fbae9aabe11d69772..3b2aeece3ed99e47c9492a0fe1fa75489c9d2061 100644 (file)
@@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
                _64bit uintptr     // size on 64bit platforms
        }{
                {Sym{}, 32, 64},
-               {Type{}, 64, 104},
+               {Type{}, 60, 96},
                {Map{}, 16, 32},
                {Forward{}, 20, 32},
                {Func{}, 32, 56},
index d8950ba89465a874b00a8c8b854aa6c207e5ad21..9bb3a70b3ed006bd5dffccb09cb1976402200595 100644 (file)
@@ -208,16 +208,6 @@ type Type struct {
        // Note that for pointers, this is always PtrSize even if the element type
        // is NotInHeap. See size.go:PtrDataSize for details.
        ptrBytes int64
-
-       // For defined (named) generic types, a pointer to the list of type params
-       // (in order) of this type that need to be instantiated. For instantiated
-       // generic types, this is the targs used to instantiate them. These targs
-       // may be typeparams (for re-instantiated types such as Value[T2]) or
-       // concrete types (for fully instantiated types such as Value[int]).
-       // rparams is only set for named types that are generic or are fully
-       // instantiated from a generic type, and is otherwise set to nil.
-       // TODO(danscales): choose a better name.
-       rparams *[]*Type
 }
 
 // Registers returns the number of integer and floating-point
@@ -240,19 +230,24 @@ const (
        typeRecur
        typeIsShape  // represents a set of closely related types, for generics
        typeHasShape // there is a shape somewhere in the type
+       // typeIsFullyInstantiated reports whether a type is fully instantiated generic type; i.e.
+       // an instantiated generic type where all type arguments are non-generic or fully instantiated generic types.
+       typeIsFullyInstantiated
 )
 
-func (t *Type) NotInHeap() bool  { return t.flags&typeNotInHeap != 0 }
-func (t *Type) Noalg() bool      { return t.flags&typeNoalg != 0 }
-func (t *Type) Deferwidth() bool { return t.flags&typeDeferwidth != 0 }
-func (t *Type) Recur() bool      { return t.flags&typeRecur != 0 }
-func (t *Type) IsShape() bool    { return t.flags&typeIsShape != 0 }
-func (t *Type) HasShape() bool   { return t.flags&typeHasShape != 0 }
+func (t *Type) NotInHeap() bool           { return t.flags&typeNotInHeap != 0 }
+func (t *Type) Noalg() bool               { return t.flags&typeNoalg != 0 }
+func (t *Type) Deferwidth() bool          { return t.flags&typeDeferwidth != 0 }
+func (t *Type) Recur() bool               { return t.flags&typeRecur != 0 }
+func (t *Type) IsShape() bool             { return t.flags&typeIsShape != 0 }
+func (t *Type) HasShape() bool            { return t.flags&typeHasShape != 0 }
+func (t *Type) IsFullyInstantiated() bool { return t.flags&typeIsFullyInstantiated != 0 }
 
-func (t *Type) SetNotInHeap(b bool)  { t.flags.set(typeNotInHeap, b) }
-func (t *Type) SetNoalg(b bool)      { t.flags.set(typeNoalg, b) }
-func (t *Type) SetDeferwidth(b bool) { t.flags.set(typeDeferwidth, b) }
-func (t *Type) SetRecur(b bool)      { t.flags.set(typeRecur, b) }
+func (t *Type) SetNotInHeap(b bool)           { t.flags.set(typeNotInHeap, b) }
+func (t *Type) SetNoalg(b bool)               { t.flags.set(typeNoalg, b) }
+func (t *Type) SetDeferwidth(b bool)          { t.flags.set(typeDeferwidth, b) }
+func (t *Type) SetRecur(b bool)               { t.flags.set(typeRecur, b) }
+func (t *Type) SetIsFullyInstantiated(b bool) { t.flags.set(typeIsFullyInstantiated, b) }
 
 // Should always do SetHasShape(true) when doing SetIsShape(true).
 func (t *Type) SetIsShape(b bool)  { t.flags.set(typeIsShape, b) }
@@ -281,34 +276,6 @@ func (t *Type) Pos() src.XPos {
        return src.NoXPos
 }
 
-func (t *Type) RParams() []*Type {
-       if t.rparams == nil {
-               return nil
-       }
-       return *t.rparams
-}
-
-func (t *Type) SetRParams(rparams []*Type) {
-       if len(rparams) == 0 {
-               base.Fatalf("Setting nil or zero-length rparams")
-       }
-       t.rparams = &rparams
-       // HasShape should be set if any type argument is or has a shape type.
-       for _, rparam := range rparams {
-               if rparam.HasShape() {
-                       t.SetHasShape(true)
-                       break
-               }
-       }
-}
-
-// IsFullyInstantiated reports whether t is a fully instantiated generic type; i.e. an
-// instantiated generic type where all type arguments are non-generic or fully
-// instantiated generic types.
-func (t *Type) IsFullyInstantiated() bool {
-       return len(t.RParams()) > 0
-}
-
 // Map contains Type fields specific to maps.
 type Map struct {
        Key  *Type // Key type