aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2022-03-21 10:06:48 -0700
committerMatthew Dempsky <mdempsky@google.com>2022-03-21 21:57:24 +0000
commitadae6ec542c3287ffe643093a0f61c9871f4e238 (patch)
treea6feb8519edb0d0558d70b3c21b9e2854dbd363a /src/cmd/compile/internal/noder
parent29866aa2b6a6a48672a386d05b53779e768c13d6 (diff)
downloadgo-adae6ec542c3287ffe643093a0f61c9871f4e238.tar.xz
cmd/compile: replace Type.OrigSym with Type.OrigType
First law of cmd/compile frontend development: thou shalt not rely on types.Sym. This CL replaces Type.OrigSym with Type.OrigType, which semantically matches what all of the uses within the frontend actually care about, and avoids using types.Sym, which invariably leads to mistakes because symbol scoping in the frontend doesn't work how anyone intuitively expects it to. Fixes #51765. Change-Id: I4affe6ee0718103ce5006ab68aa7e1bb0cac6881 Reviewed-on: https://go-review.googlesource.com/c/go/+/394274 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder')
-rw-r--r--src/cmd/compile/internal/noder/decl.go4
-rw-r--r--src/cmd/compile/internal/noder/stencil.go14
-rw-r--r--src/cmd/compile/internal/noder/types.go2
3 files changed, 9 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index a9522d09af..f985648c66 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -114,11 +114,11 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
// the Fields to represent the receiver's method set.
if recv := fn.Type().Recv(); recv != nil {
typ := types.ReceiverBaseType(recv.Type)
- if typ.OrigSym() != nil {
+ if orig := typ.OrigType(); orig != nil {
// For a generic method, we mark the methods on the
// base generic type, since those are the methods
// that will be stenciled.
- typ = typ.OrigSym().Def.Type()
+ typ = orig
}
meth := typecheck.Lookdot1(fn, typecheck.Lookup(decl.Name.Value), typ, typ.Methods(), 0)
meth.SetNointerface(true)
diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go
index c78a169d31..4ba69469a6 100644
--- a/src/cmd/compile/internal/noder/stencil.go
+++ b/src/cmd/compile/internal/noder/stencil.go
@@ -193,8 +193,7 @@ func (g *genInst) scanForGenCalls(decl ir.Node) {
targs := deref(meth.Type().Recv().Type).RParams()
t := meth.X.Type()
- baseSym := deref(t).OrigSym()
- baseType := baseSym.Def.(*ir.Name).Type()
+ baseType := deref(t).OrigType()
var gf *ir.Name
for _, m := range baseType.Methods().Slice() {
if meth.Sel == m.Sym {
@@ -348,7 +347,7 @@ func (g *genInst) buildClosure(outer *ir.Func, x ir.Node) ir.Node {
// actually generic, so no need to build a closure.
return x
}
- baseType := recv.OrigSym().Def.Type()
+ baseType := recv.OrigType()
var gf *ir.Name
for _, m := range baseType.Methods().Slice() {
if se.Sel == m.Sym {
@@ -543,8 +542,7 @@ func (g *genInst) instantiateMethods() {
typecheck.NeedRuntimeType(typ)
// Lookup the method on the base generic type, since methods may
// not be set on imported instantiated types.
- baseSym := typ.OrigSym()
- baseType := baseSym.Def.(*ir.Name).Type()
+ baseType := typ.OrigType()
for j, _ := range typ.Methods().Slice() {
if baseType.Methods().Slice()[j].Nointerface() {
typ.Methods().Slice()[j].SetNointerface(true)
@@ -644,7 +642,7 @@ func (g *genInst) getInstantiation(nameNode *ir.Name, shapes []*types.Type, isMe
if recvType.IsFullyInstantiated() {
// Get the type of the base generic type, so we get
// its original typeparams.
- recvType = recvType.OrigSym().Def.(*ir.Name).Type()
+ recvType = recvType.OrigType()
}
tparams = recvType.RParams()
} else {
@@ -1628,7 +1626,7 @@ func (g *genInst) getDictionarySym(gf *ir.Name, targs []*types.Type, isMeth bool
// instantiated type, so we need a
// sub-dictionary.
targs := recvType.RParams()
- genRecvType := recvType.OrigSym().Def.Type()
+ genRecvType := recvType.OrigType()
nameNode = typecheck.Lookdot1(call.X, se.Sel, genRecvType, genRecvType.Methods(), 1).Nname.(*ir.Name)
sym = g.getDictionarySym(nameNode, targs, true)
} else {
@@ -1707,7 +1705,7 @@ func (g *genInst) getSymForMethodCall(se *ir.SelectorExpr, subst *typecheck.Tsub
// also give the receiver type. For method expressions with embedded types, we
// need to look at the type of the selection to get the final receiver type.
recvType := deref(se.Selection.Type.Recv().Type)
- genRecvType := recvType.OrigSym().Def.Type()
+ genRecvType := recvType.OrigType()
nameNode := typecheck.Lookdot1(se, se.Sel, genRecvType, genRecvType.Methods(), 1).Nname.(*ir.Name)
subtargs := recvType.RParams()
s2targs := make([]*types.Type, len(subtargs))
diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go
index e7ce4c1089..ff3a4d982d 100644
--- a/src/cmd/compile/internal/noder/types.go
+++ b/src/cmd/compile/internal/noder/types.go
@@ -166,7 +166,7 @@ func (g *irgen) typ0(typ types2.Type) *types.Type {
//fmt.Printf("Saw new type %v %v\n", instName, ntyp.HasTParam())
// Save the symbol for the base generic type.
- ntyp.SetOrigSym(g.pkg(typ.Obj().Pkg()).Lookup(typ.Obj().Name()))
+ ntyp.SetOrigType(base.Type())
ntyp.SetUnderlying(g.typ1(typ.Underlying()))
if typ.NumMethods() != 0 {
// Save a delayed call to g.fillinMethods() (once