]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove funcdepth variables
authorMatthew Dempsky <mdempsky@google.com>
Wed, 7 Mar 2018 02:30:58 +0000 (18:30 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 7 Mar 2018 06:05:18 +0000 (06:05 +0000)
There were only two large classes of use for these variables:

1) Testing "funcdepth != 0" or "funcdepth > 0", which is equivalent to
checking "Curfn != nil".

2) In oldname, detecting whether a closure variable has been created
for the current function, which can be handled by instead testing
"n.Name.Curfn != Curfn".

Lastly, merge funcstart into funchdr, since it's only called once, and
it better matches up with funcbody now.

Passes toolstash-check.

Change-Id: I8fe159a9d37ef7debc4cd310354cea22a8b23394
Reviewed-on: https://go-review.googlesource.com/99076
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/bimport.go
src/cmd/compile/internal/gc/closure.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/fmt.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/compile/internal/gc/sizeof_test.go
src/cmd/compile/internal/gc/syntax.go
src/cmd/compile/internal/gc/walk.go

index 71d20ec37bd8297c58e488703027a0145ea85f50..68ca0ca949f93360fc5287afe3c179797db28361 100644 (file)
@@ -178,8 +178,8 @@ func Import(imp *types.Pkg, in *bufio.Reader) {
                }
                i0 = i
 
