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

View file

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