From: Matthew Dempsky Date: Tue, 10 May 2022 23:06:16 +0000 (-0700) Subject: cmd/compile/internal/types: change NewTypeParam to match New{Basic,Named} X-Git-Tag: go1.19beta1~247 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e99275241c4e4bde6ff2a8598e558a2bea151ef7;p=gostls13.git 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 Reviewed-by: Cuong Manh Le Reviewed-by: David Chase TryBot-Result: Gopher Robot --- diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go index ff3a4d982d..57b35e602b 100644 --- a/src/cmd/compile/internal/noder/types.go +++ b/src/cmd/compile/internal/noder/types.go @@ -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 diff --git a/src/cmd/compile/internal/typecheck/iimport.go b/src/cmd/compile/internal/typecheck/iimport.go index 851b1ead63..c6d3fc4c6e 100644 --- a/src/cmd/compile/internal/typecheck/iimport.go +++ b/src/cmd/compile/internal/typecheck/iimport.go @@ -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() diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index c8fe31e718..77aae3c4ac 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -238,8 +238,7 @@ func (t *Type) SetHasShape(b bool) { t.flags.set(typeHasShape, b) } 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 } +func (t *Type) Sym() *Sym { return t.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