]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use Type.OrigSym getter/setters [generated]
authorMatthew Dempsky <mdempsky@google.com>
Fri, 27 Aug 2021 00:48:12 +0000 (17:48 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 27 Aug 2021 21:27:59 +0000 (21:27 +0000)
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>
src/cmd/compile/internal/noder/decl.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/typecheck/crawler.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/subr.go
src/cmd/compile/internal/types/type.go

index 54a13b498b959c7eaf211d38954efdfeb14c8084..87a8667003f27c8d941b3060af5c2dd596912d22 100644 (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)
index 7b85a8883089517a4d2d54f818c0f53ba3dcf0b4..00c467653099906ba3396d1a73930aaaeaf7737b 100644 (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 {
index e00a3a5da91d3da4ac060fb799ddbd69a472dc9e..c549dffc461bf11064cbdbaa8ed9bcc9978911be 100644 (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
index 9a348b9f37401dc28a557192486eaa5893390dbf..9e523c3d142112dddaa0aba10c9633fd4f336de1 100644 (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)
        }
index 82006c324566c9bc381df8307dd1bd1f5aab2464..dbdf8eda358e9888ac2c82ad4c9055bc6e4fe8ce 100644 (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
        }
index 87ad5d1c54bc552ac2859366c2bd0fdf2f796580..0dfc33db201e96dd5e03ece02f5092de9006c727 100644 (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
index 73f83f65e401d03c07ef788fac98bdfe08895421..3ec2cc5d5625d1139adbf2b8b3afbc1fe9d4574e 100644 (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
index c7c8a53654610f097c5bb21126a0e99f5b201ba1..6f4bd0c114c5ce8a59b71a7215b394e05bcb2d30 100644 (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 }