mirror of
https://github.com/golang/go.git
synced 2025-05-28 19:02:22 +00:00
[dev.regabi] cmd/compile: prefer types constructors over typecheck
Similar to the earlier mkbuiltin cleanup, there's a bunch of code that calls typecheck.NewFuncType or typecheck.NewStructType, which can now just call types.NewSignature and types.NewStruct, respectively. Passes toolstash -cmp. Change-Id: Ie6e09f1a7efef84b9a2bb5daa7087a6879979668 Reviewed-on: https://go-review.googlesource.com/c/go/+/279955 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
18ebfb49e9
commit
addade2cce
@ -289,11 +289,11 @@ func hashfor(t *types.Type) ir.Node {
|
|||||||
|
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||||
}, []*ir.Field{
|
}, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||||
}))
|
}))
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
@ -777,12 +777,12 @@ func hashmem(t *types.Type) ir.Node {
|
|||||||
|
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||||
}, []*ir.Field{
|
}, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||||
}))
|
}))
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
@ -1419,7 +1419,11 @@ func WriteBasicTypes() {
|
|||||||
// The latter is the type of an auto-generated wrapper.
|
// The latter is the type of an auto-generated wrapper.
|
||||||
WriteType(types.NewPtr(types.ErrorType))
|
WriteType(types.NewPtr(types.ErrorType))
|
||||||
|
|
||||||
WriteType(typecheck.NewFuncType(nil, []*ir.Field{ir.NewField(base.Pos, nil, nil, types.ErrorType)}, []*ir.Field{ir.NewField(base.Pos, nil, nil, types.Types[types.TSTRING])}))
|
WriteType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||||
|
types.NewField(base.Pos, nil, types.ErrorType),
|
||||||
|
}, []*types.Field{
|
||||||
|
types.NewField(base.Pos, nil, types.Types[types.TSTRING]),
|
||||||
|
}))
|
||||||
|
|
||||||
// add paths for runtime and main, which 6l imports implicitly.
|
// add paths for runtime and main, which 6l imports implicitly.
|
||||||
dimportpath(ir.Pkgs.Runtime)
|
dimportpath(ir.Pkgs.Runtime)
|
||||||
|
@ -676,30 +676,26 @@ func autotmpname(n int) string {
|
|||||||
|
|
||||||
// f is method type, with receiver.
|
// f is method type, with receiver.
|
||||||
// return function type, receiver as first argument (or not).
|
// return function type, receiver as first argument (or not).
|
||||||
func NewMethodType(f *types.Type, receiver *types.Type) *types.Type {
|
func NewMethodType(sig *types.Type, recv *types.Type) *types.Type {
|
||||||
inLen := f.Params().Fields().Len()
|
nrecvs := 0
|
||||||
if receiver != nil {
|
if recv != nil {
|
||||||
inLen++
|
nrecvs++
|
||||||
}
|
|
||||||
in := make([]*ir.Field, 0, inLen)
|
|
||||||
|
|
||||||
if receiver != nil {
|
|
||||||
d := ir.NewField(base.Pos, nil, nil, receiver)
|
|
||||||
in = append(in, d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range f.Params().Fields().Slice() {
|
params := make([]*types.Field, nrecvs+sig.Params().Fields().Len())
|
||||||
d := ir.NewField(base.Pos, nil, nil, t.Type)
|
if recv != nil {
|
||||||
d.IsDDD = t.IsDDD()
|
params[0] = types.NewField(base.Pos, nil, recv)
|
||||||
in = append(in, d)
|
}
|
||||||
|
for i, param := range sig.Params().Fields().Slice() {
|
||||||
|
d := types.NewField(base.Pos, nil, param.Type)
|
||||||
|
d.SetIsDDD(param.IsDDD())
|
||||||
|
params[nrecvs+i] = d
|
||||||
}
|
}
|
||||||
|
|
||||||
outLen := f.Results().Fields().Len()
|
results := make([]*types.Field, sig.Results().Fields().Len())
|
||||||
out := make([]*ir.Field, 0, outLen)
|
for i, t := range sig.Results().Fields().Slice() {
|
||||||
for _, t := range f.Results().Fields().Slice() {
|
results[i] = types.NewField(base.Pos, nil, t.Type)
|
||||||
d := ir.NewField(base.Pos, nil, nil, t.Type)
|
|
||||||
out = append(out, d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewFuncType(nil, in, out)
|
return types.NewSignature(types.LocalPkg, nil, params, results)
|
||||||
}
|
}
|
||||||
|
@ -73,17 +73,17 @@ func ClosureType(clo *ir.ClosureExpr) *types.Type {
|
|||||||
// The information appears in the binary in the form of type descriptors;
|
// The information appears in the binary in the form of type descriptors;
|
||||||
// the struct is unnamed so that closures in multiple packages with the
|
// the struct is unnamed so that closures in multiple packages with the
|
||||||
// same struct type can share the descriptor.
|
// same struct type can share the descriptor.
|
||||||
fields := []*ir.Field{
|
fields := []*types.Field{
|
||||||
ir.NewField(base.Pos, Lookup(".F"), nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, Lookup(".F"), types.Types[types.TUINTPTR]),
|
||||||
}
|
}
|
||||||
for _, v := range clo.Func.ClosureVars {
|
for _, v := range clo.Func.ClosureVars {
|
||||||
typ := v.Type()
|
typ := v.Type()
|
||||||
if !v.Byval() {
|
if !v.Byval() {
|
||||||
typ = types.NewPtr(typ)
|
typ = types.NewPtr(typ)
|
||||||
}
|
}
|
||||||
fields = append(fields, ir.NewField(base.Pos, v.Sym(), nil, typ))
|
fields = append(fields, types.NewField(base.Pos, v.Sym(), typ))
|
||||||
}
|
}
|
||||||
typ := NewStructType(fields)
|
typ := types.NewStruct(types.NoPkg, fields)
|
||||||
typ.SetNoalg(true)
|
typ.SetNoalg(true)
|
||||||
return typ
|
return typ
|
||||||
}
|
}
|
||||||
@ -92,9 +92,9 @@ func ClosureType(clo *ir.ClosureExpr) *types.Type {
|
|||||||
// needed in the closure for n (n must be a OCALLPART node).
|
// needed in the closure for n (n must be a OCALLPART node).
|
||||||
// The address of a variable of the returned type can be cast to a func.
|
// The address of a variable of the returned type can be cast to a func.
|
||||||
func PartialCallType(n *ir.CallPartExpr) *types.Type {
|
func PartialCallType(n *ir.CallPartExpr) *types.Type {
|
||||||
t := NewStructType([]*ir.Field{
|
t := types.NewStruct(types.NoPkg, []*types.Field{
|
||||||
ir.NewField(base.Pos, Lookup("F"), nil, types.Types[types.TUINTPTR]),
|
types.NewField(base.Pos, Lookup("F"), types.Types[types.TUINTPTR]),
|
||||||
ir.NewField(base.Pos, Lookup("R"), nil, n.X.Type()),
|
types.NewField(base.Pos, Lookup("R"), n.X.Type()),
|
||||||
})
|
})
|
||||||
t.SetNoalg(true)
|
t.SetNoalg(true)
|
||||||
return t
|
return t
|
||||||
|
@ -428,11 +428,11 @@ func eqFor(t *types.Type) (n ir.Node, needsize bool) {
|
|||||||
sym := reflectdata.TypeSymPrefix(".eq", t)
|
sym := reflectdata.TypeSymPrefix(".eq", t)
|
||||||
n := typecheck.NewName(sym)
|
n := typecheck.NewName(sym)
|
||||||
ir.MarkFunc(n)
|
ir.MarkFunc(n)
|
||||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||||
}, []*ir.Field{
|
}, []*types.Field{
|
||||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TBOOL]),
|
types.NewField(base.Pos, nil, types.Types[types.TBOOL]),
|
||||||
}))
|
}))
|
||||||
return n, false
|
return n, false
|
||||||
}
|
}
|
||||||
|
@ -287,9 +287,9 @@ var scase *types.Type
|
|||||||
// Keep in sync with src/runtime/select.go.
|
// Keep in sync with src/runtime/select.go.
|
||||||
func scasetype() *types.Type {
|
func scasetype() *types.Type {
|
||||||
if scase == nil {
|
if scase == nil {
|
||||||
scase = typecheck.NewStructType([]*ir.Field{
|
scase = types.NewStruct(types.NoPkg, []*types.Field{
|
||||||
ir.NewField(base.Pos, typecheck.Lookup("c"), nil, types.Types[types.TUNSAFEPTR]),
|
types.NewField(base.Pos, typecheck.Lookup("c"), types.Types[types.TUNSAFEPTR]),
|
||||||
ir.NewField(base.Pos, typecheck.Lookup("elem"), nil, types.Types[types.TUNSAFEPTR]),
|
types.NewField(base.Pos, typecheck.Lookup("elem"), types.Types[types.TUNSAFEPTR]),
|
||||||
})
|
})
|
||||||
scase.SetNoalg(true)
|
scase.SetNoalg(true)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user