1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:20:24 -07:00

cmd/compile/internal/types: unexport New and NewBasic

Now that the universe is fully initialized within package types, we
can stop exporting New and NewBasic, which are only needed for that
purpose. So this CL renames "New" to "newType" and "NewBasic" to
"newBasic".

This CL also moves the initialization of Types[TBLANK] and Types[TNIL]
from typecheck.InitUniverse to types.InitTypes, which I missed in an
earlier CL. And a use of "New(TSTRING)" in test/abiutils_test.go,
which should just be "Types[TSTRING]" anyway.

Change-Id: I1d83f93e27b88be289d4f3f6c16357a20f570460
Reviewed-on: https://go-review.googlesource.com/c/go/+/345487
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Matthew Dempsky 2021-08-26 19:18:57 -07:00
parent 82efc05403
commit a9377183d0
4 changed files with 32 additions and 32 deletions

View File

@ -247,7 +247,7 @@ func TestABIUtilsSliceString(t *testing.T) {
// p6 int64, p6 []intr32) (r1 string, r2 int64, r3 string, r4 []int32)
i32 := types.Types[types.TINT32]
sli32 := types.NewSlice(i32)
str := types.New(types.TSTRING)
str := types.Types[types.TSTRING]
i8 := types.Types[types.TINT8]
i64 := types.Types[types.TINT64]
ft := mkFuncType(nil, []*types.Type{sli32, i8, sli32, i8, str, i8, i64, sli32},

View File

@ -94,7 +94,6 @@ func InitUniverse() {
types.BlankSym = s
s.Block = -100
s.Def = NewName(s)
types.Types[types.TBLANK] = types.New(types.TBLANK)
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
ir.BlankNode = ir.AsNode(s.Def)
ir.BlankNode.SetTypecheck(1)
@ -102,10 +101,8 @@ func InitUniverse() {
s = types.BuiltinPkg.Lookup("_")
s.Block = -100
s.Def = NewName(s)
types.Types[types.TBLANK] = types.New(types.TBLANK)
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
types.Types[types.TNIL] = types.New(types.TNIL)
s = types.BuiltinPkg.Lookup("nil")
nnil := NodNil()
nnil.(*ir.NilExpr).SetSym(s)

View File

@ -127,14 +127,14 @@ var (
ComparableType *Type
// Types to represent untyped string and boolean constants.
UntypedString = New(TSTRING)
UntypedBool = New(TBOOL)
UntypedString = newType(TSTRING)
UntypedBool = newType(TBOOL)
// Types to represent untyped numeric constants.
UntypedInt = New(TIDEAL)
UntypedRune = New(TIDEAL)
UntypedFloat = New(TIDEAL)
UntypedComplex = New(TIDEAL)
UntypedInt = newType(TIDEAL)
UntypedRune = newType(TIDEAL)
UntypedFloat = newType(TIDEAL)
UntypedComplex = newType(TIDEAL)
)
// A Type represents a Go type.
@ -586,7 +586,7 @@ func (f *Fields) Append(s ...*Field) {
}
// New returns a new Type of the specified kind.
func New(et Kind) *Type {
func newType(et Kind) *Type {
t := &Type{
kind: et,
width: BADWIDTH,
@ -629,7 +629,7 @@ func NewArray(elem *Type, bound int64) *Type {
if bound < 0 {
base.Fatalf("NewArray: invalid bound %v", bound)
}
t := New(TARRAY)
t := newType(TARRAY)
t.extra = &Array{Elem: elem, Bound: bound}
t.SetNotInHeap(elem.NotInHeap())
if elem.HasTParam() {
@ -650,7 +650,7 @@ func NewSlice(elem *Type) *Type {
return t
}
t := New(TSLICE)
t := newType(TSLICE)
t.extra = Slice{Elem: elem}
elem.cache.slice = t
if elem.HasTParam() {
@ -664,7 +664,7 @@ func NewSlice(elem *Type) *Type {
// NewChan returns a new chan Type with direction dir.
func NewChan(elem *Type, dir ChanDir) *Type {
t := New(TCHAN)
t := newType(TCHAN)
ct := t.ChanType()
ct.Elem = elem
ct.Dir = dir
@ -678,7 +678,7 @@ func NewChan(elem *Type, dir ChanDir) *Type {
}
func NewTuple(t1, t2 *Type) *Type {
t := New(TTUPLE)
t := newType(TTUPLE)
t.extra.(*Tuple).first = t1
t.extra.(*Tuple).second = t2
if t1.HasTParam() || t2.HasTParam() {
@ -691,7 +691,7 @@ func NewTuple(t1, t2 *Type) *Type {
}
func newResults(types []*Type) *Type {
t := New(TRESULTS)
t := newType(TRESULTS)
t.extra.(*Results).Types = types
return t
}
@ -704,14 +704,14 @@ func NewResults(types []*Type) *Type {
}
func newSSA(name string) *Type {
t := New(TSSA)
t := newType(TSSA)
t.extra = name
return t
}
// NewMap returns a new map Type with key type k and element (aka value) type v.
func NewMap(k, v *Type) *Type {
t := New(TMAP)
t := newType(TMAP)
mt := t.MapType()
mt.Key = k
mt.Elem = v
@ -751,7 +751,7 @@ func NewPtr(elem *Type) *Type {
return t
}
t := New(TPTR)
t := newType(TPTR)
t.extra = Ptr{Elem: elem}
t.width = int64(PtrSize)
t.align = uint8(PtrSize)
@ -769,14 +769,14 @@ func NewPtr(elem *Type) *Type {
// NewChanArgs returns a new TCHANARGS type for channel type c.
func NewChanArgs(c *Type) *Type {
t := New(TCHANARGS)
t := newType(TCHANARGS)
t.extra = ChanArgs{T: c}
return t
}
// NewFuncArgs returns a new TFUNCARGS type for func type f.
func NewFuncArgs(f *Type) *Type {
t := New(TFUNCARGS)
t := newType(TFUNCARGS)
t.extra = FuncArgs{T: f}
return t
}
@ -1738,7 +1738,7 @@ var recvType *Type
// FakeRecvType returns the singleton type used for interface method receivers.
func FakeRecvType() *Type {
if recvType == nil {
recvType = NewPtr(New(TSTRUCT))
recvType = NewPtr(newType(TSTRUCT))
}
return recvType
}
@ -1763,7 +1763,7 @@ var (
// 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 := newType(TFORW)
t.sym = obj.Sym()
t.nod = obj
return t
@ -1867,8 +1867,8 @@ func fieldsHasShape(fields []*Field) bool {
}
// NewBasic returns a new basic type of the given kind.
func NewBasic(kind Kind, obj Object) *Type {
t := New(kind)
func newBasic(kind Kind, obj Object) *Type {
t := newType(kind)
t.sym = obj.Sym()
t.nod = obj
return t
@ -1877,7 +1877,7 @@ func NewBasic(kind Kind, obj Object) *Type {
// NewInterface returns a new interface for the given methods and
// embedded types. Embedded types are specified as fields with no Sym.
func NewInterface(pkg *Pkg, methods []*Field) *Type {
t := New(TINTER)
t := newType(TINTER)
t.SetInterface(methods)
for _, f := range methods {
// f.Type could be nil for a broken interface declaration
@ -1900,7 +1900,7 @@ func NewInterface(pkg *Pkg, methods []*Field) *Type {
// NewTypeParam returns a new type param with the specified sym (package and name)
// and specified index within the typeparam list.
func NewTypeParam(sym *Sym, index int) *Type {
t := New(TTYPEPARAM)
t := newType(TTYPEPARAM)
t.sym = sym
t.extra.(*Typeparam).index = index
t.SetHasTParam(true)
@ -1934,7 +1934,7 @@ func (t *Type) Bound() *Type {
// NewUnion returns a new union with the specified set of terms (types). If
// tildes[i] is true, then terms[i] represents ~T, rather than just T.
func NewUnion(terms []*Type, tildes []bool) *Type {
t := New(TUNION)
t := newType(TUNION)
if len(terms) != len(tildes) {
base.Fatalf("Mismatched terms and tildes for NewUnion")
}
@ -1982,7 +1982,7 @@ func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Typ
recvs = []*Field{recv}
}
t := New(TFUNC)
t := newType(TFUNC)
ft := t.FuncType()
funargs := func(fields []*Field, funarg Funarg) *Type {
@ -2018,7 +2018,7 @@ func NewSignature(pkg *Pkg, recv *Field, tparams, params, results []*Field) *Typ
// NewStruct returns a new struct with the given fields.
func NewStruct(pkg *Pkg, fields []*Field) *Type {
t := New(TSTRUCT)
t := newType(TSTRUCT)
t.SetFields(fields)
if anyBroke(fields) {
t.SetBroke(true)

View File

@ -57,11 +57,11 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
SimType[et] = et
}
Types[TANY] = New(TANY)
Types[TANY] = newType(TANY)
Types[TINTER] = NewInterface(LocalPkg, nil)
defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
typ := New(kind)
typ := newType(kind)
obj := defTypeName(pkg.Lookup(name), typ)
typ.sym = obj.Sym()
typ.nod = obj
@ -109,6 +109,9 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
Types[TUNSAFEPTR] = defBasic(TUNSAFEPTR, UnsafePkg, "Pointer")
Types[TBLANK] = newType(TBLANK)
Types[TNIL] = newType(TNIL)
// simple aliases
SimType[TMAP] = TPTR
SimType[TCHAN] = TPTR