]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: remove need for the instance struct
authorRobert Findley <rfindley@google.com>
Tue, 31 Aug 2021 21:00:59 +0000 (17:00 -0400)
committerRobert Findley <rfindley@google.com>
Tue, 31 Aug 2021 22:45:26 +0000 (22:45 +0000)
This is a port of CL 345177 to go/types.

Change-Id: I79fcfbf5b28e9a7a2e66c81bc831e164a8da8bbb
Reviewed-on: https://go-review.googlesource.com/c/go/+/346551
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/instantiate.go
src/go/types/named.go
src/go/types/typestring.go

index 09c2ecf8b4cd8aaca9389de20b31303a72165364..6f0b3571d13cbff242057b580b7afb07acfa0c6f 100644 (file)
@@ -130,7 +130,7 @@ func (check *Checker) instance(pos token.Pos, typ Type, targs []Type) Type {
                tname := NewTypeName(pos, t.obj.pkg, t.obj.name, nil)
                named := check.newNamed(tname, t, nil, nil, nil) // methods and tparams are set when named is loaded
                named.targs = NewTypeList(targs)
-               named.instance = &instance{pos}
+               named.instPos = &pos
                if check != nil {
                        check.typMap[h] = named
                }
index 6f89922a4140980e8c28a164ca39319ca5a5a04b..4ee76eb8357c9fa6ae08d66e147e4102eb71f9ef 100644 (file)
@@ -17,7 +17,7 @@ type Named struct {
        orig       *Named      // original, uninstantiated type
        fromRHS    Type        // type (on RHS of declaration) this *Named type is derived of (for cycle reporting)
        underlying Type        // possibly a *Named during setup; never a *Named once set up completely
-       instance   *instance   // syntactic information for lazy instantiation
+       instPos    *token.Pos  // position information for lazy instantiation, or nil
        tparams    *TParamList // type parameters, or nil
        targs      *TypeList   // type arguments (after instantiation), or nil
        methods    []*Func     // methods declared for this type (not the method set of this type); signatures are type-checked lazily
@@ -240,24 +240,16 @@ func (n *Named) setUnderlying(typ Type) {
        }
 }
 
-// instance holds position information for use in lazy instantiation.
-//
-// TODO(rfindley): instance is probably unnecessary now. See if it can be
-// eliminated.
-type instance struct {
-       pos token.Pos // position of type instantiation; for error reporting only
-}
-
 // expand ensures that the underlying type of n is instantiated.
 // The underlying type will be Typ[Invalid] if there was an error.
 func (n *Named) expand(typMap map[string]*Named) *Named {
-       if n.instance != nil {
+       if n.instPos != nil {
                // n must be loaded before instantiation, in order to have accurate
                // tparams. This is done implicitly by the call to n.TParams, but making it
                // explicit is harmless: load is idempotent.
                n.load()
                var u Type
-               if n.check.validateTArgLen(n.instance.pos, n.tparams.Len(), n.targs.Len()) {
+               if n.check.validateTArgLen(*n.instPos, n.tparams.Len(), n.targs.Len()) {
                        if typMap == nil {
                                if n.check != nil {
                                        typMap = n.check.typMap
@@ -270,13 +262,13 @@ func (n *Named) expand(typMap map[string]*Named) *Named {
                                        typMap = map[string]*Named{h: n}
                                }
                        }
-                       u = n.check.subst(n.instance.pos, n.orig.underlying, makeSubstMap(n.TParams().list(), n.targs.list()), typMap)
+                       u = n.check.subst(*n.instPos, n.orig.underlying, makeSubstMap(n.TParams().list(), n.targs.list()), typMap)
                } else {
                        u = Typ[Invalid]
                }
                n.underlying = u
                n.fromRHS = u
-               n.instance = nil
+               n.instPos = nil
        }
        return n
 }
index cdc7ea9f512d4761b2542e22078d4c2052f3da09..03f735f2fd3e517abd1ce675780d0a81a877125a 100644 (file)
@@ -197,7 +197,7 @@ func writeType(buf *bytes.Buffer, typ Type, qf Qualifier, visited []Type) {
                }
 
        case *Named:
-               if t.instance != nil {
+               if t.instPos != nil {
                        buf.WriteByte(instanceMarker)
                }
                writeTypeName(buf, t.obj, qf)