mirror of
https://github.com/golang/go
synced 2024-11-11 18:21:40 -07: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)
|
||||
ir.MarkFunc(n)
|
||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
||||
}, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
||||
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||
}, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||
}))
|
||||
return n
|
||||
}
|
||||
@ -777,12 +777,12 @@ func hashmem(t *types.Type) ir.Node {
|
||||
|
||||
n := typecheck.NewName(sym)
|
||||
ir.MarkFunc(n)
|
||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
||||
}, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TUINTPTR]),
|
||||
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||
}, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.Types[types.TUINTPTR]),
|
||||
}))
|
||||
return n
|
||||
}
|
||||
|
@ -1419,7 +1419,11 @@ func WriteBasicTypes() {
|
||||
// The latter is the type of an auto-generated wrapper.
|
||||
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.
|
||||
dimportpath(ir.Pkgs.Runtime)
|
||||
|
@ -676,30 +676,26 @@ func autotmpname(n int) string {
|
||||
|
||||
// f is method type, with receiver.
|
||||
// return function type, receiver as first argument (or not).
|
||||
func NewMethodType(f *types.Type, receiver *types.Type) *types.Type {
|
||||
inLen := f.Params().Fields().Len()
|
||||
if receiver != nil {
|
||||
inLen++
|
||||
}
|
||||
in := make([]*ir.Field, 0, inLen)
|
||||
|
||||
if receiver != nil {
|
||||
d := ir.NewField(base.Pos, nil, nil, receiver)
|
||||
in = append(in, d)
|
||||
func NewMethodType(sig *types.Type, recv *types.Type) *types.Type {
|
||||
nrecvs := 0
|
||||
if recv != nil {
|
||||
nrecvs++
|
||||
}
|
||||
|
||||
for _, t := range f.Params().Fields().Slice() {
|
||||
d := ir.NewField(base.Pos, nil, nil, t.Type)
|
||||
d.IsDDD = t.IsDDD()
|
||||
in = append(in, d)
|
||||
params := make([]*types.Field, nrecvs+sig.Params().Fields().Len())
|
||||
if recv != nil {
|
||||
params[0] = types.NewField(base.Pos, nil, recv)
|
||||
}
|
||||
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()
|
||||
out := make([]*ir.Field, 0, outLen)
|
||||
for _, t := range f.Results().Fields().Slice() {
|
||||
d := ir.NewField(base.Pos, nil, nil, t.Type)
|
||||
out = append(out, d)
|
||||
results := make([]*types.Field, sig.Results().Fields().Len())
|
||||
for i, t := range sig.Results().Fields().Slice() {
|
||||
results[i] = types.NewField(base.Pos, nil, t.Type)
|
||||
}
|
||||
|
||||
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 struct is unnamed so that closures in multiple packages with the
|
||||
// same struct type can share the descriptor.
|
||||
fields := []*ir.Field{
|
||||
ir.NewField(base.Pos, Lookup(".F"), nil, types.Types[types.TUINTPTR]),
|
||||
fields := []*types.Field{
|
||||
types.NewField(base.Pos, Lookup(".F"), types.Types[types.TUINTPTR]),
|
||||
}
|
||||
for _, v := range clo.Func.ClosureVars {
|
||||
typ := v.Type()
|
||||
if !v.Byval() {
|
||||
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)
|
||||
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).
|
||||
// The address of a variable of the returned type can be cast to a func.
|
||||
func PartialCallType(n *ir.CallPartExpr) *types.Type {
|
||||
t := NewStructType([]*ir.Field{
|
||||
ir.NewField(base.Pos, Lookup("F"), nil, types.Types[types.TUINTPTR]),
|
||||
ir.NewField(base.Pos, Lookup("R"), nil, n.X.Type()),
|
||||
t := types.NewStruct(types.NoPkg, []*types.Field{
|
||||
types.NewField(base.Pos, Lookup("F"), types.Types[types.TUINTPTR]),
|
||||
types.NewField(base.Pos, Lookup("R"), n.X.Type()),
|
||||
})
|
||||
t.SetNoalg(true)
|
||||
return t
|
||||
|
@ -428,11 +428,11 @@ func eqFor(t *types.Type) (n ir.Node, needsize bool) {
|
||||
sym := reflectdata.TypeSymPrefix(".eq", t)
|
||||
n := typecheck.NewName(sym)
|
||||
ir.MarkFunc(n)
|
||||
n.SetType(typecheck.NewFuncType(nil, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
||||
ir.NewField(base.Pos, nil, nil, types.NewPtr(t)),
|
||||
}, []*ir.Field{
|
||||
ir.NewField(base.Pos, nil, nil, types.Types[types.TBOOL]),
|
||||
n.SetType(types.NewSignature(types.NoPkg, nil, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||
types.NewField(base.Pos, nil, types.NewPtr(t)),
|
||||
}, []*types.Field{
|
||||
types.NewField(base.Pos, nil, types.Types[types.TBOOL]),
|
||||
}))
|
||||
return n, false
|
||||
}
|
||||
|
@ -287,9 +287,9 @@ var scase *types.Type
|
||||
// Keep in sync with src/runtime/select.go.
|
||||
func scasetype() *types.Type {
|
||||
if scase == nil {
|
||||
scase = typecheck.NewStructType([]*ir.Field{
|
||||
ir.NewField(base.Pos, typecheck.Lookup("c"), nil, types.Types[types.TUNSAFEPTR]),
|
||||
ir.NewField(base.Pos, typecheck.Lookup("elem"), nil, types.Types[types.TUNSAFEPTR]),
|
||||
scase = types.NewStruct(types.NoPkg, []*types.Field{
|
||||
types.NewField(base.Pos, typecheck.Lookup("c"), types.Types[types.TUNSAFEPTR]),
|
||||
types.NewField(base.Pos, typecheck.Lookup("elem"), types.Types[types.TUNSAFEPTR]),
|
||||
})
|
||||
scase.SetNoalg(true)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user