Commit 460b76ae authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarDave Cheney <dave@cheney.net>
parent 199b17cc
...@@ -508,7 +508,7 @@ const ( ...@@ -508,7 +508,7 @@ const (
// data statements for the constant // data statements for the constant
// part of the composite literal. // 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 // Callers should set n.Name.Readonly = true on the
// returned node for readonly nodes. // returned node for readonly nodes.
func staticname(t *Type) *Node { func staticname(t *Type) *Node {
...@@ -822,7 +822,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -822,7 +822,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
init.Append(a) 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 // make the map var
nerr := nerrors nerr := nerrors
...@@ -969,7 +969,7 @@ func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) { ...@@ -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 t := n.Type
switch n.Op { switch n.Op {
default: default:
...@@ -999,7 +999,7 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -999,7 +999,7 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
var_ = Nod(OIND, var_, nil) var_ = Nod(OIND, var_, nil)
var_ = typecheck(var_, Erv|Easgn) var_ = typecheck(var_, Erv|Easgn)
anylit(ctxt, n.Left, var_, init) anylit(n.Left, var_, init)
case OSTRUCTLIT, OARRAYLIT: case OSTRUCTLIT, OARRAYLIT:
if !t.IsStruct() && !t.IsArray() { if !t.IsStruct() && !t.IsArray() {
...@@ -1007,16 +1007,15 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -1007,16 +1007,15 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
} }
if var_.isSimpleName() && n.List.Len() > 4 { if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == inInitFunction {
// lay out static data // lay out static data
vstat := staticname(t) vstat := staticname(t)
vstat.Name.Readonly = true vstat.Name.Readonly = true
litctxt := ctxt ctxt := inInitFunction
if n.Op == OARRAYLIT { if n.Op == OARRAYLIT {
litctxt = inNonInitFunction ctxt = inNonInitFunction
} }
fixedlit(litctxt, initKindStatic, n, vstat, init) fixedlit(ctxt, initKindStatic, n, vstat, init)
// copy static to var // copy static to var
a := Nod(OAS, var_, vstat) a := Nod(OAS, var_, vstat)
...@@ -1026,13 +1025,7 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -1026,13 +1025,7 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
init.Append(a) init.Append(a)
// add expressions to automatic // add expressions to automatic
fixedlit(ctxt, initKindDynamic, n, var_, init) fixedlit(inInitFunction, initKindDynamic, n, var_, init)
break
}
fixedlit(ctxt, initKindStatic, n, var_, init)
fixedlit(ctxt, initKindDynamic, n, var_, init)
break break
} }
...@@ -1050,48 +1043,48 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) { ...@@ -1050,48 +1043,48 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
init.Append(a) init.Append(a)
} }
fixedlit(ctxt, initKindLocalCode, n, var_, init) fixedlit(inInitFunction, initKindLocalCode, n, var_, init)
case OSLICELIT: case OSLICELIT:
slicelit(ctxt, n, var_, init) slicelit(inInitFunction, n, var_, init)
case OMAPLIT: case OMAPLIT:
if !t.IsMap() { if !t.IsMap() {
Fatalf("anylit: not map") Fatalf("anylit: not map")
} }
maplit(ctxt, n, var_, init) maplit(n, var_, init)
} }
} }
func oaslit(n *Node, init *Nodes) bool { func oaslit(n *Node, init *Nodes) bool {
if n.Left == nil || n.Right == nil { if n.Left == nil || n.Right == nil {
// not a special composit literal assignment // not a special composite literal assignment
return false return false
} }
if n.Left.Type == nil || n.Right.Type == nil { if n.Left.Type == nil || n.Right.Type == nil {
// not a special composit literal assignment // not a special composite literal assignment
return false return false
} }
if !n.Left.isSimpleName() { if !n.Left.isSimpleName() {
// not a special composit literal assignment // not a special composite literal assignment
return false return false
} }
if !Eqtype(n.Left.Type, n.Right.Type) { if !Eqtype(n.Left.Type, n.Right.Type) {
// not a special composit literal assignment // not a special composite literal assignment
return false return false
} }
switch n.Right.Op { switch n.Right.Op {
default: default:
// not a special composit literal assignment // not a special composite literal assignment
return false return false
case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT: case OSTRUCTLIT, OARRAYLIT, OSLICELIT, OMAPLIT:
if vmatch1(n.Left, n.Right) { if vmatch1(n.Left, n.Right) {
// not a special composit literal assignment // not a special composite literal assignment
return false return false
} }
anylit(inInitFunction, n.Right, n.Left, init) anylit(n.Right, n.Left, init)
} }
n.Op = OEMPTY n.Op = OEMPTY
......
...@@ -1644,7 +1644,7 @@ opswitch: ...@@ -1644,7 +1644,7 @@ opswitch:
break break
} }
var_ := temp(n.Type) var_ := temp(n.Type)
anylit(inInitFunction, n, var_, init) anylit(n, var_, init)
n = var_ n = var_
case OSEND: case OSEND:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment