]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: rename newNamedTypeWithSym, add some commemnts
authorDan Scales <danscales@google.com>
Fri, 2 Apr 2021 21:31:15 +0000 (14:31 -0700)
committerDan Scales <danscales@google.com>
Sat, 3 Apr 2021 18:16:29 +0000 (18:16 +0000)
Renamed newNamedTypeWithSym to newIncompleteNamedType. Added some extra
comments to types.NewNamed and types.SetUnderlying.

Change-Id: Idc5a6379991c26b429d91bae9fe1adef8457a75c
Reviewed-on: https://go-review.googlesource.com/c/go/+/307029
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Ingo Oeser <nightlyone@googlemail.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/types/type.go

index 350f8f8c2a1e68ae5be8dc83d5a931f47e031d4c..4db688571e338d5a995d599ff80a2a4f2235522c 100644 (file)
@@ -716,7 +716,7 @@ func (subst *subster) typ(t *types.Type) *types.Type {
                // In order to deal with recursive generic types, create a TFORW
                // type initially and set the Def field of its sym, so it can be
                // found if this type appears recursively within the type.
-               forw = newNamedTypeWithSym(t.Pos(), newsym)
+               forw = newIncompleteNamedType(t.Pos(), newsym)
                //println("Creating new type by sub", newsym.Name, forw.HasTParam())
                forw.SetRParams(neededTargs)
        }
@@ -896,9 +896,9 @@ func deref(t *types.Type) *types.Type {
        return t
 }
 
-// newNamedTypeWithSym returns a TFORW type t with name specified by sym, such
+// newIncompleteNamedType returns a TFORW type t with name specified by sym, such
 // that t.nod and sym.Def are set correctly.
-func newNamedTypeWithSym(pos src.XPos, sym *types.Sym) *types.Type {
+func newIncompleteNamedType(pos src.XPos, sym *types.Sym) *types.Type {
        name := ir.NewDeclNameAt(pos, ir.OTYPE, sym)
        forw := types.NewNamed(name)
        name.SetType(forw)
index 06c584714e1eb5c032183f4b2e1a3cf30cce69a8..8680559a412970277e2513fe6d1620a55d4393cc 100644 (file)
@@ -120,7 +120,7 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
                        // which may set HasTParam) before translating the
                        // underlying type itself, so we handle recursion
                        // correctly, including via method signatures.
-                       ntyp := newNamedTypeWithSym(g.pos(typ.Obj().Pos()), s)
+                       ntyp := newIncompleteNamedType(g.pos(typ.Obj().Pos()), s)
                        g.typs[typ] = ntyp
 
                        // If ntyp still has type params, then we must be
index 31a99781d126e35a7bd9e517b4a2e5e17a13f05f..762cdd32584f4b7900a1a380cae61135c309f4ab 100644 (file)
@@ -1643,7 +1643,10 @@ var (
        TypeResultMem = newResults([]*Type{TypeMem})
 )
 
-// NewNamed returns a new named type for the given type name. obj should be an ir.Name.
+// NewNamed returns a new named type for the given type name. obj should be an
+// ir.Name. The new type is incomplete, and the underlying type should be set
+// later via SetUnderlying(). References to the type are maintained until the type
+// is filled in, so those references can be updated when the type is complete.
 func NewNamed(obj Object) *Type {
        t := New(TFORW)
        t.sym = obj.Sym()
@@ -1659,7 +1662,8 @@ func (t *Type) Obj() Object {
        return nil
 }
 
-// SetUnderlying sets the underlying type.
+// SetUnderlying sets the underlying type. SetUnderlying automatically updates any
+// types that were waiting for this type to be completed.
 func (t *Type) SetUnderlying(underlying *Type) {
        if underlying.kind == TFORW {
                // This type isn't computed yet; when it is, update n.