]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clean up ctxt params in sinit
authorJosh Bleecher Snyder <josharian@gmail.com>
Sun, 4 Sep 2016 16:34:03 +0000 (09:34 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 5 Sep 2016 01:58:47 +0000 (01:58 +0000)
The ctxt parameter is always set to 0 on entry into anylit so make this
parameter a literal constant, and where possibly remove ctxt as a parameter
where it is known to be a constant zero.

Passes toolstash -cmp.

This is a re-creation of CL 28221 by Dave Cheney.
That CL was graciously reverted in CL 28480
to make merging other CLs easier.

Change-Id: If7a57bf0e27774d9890adbc30af9fabb4aff1058
Reviewed-on: https://go-review.googlesource.com/28483
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Dave Cheney <dave@cheney.net>
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/walk.go

index b480a8a211fee3090ee483080a4601d924256a5e..01c74613e0dae1ae823b13d5ddefae8bd91d6072 100644 (file)
@@ -508,7 +508,7 @@ const (
 // data statements for the constant
 // part of the composite literal.
 
-// staticname return a name backed by a static data symbol.
+// staticname returns a name backed by a static data symbol.
 // Callers should set n.Name.Readonly = true on the
 // returned node for readonly nodes.
 func staticname(t *Type) *Node {
@@ -822,7 +822,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
        init.Append(a)
 }
 
-func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) {
+func maplit(n *Node, m *Node, init *Nodes) {
        // make the map var
        nerr := nerrors
 
@@ -969,7 +969,7 @@ func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) {
        }
 }
 
-func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
+func anylit(n *Node, var_ *Node, init *Nodes) {
        t := n.Type
        switch n.Op {
        default:
@@ -999,7 +999,7 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
 
                var_ = Nod(OIND, var_, nil)
                var_ = typecheck(var_, Erv|Easgn)
-               anylit(ctxt, n.Left, var_, init)
+               anylit(n.Left, var_, init)
 
        case OSTRUCTLIT, OARRAYLIT:
                if !t.IsStruct() && !t.IsArray() {
@@ -1007,32 +1007,25 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
                }
 
                if var_.isSimpleName() && n.List.Len() > 4 {
-                       if ctxt == inInitFunction {
-                               // lay out static data
-                               vstat := staticname(t)
-                               vstat.Name.Readonly = true
-
-                               litctxt := ctxt
-                               if n.Op == OARRAYLIT {
-                                       litctxt = inNonInitFunction
-                               }
-                               fixedlit(litctxt, initKindStatic, n, vstat, init)
-
-                               // copy static to var
-                               a := Nod(OAS, var_, vstat)
+                       // lay out static data
+                       vstat := staticname(t)
+                       vstat.Name.Readonly = true
 
-                               a = typecheck(a, Etop)
-                               a = walkexpr(a, init)
-                               init.Append(a)
+                       ctxt := inInitFunction
+                       if n.Op == OARRAYLIT {
+                               ctxt = inNonInitFunction
+                       }
+                       fixedlit(ctxt, initKindStatic, n, vstat, init)
 
-                               // add expressions to automatic
-                               fixedlit(ctxt, initKindDynamic, n, var_, init)
+                       // copy static to var
+                       a := Nod(OAS, var_, vstat)
 
-                               break
-                       }
+                       a = typecheck(a, Etop)
+                       a = walkexpr(a, init)
+                       init.Append(a)
 
-                       fixedlit(ctxt, initKindStatic, n, var_, init)
-                       fixedlit(ctxt, initKindDynamic, n, var_, init)
+                       // add expressions to automatic
+                       fixedlit(inInitFunction, initKindDynamic, n, var_, init)
                        break
                }
 
@@ -1050,48 +1043,48 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
                        init.Append(a)
                }
 
-               fixedlit(ctxt, initKindLocalCode, n, var_, init)
+               fixedlit(inInitFunction, initKindLocalCode, n, var_, init)
 
        case OSLICELIT:
-               slicelit(ctxt, n, var_, init)
+               slicelit(inInitFunction, n, var_, init)
 
        case OMAPLIT:
                if !t.IsMap() {
                        Fatalf("anylit: not map")
                }
-               maplit(ctxt, n, var_, init)
+               maplit(n, var_, init)
        }
 }
 
 func oaslit(n *Node, init *Nodes) bool {
        if n.Left == nil || n.Right == nil {
-               // not a special composit literal assignment
+               // not a special composite literal assignment
                return false
        }
        if n.Left.Type == nil || n.Right.Type == nil {
-               // not a special composit literal assignment
+               // not a special composite literal assignment
                return false
        }
        if !n.Left.isSimpleName() {
-               // not a special composit literal assignment
+               // not a special composite literal assignment
                return false
        }
        if !Eqtype(n.Left.Type, n.Right.Type) {
-               // not a special composit literal assignment
+               // not a special composite literal assignment
                return false
        }
 
        switch n.Right.Op {
        default:
-               // not a special composit literal assignment
+               // not a special composite literal assignment
                return false
 
        case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
                if vmatch1(n.Left, n.Right) {
-                       // not a special composit literal assignment
+                       // not a special composite literal assignment
                        return false
                }
-               anylit(inInitFunction, n.Right, n.Left, init)
+               anylit(n.Right, n.Left, init)
        }
 
        n.Op = OEMPTY
index 28fe549694c0504eb68c5165b89b3eaa11fa5107..0b033758a5691fec3cd0feaa98761cee08d9d480 100644 (file)
@@ -1644,7 +1644,7 @@ opswitch:
                        break
                }
                var_ := temp(n.Type)
-               anylit(inInitFunction, n, var_, init)
+               anylit(n, var_, init)
                n = var_
 
        case OSEND: