mirror of
https://github.com/golang/go
synced 2024-11-23 20:30:04 -07:00
cmd/compile/internal/types: change NewTypeParam to match New{Basic,Named}
NewBasic and NewNamed take an Object (i.e., *ir.Name), so that callers don't need to call SetNod. This CL changes NewTypeParam to follow the same convention. Following up on recent Ntype removal, this allows getting rid of Type.SetNod entirely. While here, Type.SetSym is unused too. Change-Id: Ibe0f5747e2ab4a9512b65142b6d3006704b60bd3 Reviewed-on: https://go-review.googlesource.com/c/go/+/405654 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
80f3e3deba
commit
e99275241c
@ -253,11 +253,10 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
|
||||
// this types2-to-types1 translation.
|
||||
return sym.Def.Type()
|
||||
}
|
||||
tp := types.NewTypeParam(sym, typ.Index())
|
||||
nname := ir.NewDeclNameAt(g.pos(typ.Obj().Pos()), ir.OTYPE, sym)
|
||||
sym.Def = nname
|
||||
nname.SetType(tp)
|
||||
tp.SetNod(nname)
|
||||
obj := ir.NewDeclNameAt(g.pos(typ.Obj().Pos()), ir.OTYPE, sym)
|
||||
sym.Def = obj
|
||||
tp := types.NewTypeParam(obj, typ.Index())
|
||||
obj.SetType(tp)
|
||||
// Set g.typs[typ] in case the bound methods reference typ.
|
||||
g.typs[typ] = tp
|
||||
|
||||
|
@ -420,14 +420,11 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
|
||||
// this types2-to-types1 translation.
|
||||
return sym.Def.(*ir.Name)
|
||||
}
|
||||
n := importsym(pos, sym, ir.OTYPE, ir.PTYPEPARAM)
|
||||
// The typeparam index is set at the point where the containing type
|
||||
// param list is imported.
|
||||
t := types.NewTypeParam(sym, 0)
|
||||
// Nname needed to save the pos.
|
||||
nname := ir.NewDeclNameAt(pos, ir.OTYPE, sym)
|
||||
sym.Def = nname
|
||||
nname.SetType(t)
|
||||
t.SetNod(nname)
|
||||
t := types.NewTypeParam(n, 0)
|
||||
n.SetType(t)
|
||||
implicit := false
|
||||
if r.p.exportVersion >= iexportVersionGo1_18 {
|
||||
implicit = r.bool()
|
||||
@ -437,7 +434,7 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
|
||||
bound.MarkImplicit()
|
||||
}
|
||||
t.SetBound(bound)
|
||||
return nname
|
||||
return n
|
||||
|
||||
case 'V':
|
||||
typ := r.typ()
|
||||
|
@ -239,7 +239,6 @@ func (t *Type) Kind() Kind { return t.kind }
|
||||
|
||||
// Sym returns the name of type t.
|
||||
func (t *Type) Sym() *Sym { return t.sym }
|
||||
func (t *Type) SetSym(sym *Sym) { t.sym = sym }
|
||||
|
||||
// OrigType returns the original generic type that t is an
|
||||
// instantiation of, if any.
|
||||
@ -249,15 +248,6 @@ func (t *Type) SetOrigType(orig *Type) { t.origType = orig }
|
||||
// Underlying returns the underlying type of type t.
|
||||
func (t *Type) Underlying() *Type { return t.underlying }
|
||||
|
||||
// SetNod associates t with syntax node n.
|
||||
func (t *Type) SetNod(n Object) {
|
||||
// t.nod can be non-nil already
|
||||
// in the case of shared *Types, like []byte or interface{}.
|
||||
if t.nod == nil {
|
||||
t.nod = n
|
||||
}
|
||||
}
|
||||
|
||||
// Pos returns a position associated with t, if any.
|
||||
// This should only be used for diagnostics.
|
||||
func (t *Type) Pos() src.XPos {
|
||||
@ -1853,9 +1843,10 @@ func NewInterface(pkg *Pkg, methods []*Field, implicit bool) *Type {
|
||||
|
||||
// NewTypeParam returns a new type param with the specified sym (package and name)
|
||||
// and specified index within the typeparam list.
|
||||
func NewTypeParam(sym *Sym, index int) *Type {
|
||||
func NewTypeParam(obj Object, index int) *Type {
|
||||
t := newType(TTYPEPARAM)
|
||||
t.sym = sym
|
||||
t.sym = obj.Sym()
|
||||
t.nod = obj
|
||||
t.extra.(*Typeparam).index = index
|
||||
t.SetHasTParam(true)
|
||||
return t
|
||||
|
Loading…
Reference in New Issue
Block a user