[dev.regabi] cmd/compile: change CaseStmt.Vars to Var

There's only ever one variable implicitly declared by a CaseStmt. It's
only a slice because we previous used Rlist for this.

Passes toolstash -cmp.

Change-Id: Idf747f3ec6dfbbe4e94d60546ba04a81754df3fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/280012
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>
This commit is contained in:
Matthew Dempsky 2020-12-23 06:59:16 -08:00
parent 9eeed291bc
commit 40818038bf
8 changed files with 11 additions and 15 deletions

View file

@ -373,7 +373,7 @@ func (e *escape) stmt(n ir.Node) {
for _, cas := range n.Cases { // cases for _, cas := range n.Cases { // cases
cas := cas.(*ir.CaseStmt) cas := cas.(*ir.CaseStmt)
if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil { if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil {
cv := cas.Vars[0] cv := cas.Var
k := e.dcl(cv) // type switch variables have no ODCL. k := e.dcl(cv) // type switch variables have no ODCL.
if cv.Type().HasPointers() { if cv.Type().HasPointers() {
ks = append(ks, k.dotType(cv.Type(), cas, "switch case")) ks = append(ks, k.dotType(cv.Type(), cas, "switch case"))

View file

@ -230,7 +230,6 @@ func (n *CaseStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *CaseStmt) copy() Node { func (n *CaseStmt) copy() Node {
c := *n c := *n
c.init = c.init.Copy() c.init = c.init.Copy()
c.Vars = c.Vars.Copy()
c.List = c.List.Copy() c.List = c.List.Copy()
c.Body = c.Body.Copy() c.Body = c.Body.Copy()
return &c return &c
@ -238,7 +237,7 @@ func (n *CaseStmt) copy() Node {
func (n *CaseStmt) doChildren(do func(Node) error) error { func (n *CaseStmt) doChildren(do func(Node) error) error {
var err error var err error
err = maybeDoList(n.init, err, do) err = maybeDoList(n.init, err, do)
err = maybeDoList(n.Vars, err, do) err = maybeDo(n.Var, err, do)
err = maybeDoList(n.List, err, do) err = maybeDoList(n.List, err, do)
err = maybeDo(n.Comm, err, do) err = maybeDo(n.Comm, err, do)
err = maybeDoList(n.Body, err, do) err = maybeDoList(n.Body, err, do)
@ -246,7 +245,7 @@ func (n *CaseStmt) doChildren(do func(Node) error) error {
} }
func (n *CaseStmt) editChildren(edit func(Node) Node) { func (n *CaseStmt) editChildren(edit func(Node) Node) {
editList(n.init, edit) editList(n.init, edit)
editList(n.Vars, edit) n.Var = maybeEdit(n.Var, edit)
editList(n.List, edit) editList(n.List, edit)
n.Comm = maybeEdit(n.Comm, edit) n.Comm = maybeEdit(n.Comm, edit)
editList(n.Body, edit) editList(n.Body, edit)

View file

@ -176,7 +176,7 @@ func (n *BranchStmt) Sym() *types.Sym { return n.Label }
// A CaseStmt is a case statement in a switch or select: case List: Body. // A CaseStmt is a case statement in a switch or select: case List: Body.
type CaseStmt struct { type CaseStmt struct {
miniStmt miniStmt
Vars Nodes // declared variable for this case in type switch Var Node // declared variable for this case in type switch
List Nodes // list of expressions for switch, early select List Nodes // list of expressions for switch, early select
Comm Node // communication case (Exprs[0]) after select is type-checked Comm Node // communication case (Exprs[0]) after select is type-checked
Body Nodes Body Nodes

View file

@ -1217,7 +1217,7 @@ func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *ir.TypeSwitch
if tswitch != nil && tswitch.Tag != nil { if tswitch != nil && tswitch.Tag != nil {
nn := typecheck.NewName(tswitch.Tag.Sym()) nn := typecheck.NewName(tswitch.Tag.Sym())
typecheck.Declare(nn, typecheck.DeclContext) typecheck.Declare(nn, typecheck.DeclContext)
n.Vars = []ir.Node{nn} n.Var = nn
// keep track of the instances for reporting unused // keep track of the instances for reporting unused
nn.Defn = tswitch nn.Defn = tswitch
} }

View file

@ -1196,7 +1196,7 @@ func (w *exportWriter) caseList(cases []ir.Node, namedTypeSwitch bool) {
w.pos(cas.Pos()) w.pos(cas.Pos())
w.stmtList(cas.List) w.stmtList(cas.List)
if namedTypeSwitch { if namedTypeSwitch {
w.localName(cas.Vars[0].(*ir.Name)) w.localName(cas.Var.(*ir.Name))
} }
w.stmtList(cas.Body) w.stmtList(cas.Body)
} }

View file

@ -780,7 +780,7 @@ func (r *importReader) caseList(switchExpr ir.Node) []ir.Node {
// Sym for diagnostics anyway. // Sym for diagnostics anyway.
caseVar := ir.NewNameAt(cas.Pos(), r.ident()) caseVar := ir.NewNameAt(cas.Pos(), r.ident())
Declare(caseVar, DeclContext) Declare(caseVar, DeclContext)
cas.Vars = []ir.Node{caseVar} cas.Var = caseVar
caseVar.Defn = switchExpr caseVar.Defn = switchExpr
} }
cas.Body.Set(r.stmtList()) cas.Body.Set(r.stmtList())

View file

@ -694,7 +694,7 @@ func tcSwitchType(n *ir.SwitchStmt) {
ts.add(ncase.Pos(), n1.Type()) ts.add(ncase.Pos(), n1.Type())
} }
if len(ncase.Vars) != 0 { if ncase.Var != nil {
// Assign the clause variable's type. // Assign the clause variable's type.
vt := t vt := t
if len(ls) == 1 { if len(ls) == 1 {
@ -707,7 +707,7 @@ func tcSwitchType(n *ir.SwitchStmt) {
} }
} }
nvar := ncase.Vars[0] nvar := ncase.Var
nvar.SetType(vt) nvar.SetType(vt)
if vt != nil { if vt != nil {
nvar = AssignExpr(nvar) nvar = AssignExpr(nvar)
@ -716,7 +716,7 @@ func tcSwitchType(n *ir.SwitchStmt) {
nvar.SetTypecheck(1) nvar.SetTypecheck(1)
nvar.SetWalkdef(1) nvar.SetWalkdef(1)
} }
ncase.Vars[0] = nvar ncase.Var = nvar
} }
Stmts(ncase.Body) Stmts(ncase.Body)

View file

@ -334,10 +334,7 @@ func walkSwitchType(sw *ir.SwitchStmt) {
var body ir.Nodes var body ir.Nodes
for _, ncase := range sw.Cases { for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt) ncase := ncase.(*ir.CaseStmt)
var caseVar ir.Node caseVar := ncase.Var
if len(ncase.Vars) != 0 {
caseVar = ncase.Vars[0]
}
// For single-type cases with an interface type, // For single-type cases with an interface type,
// we initialize the case variable as part of the type assertion. // we initialize the case variable as part of the type assertion.