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

[dev.typeparams] cmd/compile: simplify tparam's type

We just need the type of the param, no need for a full Field.

Change-Id: I851ff2628e1323d971e58d0cabbdfd93c63e1d3c
Reviewed-on: https://go-review.googlesource.com/c/go/+/321229
Trust: Keith Randall <khr@golang.org>
Trust: Dan Scales <danscales@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Dan Scales <danscales@google.com>
This commit is contained in:
Keith Randall 2021-05-19 10:04:44 -07:00
parent 701bd60646
commit b69347d24a
2 changed files with 11 additions and 10 deletions

View File

@ -217,7 +217,7 @@ type subster struct {
g *irgen
isMethod bool // If a method is being instantiated
newf *ir.Func // Func node for the new stenciled function
tparams []*types.Field
tparams []*types.Type
targs []*types.Type
// The substitution map from name nodes in the generic function to the
// name nodes in the new stenciled function.
@ -231,18 +231,19 @@ type subster struct {
// instantiated method would still need to be transformed by later compiler
// phases.
func (g *irgen) genericSubst(newsym *types.Sym, nameNode *ir.Name, targs []*types.Type, isMethod bool) *ir.Func {
var tparams []*types.Field
var tparams []*types.Type
if isMethod {
// Get the type params from the method receiver (after skipping
// over any pointer)
recvType := nameNode.Type().Recv().Type
recvType = deref(recvType)
tparams = make([]*types.Field, len(recvType.RParams()))
for i, rparam := range recvType.RParams() {
tparams[i] = types.NewField(src.NoXPos, nil, rparam)
}
tparams = recvType.RParams()
} else {
tparams = nameNode.Type().TParams().Fields().Slice()
fields := nameNode.Type().TParams().Fields().Slice()
tparams = make([]*types.Type, len(fields))
for i, f := range fields {
tparams[i] = f.Type
}
}
gf := nameNode.Func
// Pos of the instantiated function is same as the generic function
@ -660,7 +661,7 @@ func (subst *subster) typ(t *types.Type) *types.Type {
if t.Kind() == types.TTYPEPARAM {
for i, tp := range subst.tparams {
if tp.Type == t {
if tp == t {
return subst.targs[i]
}
}

View File

@ -273,9 +273,9 @@ func (g *irgen) fillinMethods(typ *types2.Named, ntyp *types.Type) {
} else {
meth2 = ir.NewNameAt(meth.Pos(), newsym)
rparams := types2.AsSignature(m.Type()).RParams()
tparams := make([]*types.Field, len(rparams))
tparams := make([]*types.Type, len(rparams))
for i, rparam := range rparams {
tparams[i] = types.NewField(src.NoXPos, nil, g.typ1(rparam.Type()))
tparams[i] = g.typ1(rparam.Type())
}
assert(len(tparams) == len(targs))
subst := &subster{