From 460b76aef98490b3cf8d374c589db631eab85957 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 4 Sep 2016 09:34:03 -0700 Subject: [PATCH] cmd/compile: clean up ctxt params in sinit 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Dave Cheney --- src/cmd/compile/internal/gc/sinit.go | 65 +++++++++++++--------------- src/cmd/compile/internal/gc/walk.go | 2 +- 2 files changed, 30 insertions(+), 37 deletions(-) diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index b480a8a211..01c74613e0 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -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 diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 28fe549694..0b033758a5 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1644,7 +1644,7 @@ opswitch: break } var_ := temp(n.Type) - anylit(inInitFunction, n, var_, init) + anylit(n, var_, init) n = var_ case OSEND: -- 2.48.1