-               if funcdepth != 0 {
-                       p.formatErrorf("unexpected Funcdepth %d", funcdepth)
+               if Curfn != nil {
+                       p.formatErrorf("unexpected Curfn %v", Curfn)
                }
 
                // Note: In the original code, funchdr and funcbody are called for
index 1713b5129c5e8198f9e507e149ae6c441ab083ac..1a79b7b149fac9bfe9387cca7d18dce1641baf65 100644 (file)
@@ -16,7 +16,6 @@ func (p *noder) funcLit(expr *syntax.FuncLit) *Node {
        n := p.nod(expr, OCLOSURE, nil, nil)
        n.Func.SetIsHiddenClosure(Curfn != nil)
        n.Func.Ntype = ntype
-       n.Func.Depth = funcdepth
        n.Func.Outerfunc = Curfn
 
        old := p.funchdr(n)
@@ -220,8 +219,6 @@ func makeclosure(func_ *Node) *Node {
        xfunc.Func.Nname.Name.Param.Ntype = xtype
        xfunc.Func.Nname.Name.Defn = xfunc
        declare(xfunc.Func.Nname, PFUNC)
-       xfunc.Func.Nname.Name.Funcdepth = func_.Func.Depth
-       xfunc.Func.Depth = func_.Func.Depth
        xfunc.Func.Endlineno = func_.Func.Endlineno
        if Ctxt.Flag_dynlink {
                makefuncsym(xfunc.Func.Nname.Sym)
index 5d1efaadafaf26afd8c4be65a8dd0ad359ea206f..ce1033cf258c08dcdf4877d680bde8449ffa956e 100644 (file)
@@ -128,7 +128,6 @@ func declare(n *Node, ctxt Class) {
        s.Lastlineno = lineno
        s.Def = asTypesNode(n)
        n.Name.Vargen = int32(gen)
-       n.Name.Funcdepth = funcdepth
        n.SetClass(ctxt)
 
        autoexport(n, ctxt)
@@ -160,7 +159,7 @@ func variter(vl []*Node, t *Node, el []*Node) []*Node {
                        declare(v, dclcontext)
                        v.Name.Param.Ntype = t
                        v.Name.Defn = as2
-                       if funcdepth > 0 {
+                       if Curfn != nil {
                                init = append(init, nod(ODCL, v, nil))
                        }
                }
@@ -183,8 +182,8 @@ func variter(vl []*Node, t *Node, el []*Node) []*Node {
                declare(v, dclcontext)
                v.Name.Param.Ntype = t
 
-               if e != nil || funcdepth > 0 || isblank(v) {
-                       if funcdepth > 0 {
+               if e != nil || Curfn != nil || isblank(v) {
+                       if Curfn != nil {
                                init = append(init, nod(ODCL, v, nil))
                        }
                        e = nod(OAS, v, e)
@@ -276,7 +275,7 @@ func oldname(s *types.Sym) *Node {
                return newnoname(s)
        }
 
-       if Curfn != nil && n.Op == ONAME && n.Name.Funcdepth > 0 && n.Name.Funcdepth != funcdepth {
+       if Curfn != nil && n.Op == ONAME && n.Name.Curfn != nil && n.Name.Curfn != Curfn {
                // Inner func is referring to var in outer func.
                //
                // TODO(rsc): If there is an outer variable x and we
@@ -284,7 +283,7 @@ func oldname(s *types.Sym) *Node {
                // the := it looks like a reference to the outer x so we'll
                // make x a closure variable unnecessarily.
                c := n.Name.Param.Innermost
-               if c == nil || c.Name.Funcdepth != funcdepth {
+               if c == nil || c.Name.Curfn != Curfn {
                        // Do not have a closure var for the active closure yet; make one.
                        c = newname(s)
                        c.SetClass(PAUTOHEAP)
@@ -292,7 +291,6 @@ func oldname(s *types.Sym) *Node {
                        c.SetIsddd(n.Isddd())
                        c.Name.Defn = n
                        c.SetAddable(false)
-                       c.Name.Funcdepth = funcdepth
 
                        // Link into list of active closure variables.
                        // Popped from list in func closurebody.
@@ -384,12 +382,14 @@ func ifacedcl(n *Node) {
 // returns in auto-declaration context.
 func funchdr(n *Node) {
        // change the declaration context from extern to auto
-       if funcdepth == 0 && dclcontext != PEXTERN {
+       if Curfn == nil && dclcontext != PEXTERN {
                Fatalf("funchdr: dclcontext = %d", dclcontext)
        }
 
        dclcontext = PAUTO
-       funcstart(n)
+       types.Markdcl()
+       funcstack = append(funcstack, Curfn)
+       Curfn = n
 
        if n.Func.Nname != nil {
                funcargs(n.Func.Nname.Name.Param.Ntype)
@@ -523,16 +523,6 @@ func funcargs2(t *types.Type) {
 }
 
 var funcstack []*Node // stack of previous values of Curfn
-var funcdepth int32   // len(funcstack) during parsing, but then forced to be the same later during compilation
-
-// start the function.
-// called before funcargs; undone at end of funcbody.
-func funcstart(n *Node) {
-       types.Markdcl()
-       funcstack = append(funcstack, Curfn)
-       funcdepth++
-       Curfn = n
-}
 
 // finish the body.
 // called in auto-declaration context.
@@ -544,8 +534,7 @@ func funcbody() {
        }
        types.Popdcl()
        funcstack, Curfn = funcstack[:len(funcstack)-1], funcstack[len(funcstack)-1]
-       funcdepth--
-       if funcdepth == 0 {
+       if Curfn == nil {
                dclcontext = PEXTERN
        }
 }
index 2cebab28dd5e3933182a47d0d545f9db4d36498d..aa7e23049636d223f7e8be73671233d7c2d79451 100644 (file)
@@ -436,13 +436,6 @@ func (n *Node) jconv(s fmt.State, flag FmtFlag) {
                fmt.Fprintf(s, " colas(%v)", n.Colas())
        }
 
-       if n.Name != nil && n.Name.Funcdepth != 0 {
-               fmt.Fprintf(s, " f(%d)", n.Name.Funcdepth)
-       }
-       if n.Func != nil && n.Func.Depth != 0 {
-               fmt.Fprintf(s, " ff(%d)", n.Func.Depth)
-       }
-
        switch n.Esc {
        case EscUnknown:
                break
index 36b46a1c6903d2115112fb6506c74c958df4ff29..e920f698b7d83f25b40414db445591950a2eee53 100644 (file)
@@ -204,13 +204,11 @@ func funccompile(fn *Node) {
        }
 
        dclcontext = PAUTO
-       funcdepth = fn.Func.Depth + 1
        Curfn = fn
 
        compile(fn)
 
        Curfn = nil
-       funcdepth = 0
        dclcontext = PEXTERN
 }
 
index 48d357a0b03b3379015b5b2ee00a90968091ed86..d649fd58d30e789ca39526b0665bdf4d95fc7b4a 100644 (file)
@@ -22,8 +22,8 @@ func TestSizeof(t *testing.T) {
                _32bit uintptr     // size on 32bit platforms
                _64bit uintptr     // size on 64bit platforms
        }{
-               {Func{}, 132, 232},
-               {Name{}, 36, 56},
+               {Func{}, 128, 232},
+               {Name{}, 32, 56},
                {Param{}, 28, 56},
                {Node{}, 76, 128},
        }
index e120dccabfcb66ebd064c2c37637e0222b15d7b6..65ecbeede200b541be875b0ae0016a06d353b816 100644 (file)
@@ -242,7 +242,6 @@ type Name struct {
        Param     *Param     // additional fields for ONAME, OTYPE
        Decldepth int32      // declaration loop depth, increased for every loop or label
        Vargen    int32      // unique name for ONAME within a function.  Function outputs are numbered starting at one.
-       Funcdepth int32
 
        used  bool // for variable declared and not used error
        flags bitset8
@@ -433,7 +432,6 @@ type Func struct {
 
        Inl     Nodes // copy of the body for use in inlining
        InlCost int32
-       Depth   int32
 
        Label int32 // largest auto-generated label in this function
 
index 8770684d876b1b2b491bc615c9d24fa2b596cca7..bdfda78061b3753a50d0f55dc53f9c053aba5289 100644 (file)
@@ -3868,9 +3868,6 @@ func wrapCall(n *Node, init *Nodes) *Node {
                args = append(args, a.Left)
        }
 
-       oldfn := Curfn
-       Curfn = nil
-
        wrapCall_prgen++
        sym := lookupN("wrap·", wrapCall_prgen)
        fn := dclfunc(sym, t)
@@ -3885,7 +3882,6 @@ func wrapCall(n *Node, init *Nodes) *Node {
        fn = typecheck(fn, Etop)
        typecheckslice(fn.Nbody.Slice(), Etop)
        xtop = append(xtop, fn)
-       Curfn = oldfn
 
        a = nod(OCALL, nil, nil)
        a.Left = fn.Func.Nname