cmd/compile: use Type.OrigSym getter/setters [generated]

Automated CL to rewrite existing code to use OrigSym getters and
setters. Afterwards, we also unexported OrigSym, and then rename the
getter to OrigSym.

[git-generate]
cd src/cmd/compile/internal

: Workaround rf issue with types2 tests.
rm types2/*_test.go

rf '
ex ./noder ./typecheck {
import "cmd/compile/internal/types"
var s *types.Sym
var t *types.Type

t.OrigSym = s -> t.SetOrigSym(s)
t.OrigSym     -> t.OrigSym_()
}
'

cd types
rf '
mv Type.OrigSym Type.origSym
mv Type.OrigSym_ Type.OrigSym
'

: Revert types2 hack.
cd ../types2
git checkout HEAD^ .

Change-Id: I8eb17098613b1575df56b8189b1615823071d3d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/345485
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Matthew Dempsky 2021-08-26 17:48:12 -07:00
parent 68ecdc2c70
commit 82efc05403
8 changed files with 21 additions and 21 deletions

View file

@ -102,11 +102,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 typ.OrigSym() != 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 = typ.OrigSym().Def.Type()
}
meth := typecheck.Lookdot1(fn, typecheck.Lookup(decl.Name.Value), typ, typ.Methods(), 0)
meth.SetNointerface(true)

View file

@ -151,7 +151,7 @@ func (g *irgen) stencil() {
targs := deref(meth.Type().Recv().Type).RParams()
t := meth.X.Type()
baseSym := deref(t).OrigSym
baseSym := deref(t).OrigSym()
baseType := baseSym.Def.(*ir.Name).Type()
var gf *ir.Name
for _, m := range baseType.Methods().Slice() {
@ -309,7 +309,7 @@ func (g *irgen) 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.OrigSym().Def.Type()
var gf *ir.Name
for _, m := range baseType.Methods().Slice() {
if se.Sel == m.Sym {
@ -493,7 +493,7 @@ func (g *irgen) 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
baseSym := typ.OrigSym()
baseType := baseSym.Def.(*ir.Name).Type()
for j, _ := range typ.Methods().Slice() {
if baseType.Methods().Slice()[j].Nointerface() {
@ -1465,7 +1465,7 @@ func (g *irgen) 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.OrigSym().Def.Type()
nameNode = typecheck.Lookdot1(call.X, se.Sel, genRecvType, genRecvType.Methods(), 1).Nname.(*ir.Name)
sym = g.getDictionarySym(nameNode, targs, true)
} else {

View file

@ -162,7 +162,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.OrigSym = g.pkg(typ.Obj().Pkg()).Lookup(typ.Obj().Name())
ntyp.SetOrigSym(g.pkg(typ.Obj().Pkg()).Lookup(typ.Obj().Name()))
ntyp.SetUnderlying(g.typ1(typ.Underlying()))
if typ.NumMethods() != 0 {
// Save a delayed call to g.fillinMethods() (once

View file

@ -222,9 +222,9 @@ func (p *crawler) markInlBody(n *ir.Name) {
// for export), so its methods will be available for inlining if needed.
func (p *crawler) checkGenericType(t *types.Type) {
if t != nil && t.HasTParam() {
if t.OrigSym != nil {
if t.OrigSym() != nil {
// Convert to the base generic type.
t = t.OrigSym.Def.Type()
t = t.OrigSym().Def.Type()
}
p.markType(t)
}

View file

@ -878,7 +878,7 @@ func (w *exportWriter) startType(k itag) {
func (w *exportWriter) doTyp(t *types.Type) {
s := t.Sym()
if s != nil && t.OrigSym != nil {
if s != nil && t.OrigSym() != nil {
assert(base.Flag.G > 0)
// This is an instantiated type - could be a re-instantiation like
// Value[T2] or a full instantiation like Value[int].
@ -895,7 +895,7 @@ func (w *exportWriter) doTyp(t *types.Type) {
// types or existing typeparams from the function/method header.
w.typeList(t.RParams())
// Export a reference to the base type.
baseType := t.OrigSym.Def.(*ir.Name).Type()
baseType := t.OrigSym().Def.(*ir.Name).Type()
w.typ(baseType)
return
}

View file

@ -714,7 +714,7 @@ func (p *iimporter) typAt(off uint64) *types.Type {
// No need to calc sizes for re-instantiated generic types, and
// they are not necessarily resolved until the top-level type is
// defined (because of recursive types).
if t.OrigSym == nil || !t.HasTParam() {
if t.OrigSym() == nil || !t.HasTParam() {
types.CheckSize(t)
}
p.typCache[off] = t
@ -1395,7 +1395,7 @@ func (r *importReader) node() ir.Node {
} else {
genType := types.ReceiverBaseType(n1.X.Type())
if genType.IsInstantiatedGeneric() {
genType = genType.OrigSym.Def.Type()
genType = genType.OrigSym().Def.Type()
}
m = Lookdot1(n1, sel, genType, genType.Methods(), 1)
}
@ -1778,7 +1778,7 @@ func Instantiate(pos src.XPos, baseType *types.Type, targs []*types.Type) *types
t := NewIncompleteNamedType(baseType.Pos(), instSym)
t.SetRParams(targs)
t.OrigSym = baseSym
t.SetOrigSym(baseSym)
// baseType may still be TFORW or its methods may not be fully filled in
// (since we are in the middle of importing it). So, delay call to
@ -1803,7 +1803,7 @@ func resumeDoInst() {
for len(deferredInstStack) > 0 {
t := deferredInstStack[0]
deferredInstStack = deferredInstStack[1:]
substInstType(t, t.OrigSym.Def.(*ir.Name).Type(), t.RParams())
substInstType(t, t.OrigSym().Def.(*ir.Name).Type(), t.RParams())
}
}
deferInst--
@ -1814,7 +1814,7 @@ func resumeDoInst() {
// during a type substitution for an instantiation. This is needed for
// instantiations of mutually recursive types.
func doInst(t *types.Type) *types.Type {
return Instantiate(t.Pos(), t.OrigSym.Def.(*ir.Name).Type(), t.RParams())
return Instantiate(t.Pos(), t.OrigSym().Def.(*ir.Name).Type(), t.RParams())
}
// substInstType completes the instantiation of a generic type by doing a

View file

@ -1081,8 +1081,8 @@ func (ts *Tsubster) typ1(t *types.Type) *types.Type {
forw.SetRParams(neededTargs)
// Copy the OrigSym from the re-instantiated type (which is the sym of
// the base generic type).
assert(t.OrigSym != nil)
forw.OrigSym = t.OrigSym
assert(t.OrigSym() != nil)
forw.SetOrigSym(t.OrigSym())
}
var newt *types.Type

View file

@ -198,7 +198,7 @@ type Type struct {
// For an instantiated generic type, the symbol for the base generic type.
// This backpointer is useful, because the base type is the type that has
// the method bodies.
OrigSym *Sym
origSym *Sym
}
func (*Type) CanBeAnSSAAux() {}
@ -245,8 +245,8 @@ func (t *Type) SetSym(sym *Sym) { t.sym = sym }
// OrigSym returns the name of the original generic type that t is an
// instantiation of, if any.
func (t *Type) OrigSym_() *Sym { return t.OrigSym }
func (t *Type) SetOrigSym(sym *Sym) { t.OrigSym = sym }
func (t *Type) OrigSym() *Sym { return t.origSym }
func (t *Type) SetOrigSym(sym *Sym) { t.origSym = sym }
// Underlying returns the underlying type of type t.
func (t *Type) Underlying() *Type { return t.underlying }