mirror of
https://github.com/golang/go
synced 2024-11-23 07:30:05 -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:
parent
82efc05403
commit
a9377183d0
@ -247,7 +247,7 @@ func TestABIUtilsSliceString(t *testing.T) {
|
|||||||
// p6 int64, p6 []intr32) (r1 string, r2 int64, r3 string, r4 []int32)
|
// p6 int64, p6 []intr32) (r1 string, r2 int64, r3 string, r4 []int32)
|
||||||
i32 := types.Types[types.TINT32]
|
i32 := types.Types[types.TINT32]
|
||||||
sli32 := types.NewSlice(i32)
|
sli32 := types.NewSlice(i32)
|
||||||
str := types.New(types.TSTRING)
|
str := types.Types[types.TSTRING]
|
||||||
i8 := types.Types[types.TINT8]
|
i8 := types.Types[types.TINT8]
|
||||||
i64 := types.Types[types.TINT64]
|
i64 := types.Types[types.TINT64]
|
||||||
ft := mkFuncType(nil, []*types.Type{sli32, i8, sli32, i8, str, i8, i64, sli32},
|
ft := mkFuncType(nil, []*types.Type{sli32, i8, sli32, i8, str, i8, i64, sli32},
|
||||||
|
@ -94,7 +94,6 @@ func InitUniverse() {
|
|||||||
types.BlankSym = s
|
types.BlankSym = s
|
||||||
s.Block = -100
|
s.Block = -100
|
||||||
s.Def = NewName(s)
|
s.Def = NewName(s)
|
||||||
types.Types[types.TBLANK] = types.New(types.TBLANK)
|
|
||||||
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
|
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
|
||||||
ir.BlankNode = ir.AsNode(s.Def)
|
ir.BlankNode = ir.AsNode(s.Def)
|
||||||
ir.BlankNode.SetTypecheck(1)
|
ir.BlankNode.SetTypecheck(1)
|
||||||
@ -102,10 +101,8 @@ func InitUniverse() {
|
|||||||
s = types.BuiltinPkg.Lookup("_")
|
s = types.BuiltinPkg.Lookup("_")
|
||||||
s.Block = -100
|
s.Block = -100
|
||||||
s.Def = NewName(s)
|
s.Def = NewName(s)
|
||||||
types.Types[types.TBLANK] = types.New(types.TBLANK)
|
|
||||||
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
|
ir.AsNode(s.Def).SetType(types.Types[types.TBLANK])
|
||||||
|
|
||||||
types.Types[types.TNIL] = types.New(types.TNIL)
|
|
||||||
s = types.BuiltinPkg.Lookup("nil")
|
s = types.BuiltinPkg.Lookup("nil")
|
||||||
nnil := NodNil()
|
nnil := NodNil()
|
||||||
nnil.(*ir.NilExpr).SetSym(s)
|
nnil.(*ir.NilExpr).SetSym(s)
|
||||||
|
@ -127,14 +127,14 @@ var (
|
|||||||
ComparableType *Type
|
ComparableType *Type
|
||||||
|
|
||||||
// Types to represent untyped string and boolean constants.
|
// Types to represent untyped string and boolean constants.
|
||||||
UntypedString = New(TSTRING)
|
UntypedString = newType(TSTRING)
|
||||||
UntypedBool = New(TBOOL)
|
UntypedBool = newType(TBOOL)
|
||||||
|
|
||||||
// Types to represent untyped numeric constants.
|
// Types to represent untyped numeric constants.
|
||||||
UntypedInt = New(TIDEAL)
|
UntypedInt = newType(TIDEAL)
|
||||||
UntypedRune = New(TIDEAL)
|
UntypedRune = newType(TIDEAL)
|
||||||
UntypedFloat = New(TIDEAL)
|
UntypedFloat = newType(TIDEAL)
|
||||||
UntypedComplex = New(TIDEAL)
|
UntypedComplex = newType(TIDEAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
// A Type represents a Go type.
|
// 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.
|
// New returns a new Type of the specified kind.
|
||||||
func New(et Kind) *Type {
|
func newType(et Kind) *Type {
|
||||||
t := &Type{
|
t := &Type{
|
||||||
kind: et,
|
kind: et,
|
||||||
width: BADWIDTH,
|
width: BADWIDTH,
|
||||||
@ -629,7 +629,7 @@ func NewArray(elem *Type, bound int64) *Type {
|
|||||||
if bound < 0 {
|
if bound < 0 {
|
||||||
base.Fatalf("NewArray: invalid bound %v", bound)
|
base.Fatalf("NewArray: invalid bound %v", bound)
|
||||||
}
|
}
|
||||||
t := New(TARRAY)
|
t := newType(TARRAY)
|
||||||
t.extra = &Array{Elem: elem, Bound: bound}
|
t.extra = &Array{Elem: elem, Bound: bound}
|
||||||
t.SetNotInHeap(elem.NotInHeap())
|
t.SetNotInHeap(elem.NotInHeap())
|
||||||
if elem.HasTParam() {
|
if elem.HasTParam() {
|
||||||
@ -650,7 +650,7 @@ func NewSlice(elem *Type) *Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
t := New(TSLICE)
|
t := newType(TSLICE)
|
||||||
t.extra = Slice{Elem: elem}
|
t.extra = Slice{Elem: elem}
|
||||||
elem.cache.slice = t
|
elem.cache.slice = t
|
||||||
if elem.HasTParam() {
|
if elem.HasTParam() {
|
||||||
@ -664,7 +664,7 @@ func NewSlice(elem *Type) *Type {
|
|||||||
|
|
||||||
// NewChan returns a new chan Type with direction dir.
|
// NewChan returns a new chan Type with direction dir.
|
||||||
func NewChan(elem *Type, dir ChanDir) *Type {
|
func NewChan(elem *Type, dir ChanDir) *Type {
|
||||||
t := New(TCHAN)
|
t := newType(TCHAN)
|
||||||
ct := t.ChanType()
|
ct := t.ChanType()
|
||||||
ct.Elem = elem
|
ct.Elem = elem
|
||||||
ct.Dir = dir
|
ct.Dir = dir
|
||||||
@ -678,7 +678,7 @@ func NewChan(elem *Type, dir ChanDir) *Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTuple(t1, t2 *Type) *Type {
|
func NewTuple(t1, t2 *Type) *Type {
|
||||||
t := New(TTUPLE)
|
t := newType(TTUPLE)
|
||||||
t.extra.(*Tuple).first = t1
|
t.extra.(*Tuple).first = t1
|
||||||
t.extra.(*Tuple).second = t2
|
t.extra.(*Tuple).second = t2
|
||||||
if t1.HasTParam() || t2.HasTParam() {
|
if t1.HasTParam() || t2.HasTParam() {
|
||||||
@ -691,7 +691,7 @@ func NewTuple(t1, t2 *Type) *Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newResults(types []*Type) *Type {
|
func newResults(types []*Type) *Type {
|
||||||
t := New(TRESULTS)
|
t := newType(TRESULTS)
|
||||||
t.extra.(*Results).Types = types
|
t.extra.(*Results).Types = types
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -704,14 +704,14 @@ func NewResults(types []*Type) *Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newSSA(name string) *Type {
|
func newSSA(name string) *Type {
|
||||||
t := New(TSSA)
|
t := newType(TSSA)
|
||||||
t.extra = name
|
t.extra = name
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMap returns a new map Type with key type k and element (aka value) type v.
|
// NewMap returns a new map Type with key type k and element (aka value) type v.
|
||||||
func NewMap(k, v *Type) *Type {
|
func NewMap(k, v *Type) *Type {
|
||||||
t := New(TMAP)
|
t := newType(TMAP)
|
||||||
mt := t.MapType()
|
mt := t.MapType()
|
||||||
mt.Key = k
|
mt.Key = k
|
||||||
mt.Elem = v
|
mt.Elem = v
|
||||||
@ -751,7 +751,7 @@ func NewPtr(elem *Type) *Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
t := New(TPTR)
|
t := newType(TPTR)
|
||||||
t.extra = Ptr{Elem: elem}
|
t.extra = Ptr{Elem: elem}
|
||||||
t.width = int64(PtrSize)
|
t.width = int64(PtrSize)
|
||||||
t.align = uint8(PtrSize)
|
t.align = uint8(PtrSize)
|
||||||
@ -769,14 +769,14 @@ func NewPtr(elem *Type) *Type {
|
|||||||
|
|
||||||
// NewChanArgs returns a new TCHANARGS type for channel type c.
|
// NewChanArgs returns a new TCHANARGS type for channel type c.
|
||||||
func NewChanArgs(c *Type) *Type {
|
func NewChanArgs(c *Type) *Type {
|
||||||
t := New(TCHANARGS)
|
t := newType(TCHANARGS)
|
||||||
t.extra = ChanArgs{T: c}
|
t.extra = ChanArgs{T: c}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFuncArgs returns a new TFUNCARGS type for func type f.
|
// NewFuncArgs returns a new TFUNCARGS type for func type f.
|
||||||
func NewFuncArgs(f *Type) *Type {
|
func NewFuncArgs(f *Type) *Type {
|
||||||
t := New(TFUNCARGS)
|
t := newType(TFUNCARGS)
|
||||||
t.extra = FuncArgs{T: f}
|
t.extra = FuncArgs{T: f}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
@ -1738,7 +1738,7 @@ var recvType *Type
|
|||||||
// FakeRecvType returns the singleton type used for interface method receivers.
|
// FakeRecvType returns the singleton type used for interface method receivers.
|
||||||
func FakeRecvType() *Type {
|
func FakeRecvType() *Type {
|
||||||
if recvType == nil {
|
if recvType == nil {
|
||||||
recvType = NewPtr(New(TSTRUCT))
|
recvType = NewPtr(newType(TSTRUCT))
|
||||||
}
|
}
|
||||||
return recvType
|
return recvType
|
||||||
}
|
}
|
||||||
@ -1763,7 +1763,7 @@ var (
|
|||||||
// maintained until the type is filled in, so those references can be updated when
|
// maintained until the type is filled in, so those references can be updated when
|
||||||
// the type is complete.
|
// the type is complete.
|
||||||
func NewNamed(obj Object) *Type {
|
func NewNamed(obj Object) *Type {
|
||||||
t := New(TFORW)
|
t := newType(TFORW)
|
||||||
t.sym = obj.Sym()
|
t.sym = obj.Sym()
|
||||||
t.nod = obj
|
t.nod = obj
|
||||||
return t
|
return t
|
||||||
@ -1867,8 +1867,8 @@ 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 := New(kind)
|
t := newType(kind)
|
||||||
t.sym = obj.Sym()
|
t.sym = obj.Sym()
|
||||||
t.nod = obj
|
t.nod = obj
|
||||||
return t
|
return t
|
||||||
@ -1877,7 +1877,7 @@ func NewBasic(kind Kind, obj Object) *Type {
|
|||||||
// NewInterface returns a new interface for the given methods and
|
// NewInterface returns a new interface for the given methods and
|
||||||
// embedded types. Embedded types are specified as fields with no Sym.
|
// embedded types. Embedded types are specified as fields with no Sym.
|
||||||
func NewInterface(pkg *Pkg, methods []*Field) *Type {
|
func NewInterface(pkg *Pkg, methods []*Field) *Type {
|
||||||
t := New(TINTER)
|
t := newType(TINTER)
|
||||||
t.SetInterface(methods)
|
t.SetInterface(methods)
|
||||||
for _, f := range methods {
|
for _, f := range methods {
|
||||||
// f.Type could be nil for a broken interface declaration
|
// 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)
|
// NewTypeParam returns a new type param with the specified sym (package and name)
|
||||||
// and specified index within the typeparam list.
|
// and specified index within the typeparam list.
|
||||||
func NewTypeParam(sym *Sym, index int) *Type {
|
func NewTypeParam(sym *Sym, index int) *Type {
|
||||||
t := New(TTYPEPARAM)
|
t := newType(TTYPEPARAM)
|
||||||
t.sym = sym
|
t.sym = sym
|
||||||
t.extra.(*Typeparam).index = index
|
t.extra.(*Typeparam).index = index
|
||||||
t.SetHasTParam(true)
|
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
|
// 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.
|
// tildes[i] is true, then terms[i] represents ~T, rather than just T.
|
||||||
func NewUnion(terms []*Type, tildes []bool) *Type {
|
func NewUnion(terms []*Type, tildes []bool) *Type {
|
||||||
t := New(TUNION)
|
t := newType(TUNION)
|
||||||
if len(terms) != len(tildes) {
|
if len(terms) != len(tildes) {
|
||||||
base.Fatalf("Mismatched terms and tildes for NewUnion")
|
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}
|
recvs = []*Field{recv}
|
||||||
}
|
}
|
||||||
|
|
||||||
t := New(TFUNC)
|
t := newType(TFUNC)
|
||||||
ft := t.FuncType()
|
ft := t.FuncType()
|
||||||
|
|
||||||
funargs := func(fields []*Field, funarg Funarg) *Type {
|
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.
|
// NewStruct returns a new struct with the given fields.
|
||||||
func NewStruct(pkg *Pkg, fields []*Field) *Type {
|
func NewStruct(pkg *Pkg, fields []*Field) *Type {
|
||||||
t := New(TSTRUCT)
|
t := newType(TSTRUCT)
|
||||||
t.SetFields(fields)
|
t.SetFields(fields)
|
||||||
if anyBroke(fields) {
|
if anyBroke(fields) {
|
||||||
t.SetBroke(true)
|
t.SetBroke(true)
|
||||||
|
@ -57,11 +57,11 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
|
|||||||
SimType[et] = et
|
SimType[et] = et
|
||||||
}
|
}
|
||||||
|
|
||||||
Types[TANY] = New(TANY)
|
Types[TANY] = newType(TANY)
|
||||||
Types[TINTER] = NewInterface(LocalPkg, nil)
|
Types[TINTER] = NewInterface(LocalPkg, nil)
|
||||||
|
|
||||||
defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
|
defBasic := func(kind Kind, pkg *Pkg, name string) *Type {
|
||||||
typ := New(kind)
|
typ := newType(kind)
|
||||||
obj := defTypeName(pkg.Lookup(name), typ)
|
obj := defTypeName(pkg.Lookup(name), typ)
|
||||||
typ.sym = obj.Sym()
|
typ.sym = obj.Sym()
|
||||||
typ.nod = obj
|
typ.nod = obj
|
||||||
@ -109,6 +109,9 @@ func InitTypes(defTypeName func(sym *Sym, typ *Type) Object) {
|
|||||||
|
|
||||||
Types[TUNSAFEPTR] = defBasic(TUNSAFEPTR, UnsafePkg, "Pointer")
|
Types[TUNSAFEPTR] = defBasic(TUNSAFEPTR, UnsafePkg, "Pointer")
|
||||||
|
|
||||||
|
Types[TBLANK] = newType(TBLANK)
|
||||||
|
Types[TNIL] = newType(TNIL)
|
||||||
|
|
||||||
// simple aliases
|
// simple aliases
|
||||||
SimType[TMAP] = TPTR
|
SimType[TMAP] = TPTR
|
||||||
SimType[TCHAN] = TPTR
|
SimType[TCHAN] = TPTR
|
||||||
|
Loading…
Reference in New Issue
Block a user