]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: simplify ir.Func somewhat
authorMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 11:08:23 +0000 (03:08 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 29 Dec 2020 11:54:34 +0000 (11:54 +0000)
Two simplifications:

1. Statements (including ODCLFUNC) don't have types, and the
Func.Nname already has a type. There's no need for a second one.
However, there is a lot of code that expects to be able to call
Func.Type, so leave a forwarding method, like with Sym and Linksym.

2. Inline and remove ir.NewFuncNameAt. It doesn't really save any
code, and it's only used a handful of places.

Passes toolstash -cmp.

Change-Id: I51acaa341897dae0fcdf2fa576a10174a2ae4d1e
Reviewed-on: https://go-review.googlesource.com/c/go/+/280648
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/func.go
src/cmd/compile/internal/ir/sizeof_test.go
src/cmd/compile/internal/noder/noder.go
src/cmd/compile/internal/typecheck/dcl.go
src/cmd/compile/internal/typecheck/export.go
src/cmd/compile/internal/typecheck/func.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/walk/closure.go

index 4613425f1a3404edd14ee7712b5fd3664d8b3f67..bffd4dd5ef9b25ac181a3c181cf220de29825a16 100644 (file)
@@ -49,7 +49,6 @@ import (
 // pointer from the Func back to the OCALLPART.
 type Func struct {
        miniNode
-       typ  *types.Type
        Body Nodes
        Iota int64
 
@@ -116,9 +115,7 @@ func NewFunc(pos src.XPos) *Func {
 
 func (f *Func) isStmt() {}
 
-func (f *Func) Type() *types.Type     { return f.typ }
-func (f *Func) SetType(x *types.Type) { f.typ = x }
-
+func (f *Func) Type() *types.Type  { return f.Nname.Type() }
 func (f *Func) Sym() *types.Sym    { return f.Nname.Sym() }
 func (f *Func) Linksym() *obj.LSym { return f.Nname.Linksym() }
 
@@ -236,17 +233,6 @@ func FuncSymName(s *types.Sym) string {
        return s.Name + "·f"
 }
 
-// NewFuncNameAt generates a new name node for a function or method.
-func NewFuncNameAt(pos src.XPos, s *types.Sym, fn *Func) *Name {
-       if fn.Nname != nil {
-               base.Fatalf("newFuncName - already have name")
-       }
-       n := NewNameAt(pos, s)
-       n.SetFunc(fn)
-       fn.Nname = n
-       return n
-}
-
 // MarkFunc marks a node as a function.
 func MarkFunc(n *Name) {
        if n.Op() != ONAME || n.Class_ != Pxxx {
index 2a618f85ed4ea03566a5a0b05cfbf2d65f5d3001..61f207af2048e68b66425cbe4fcc01bccf8995d0 100644 (file)
@@ -20,7 +20,7 @@ func TestSizeof(t *testing.T) {
                _32bit uintptr     // size on 32bit platforms
                _64bit uintptr     // size on 64bit platforms
        }{
-               {Func{}, 200, 352},
+               {Func{}, 196, 344},
                {Name{}, 132, 232},
        }
 
index 920f4839adfcc3642604496144edd69558078a38..f4b5e0cf91d408cadc0ecb372c6e6de41138ea15 100644 (file)
@@ -524,7 +524,8 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) ir.Node {
                name = ir.BlankNode.Sym() // filled in by typecheckfunc
        }
 
-       f.Nname = ir.NewFuncNameAt(p.pos(fun.Name), name, f)
+       f.Nname = ir.NewNameAt(p.pos(fun.Name), name)
+       f.Nname.Func = f
        f.Nname.Defn = f
        f.Nname.Ntype = t
 
@@ -1742,7 +1743,9 @@ func (p *noder) funcLit(expr *syntax.FuncLit) ir.Node {
 
        fn := ir.NewFunc(p.pos(expr))
        fn.SetIsHiddenClosure(ir.CurFunc != nil)
-       fn.Nname = ir.NewFuncNameAt(p.pos(expr), ir.BlankNode.Sym(), fn) // filled in by typecheckclosure
+
+       fn.Nname = ir.NewNameAt(p.pos(expr), ir.BlankNode.Sym()) // filled in by typecheckclosure
+       fn.Nname.Func = fn
        fn.Nname.Ntype = xtype
        fn.Nname.Defn = fn
 
index 83f926e135e8ab775ea5bb31b0a0b5724b2c4ecb..c4f32ff59dbad196523094621628f14903d65115 100644 (file)
@@ -23,7 +23,8 @@ func DeclFunc(sym *types.Sym, tfn ir.Ntype) *ir.Func {
        }
 
        fn := ir.NewFunc(base.Pos)
-       fn.Nname = ir.NewFuncNameAt(base.Pos, sym, fn)
+       fn.Nname = ir.NewNameAt(base.Pos, sym)
+       fn.Nname.Func = fn
        fn.Nname.Defn = fn
        fn.Nname.Ntype = tfn
        ir.MarkFunc(fn.Nname)
index 03deff8174ae3f96d5d48f74288bcd616af191b2..c5253914012c6ac8b43a5bc94ec7d8dc22291b45 100644 (file)
@@ -31,12 +31,8 @@ func importconst(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type, val
 // ipkg is the package being imported
 func importfunc(ipkg *types.Pkg, pos src.XPos, s *types.Sym, t *types.Type) *ir.Name {
        n := importobj(ipkg, pos, s, ir.ONAME, ir.PFUNC, t)
-
-       fn := ir.NewFunc(pos)
-       fn.SetType(t)
-       n.SetFunc(fn)
-       fn.Nname = n
-
+       n.Func = ir.NewFunc(pos)
+       n.Func.Nname = n
        return n
 }
 
index 9bb9245d4a4437de3905e5d7cf163fa0847dc3d8..060024951e0956d6a9fc437f9ef5376c70762b16 100644 (file)
@@ -409,7 +409,6 @@ func tcFunc(n *ir.Func) {
        if t == nil {
                return
        }
-       n.SetType(t)
        rcvr := t.Recv()
        if rcvr != nil && n.Shortname != nil {
                m := addmethod(n, n.Shortname, t, true, n.Pragma&ir.Nointerface != 0)
index 86277e69bd4cc9a4193f4777787284fac1b5d735..00ecd9b8190297e03d026c14eebc1d718231f53e 100644 (file)
@@ -331,12 +331,13 @@ func (r *importReader) doDecl(sym *types.Sym) *ir.Name {
                        recv := r.param()
                        mtyp := r.signature(recv)
 
-                       fn := ir.NewFunc(mpos)
-                       fn.SetType(mtyp)
-                       m := ir.NewFuncNameAt(mpos, ir.MethodSym(recv.Type, msym), fn)
-                       m.SetType(mtyp)
-                       m.Class_ = ir.PFUNC
                        // methodSym already marked m.Sym as a function.
+                       m := ir.NewNameAt(mpos, ir.MethodSym(recv.Type, msym))
+                       m.Class_ = ir.PFUNC
+                       m.SetType(mtyp)
+
+                       m.Func = ir.NewFunc(mpos)
+                       m.Func.Nname = m
 
                        f := types.NewField(mpos, msym, mtyp)
                        f.Nname = m
index 9bcb82bc036693164ce49d2ef184b04f088a3aed..00d3f50bc4c75c3cdf04b5a82f68cf335f49ff04 100644 (file)
@@ -67,7 +67,7 @@ func Closure(fn *ir.Func) {
                }
 
                types.CalcSize(f.Type())
-               fn.SetType(f.Type()) // update type of ODCLFUNC
+               fn.Nname.SetType(f.Type()) // update type of ODCLFUNC
        } else {
                // The closure is not called, so it is going to stay as closure.
                var body []ir.Node