cmd/compile/internal/types: remove Type.sym and rename Type.nod to Type.obj

Now that Ntype is gone, we no longer require separate sym and nod
fields for Type. It's now always the case that t.sym == t.nod.Sym(),
or that t.sym and t.nod are both nil.

While here, rename nod to obj, to better reflect that in fact it's
always an object (i.e., *ir.Name), not merely a type literal (which no
longer exists in package ir).

Change-Id: Iba4c1590ca585b816ff6b70947ad2a1109918955
Reviewed-on: https://go-review.googlesource.com/c/go/+/405656
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Matthew Dempsky 2022-05-10 16:26:41 -07:00
parent 53db708a1d
commit aa6b75dd7d
4 changed files with 20 additions and 23 deletions

View File

@ -42,7 +42,7 @@ func identical(t1, t2 *Type, flags int, assumedEqual map[typePair]struct{}) bool
if t1 == nil || t2 == nil || t1.kind != t2.kind { if t1 == nil || t2 == nil || t1.kind != t2.kind {
return false return false
} }
if t1.sym != nil || t2.sym != nil { if t1.obj != nil || t2.obj != nil {
if flags&identStrict == 0 && (t1.HasShape() || t2.HasShape()) { if flags&identStrict == 0 && (t1.HasShape() || t2.HasShape()) {
switch t1.kind { switch t1.kind {
case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64, TBOOL, TSTRING, TPTR, TUNSAFEPTR: case TINT8, TUINT8, TINT16, TUINT16, TINT32, TUINT32, TINT64, TUINT64, TINT, TUINT, TUINTPTR, TCOMPLEX64, TCOMPLEX128, TFLOAT32, TFLOAT64, TBOOL, TSTRING, TPTR, TUNSAFEPTR:

View File

@ -21,7 +21,7 @@ func TestSizeof(t *testing.T) {
_64bit uintptr // size on 64bit platforms _64bit uintptr // size on 64bit platforms
}{ }{
{Sym{}, 32, 64}, {Sym{}, 32, 64},
{Type{}, 64, 112}, {Type{}, 60, 104},
{Map{}, 20, 40}, {Map{}, 20, 40},
{Forward{}, 20, 32}, {Forward{}, 20, 32},
{Func{}, 28, 48}, {Func{}, 28, 48},

View File

@ -168,7 +168,7 @@ type Type struct {
allMethods Fields allMethods Fields
// canonical OTYPE node for a named type (should be an ir.Name node with same sym) // canonical OTYPE node for a named type (should be an ir.Name node with same sym)
nod Object obj Object
// the underlying type (type literal or predeclared type) for a defined type // the underlying type (type literal or predeclared type) for a defined type
underlying *Type underlying *Type
@ -178,7 +178,6 @@ type Type struct {
slice *Type // []T, or nil slice *Type // []T, or nil
} }
sym *Sym // symbol containing name, for named types
vargen int32 // unique name for OTYPE/ONAME vargen int32 // unique name for OTYPE/ONAME
kind Kind // kind of type kind Kind // kind of type
@ -238,7 +237,12 @@ func (t *Type) SetHasShape(b bool) { t.flags.set(typeHasShape, b) }
func (t *Type) Kind() Kind { return t.kind } func (t *Type) Kind() Kind { return t.kind }
// Sym returns the name of type t. // Sym returns the name of type t.
func (t *Type) Sym() *Sym { return t.sym } func (t *Type) Sym() *Sym {
if t.obj != nil {
return t.obj.Sym()
}
return nil
}
// OrigType returns the original generic type that t is an // OrigType returns the original generic type that t is an
// instantiation of, if any. // instantiation of, if any.
@ -251,8 +255,8 @@ func (t *Type) Underlying() *Type { return t.underlying }
// Pos returns a position associated with t, if any. // Pos returns a position associated with t, if any.
// This should only be used for diagnostics. // This should only be used for diagnostics.
func (t *Type) Pos() src.XPos { func (t *Type) Pos() src.XPos {
if t.nod != nil { if t.obj != nil {
return t.nod.Pos() return t.obj.Pos()
} }
return src.NoXPos return src.NoXPos
} }
@ -1190,7 +1194,7 @@ func (t *Type) cmp(x *Type) Cmp {
return cmpForNe(t.kind < x.kind) return cmpForNe(t.kind < x.kind)
} }
if t.sym != nil || x.sym != nil { if t.obj != nil || x.obj != nil {
// Special case: we keep byte and uint8 separate // Special case: we keep byte and uint8 separate
// for error messages. Treat them as equal. // for error messages. Treat them as equal.
switch t.kind { switch t.kind {
@ -1212,11 +1216,11 @@ func (t *Type) cmp(x *Type) Cmp {
} }
} }
if c := t.sym.cmpsym(x.sym); c != CMPeq { if c := t.Sym().cmpsym(x.Sym()); c != CMPeq {
return c return c
} }
if x.sym != nil { if x.obj != nil {
// Syms non-nil, if vargens match then equal. // Syms non-nil, if vargens match then equal.
if t.vargen != x.vargen { if t.vargen != x.vargen {
return cmpForNe(t.vargen < x.vargen) return cmpForNe(t.vargen < x.vargen)
@ -1708,9 +1712,8 @@ var (
// the type is complete. // the type is complete.
func NewNamed(obj Object) *Type { func NewNamed(obj Object) *Type {
t := newType(TFORW) t := newType(TFORW)
t.sym = obj.Sym() t.obj = obj
t.nod = obj if obj.Sym().Pkg == ShapePkg {
if t.sym.Pkg == ShapePkg {
t.SetIsShape(true) t.SetIsShape(true)
t.SetHasShape(true) t.SetHasShape(true)
} }
@ -1719,10 +1722,7 @@ func NewNamed(obj Object) *Type {
// Obj returns the canonical type name node for a named type t, nil for an unnamed type. // Obj returns the canonical type name node for a named type t, nil for an unnamed type.
func (t *Type) Obj() Object { func (t *Type) Obj() Object {
if t.sym != nil { return t.obj
return t.nod
}
return nil
} }
// typeGen tracks the number of function-scoped defined types that // typeGen tracks the number of function-scoped defined types that
@ -1815,8 +1815,7 @@ func fieldsHasShape(fields []*Field) bool {
// NewBasic returns a new basic type of the given kind. // NewBasic returns a new basic type of the given kind.
func newBasic(kind Kind, obj Object) *Type { func newBasic(kind Kind, obj Object) *Type {
t := newType(kind) t := newType(kind)
t.sym = obj.Sym() t.obj = obj
t.nod = obj
return t return t
} }
@ -1845,8 +1844,7 @@ func NewInterface(pkg *Pkg, methods []*Field, implicit bool) *Type {
// and specified index within the typeparam list. // and specified index within the typeparam list.
func NewTypeParam(obj Object, index int) *Type { func NewTypeParam(obj Object, index int) *Type {
t := newType(TTYPEPARAM) t := newType(TTYPEPARAM)
t.sym = obj.Sym() t.obj = obj
t.nod = obj
t.extra.(*Typeparam).index = index t.extra.(*Typeparam).index = index
t.SetHasTParam(true) t.SetHasTParam(true)
return t return t

View File

@ -64,8 +64,7 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
defBasic := func(kind Kind, pkg *Pkg, name string) *Type { defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
typ := newType(kind) typ := newType(kind)
obj := defTypeName(pkg.Lookup(name), typ) obj := defTypeName(pkg.Lookup(name), typ)
typ.sym = obj.Sym() typ.obj = obj
typ.nod = obj
if kind != TANY { if kind != TANY {
CheckSize(typ) CheckSize(typ)
} }