1
0
mirror of https://github.com/golang/go synced 2024-11-22 19:05:01 -07:00

[dev.regabi] cmd/compile: use []*CaseStmt in {Select,Switch}Stmt

Select and switch statements only ever contain case statements, so
change their Cases fields from Nodes to []*CaseStmt. This allows
removing a bunch of type assertions throughout the compiler.

CaseStmt should be renamed to CaseClause, and SelectStmt should
probably have its own CommClause type instead (like in go/ast and
cmd/compile/internal/syntax), but this is a good start.

Passes toolstash -cmp.

Change-Id: I2d41d616d44512c2be421e1e2ff13d0ee8b238ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/280442
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-26 22:23:45 -08:00
parent fbc4458c06
commit a59d26603f
13 changed files with 73 additions and 53 deletions

View File

@ -369,7 +369,6 @@ func (e *escape) stmt(n ir.Node) {
var ks []hole var ks []hole
for _, cas := range n.Cases { // cases for _, cas := range n.Cases { // cases
cas := cas.(*ir.CaseStmt)
if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil { if typesw && n.Tag.(*ir.TypeSwitchGuard).Tag != nil {
cv := cas.Var cv := cas.Var
k := e.dcl(cv) // type switch variables have no ODCL. k := e.dcl(cv) // type switch variables have no ODCL.
@ -391,7 +390,6 @@ func (e *escape) stmt(n ir.Node) {
case ir.OSELECT: case ir.OSELECT:
n := n.(*ir.SelectStmt) n := n.(*ir.SelectStmt)
for _, cas := range n.Cases { for _, cas := range n.Cases {
cas := cas.(*ir.CaseStmt)
e.stmt(cas.Comm) e.stmt(cas.Comm)
e.block(cas.Body) e.block(cas.Body)
} }

View File

@ -37,6 +37,7 @@ func main() {
nodeType := lookup("Node") nodeType := lookup("Node")
ntypeType := lookup("Ntype") ntypeType := lookup("Ntype")
nodesType := lookup("Nodes") nodesType := lookup("Nodes")
slicePtrCaseStmtType := types.NewSlice(types.NewPointer(lookup("CaseStmt")))
ptrFieldType := types.NewPointer(lookup("Field")) ptrFieldType := types.NewPointer(lookup("Field"))
slicePtrFieldType := types.NewSlice(ptrFieldType) slicePtrFieldType := types.NewSlice(ptrFieldType)
ptrIdentType := types.NewPointer(lookup("Ident")) ptrIdentType := types.NewPointer(lookup("Ident"))
@ -76,6 +77,8 @@ func main() {
switch { switch {
case is(nodesType): case is(nodesType):
fmt.Fprintf(&buf, "c.%s = c.%s.Copy()\n", name, name) fmt.Fprintf(&buf, "c.%s = c.%s.Copy()\n", name, name)
case is(slicePtrCaseStmtType):
fmt.Fprintf(&buf, "c.%s = copyCases(c.%s)\n", name, name)
case is(ptrFieldType): case is(ptrFieldType):
fmt.Fprintf(&buf, "if c.%s != nil { c.%s = c.%s.copy() }\n", name, name, name) fmt.Fprintf(&buf, "if c.%s != nil { c.%s = c.%s.copy() }\n", name, name, name)
case is(slicePtrFieldType): case is(slicePtrFieldType):
@ -94,6 +97,8 @@ func main() {
fmt.Fprintf(&buf, "err = maybeDo(n.%s, err, do)\n", name) fmt.Fprintf(&buf, "err = maybeDo(n.%s, err, do)\n", name)
case is(nodesType): case is(nodesType):
fmt.Fprintf(&buf, "err = maybeDoList(n.%s, err, do)\n", name) fmt.Fprintf(&buf, "err = maybeDoList(n.%s, err, do)\n", name)
case is(slicePtrCaseStmtType):
fmt.Fprintf(&buf, "err = maybeDoCases(n.%s, err, do)\n", name)
case is(ptrFieldType): case is(ptrFieldType):
fmt.Fprintf(&buf, "err = maybeDoField(n.%s, err, do)\n", name) fmt.Fprintf(&buf, "err = maybeDoField(n.%s, err, do)\n", name)
case is(slicePtrFieldType): case is(slicePtrFieldType):
@ -113,6 +118,8 @@ func main() {
fmt.Fprintf(&buf, "n.%s = toNtype(maybeEdit(n.%s, edit))\n", name, name) fmt.Fprintf(&buf, "n.%s = toNtype(maybeEdit(n.%s, edit))\n", name, name)
case is(nodesType): case is(nodesType):
fmt.Fprintf(&buf, "editList(n.%s, edit)\n", name) fmt.Fprintf(&buf, "editList(n.%s, edit)\n", name)
case is(slicePtrCaseStmtType):
fmt.Fprintf(&buf, "editCases(n.%s, edit)\n", name)
case is(ptrFieldType): case is(ptrFieldType):
fmt.Fprintf(&buf, "editField(n.%s, edit)\n", name) fmt.Fprintf(&buf, "editField(n.%s, edit)\n", name)
case is(slicePtrFieldType): case is(slicePtrFieldType):

View File

@ -781,20 +781,20 @@ func (n *SelectStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SelectStmt) copy() Node { func (n *SelectStmt) copy() Node {
c := *n c := *n
c.init = c.init.Copy() c.init = c.init.Copy()
c.Cases = c.Cases.Copy() c.Cases = copyCases(c.Cases)
c.Compiled = c.Compiled.Copy() c.Compiled = c.Compiled.Copy()
return &c return &c
} }
func (n *SelectStmt) doChildren(do func(Node) error) error { func (n *SelectStmt) 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.Cases, err, do) err = maybeDoCases(n.Cases, err, do)
err = maybeDoList(n.Compiled, err, do) err = maybeDoList(n.Compiled, err, do)
return err return err
} }
func (n *SelectStmt) editChildren(edit func(Node) Node) { func (n *SelectStmt) editChildren(edit func(Node) Node) {
editList(n.init, edit) editList(n.init, edit)
editList(n.Cases, edit) editCases(n.Cases, edit)
editList(n.Compiled, edit) editList(n.Compiled, edit)
} }
@ -945,7 +945,7 @@ func (n *SwitchStmt) Format(s fmt.State, verb rune) { FmtNode(n, s, verb) }
func (n *SwitchStmt) copy() Node { func (n *SwitchStmt) copy() Node {
c := *n c := *n
c.init = c.init.Copy() c.init = c.init.Copy()
c.Cases = c.Cases.Copy() c.Cases = copyCases(c.Cases)
c.Compiled = c.Compiled.Copy() c.Compiled = c.Compiled.Copy()
return &c return &c
} }
@ -953,14 +953,14 @@ func (n *SwitchStmt) 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 = maybeDo(n.Tag, err, do) err = maybeDo(n.Tag, err, do)
err = maybeDoList(n.Cases, err, do) err = maybeDoCases(n.Cases, err, do)
err = maybeDoList(n.Compiled, err, do) err = maybeDoList(n.Compiled, err, do)
return err return err
} }
func (n *SwitchStmt) editChildren(edit func(Node) Node) { func (n *SwitchStmt) editChildren(edit func(Node) Node) {
editList(n.init, edit) editList(n.init, edit)
n.Tag = maybeEdit(n.Tag, edit) n.Tag = maybeEdit(n.Tag, edit)
editList(n.Cases, edit) editCases(n.Cases, edit)
editList(n.Compiled, edit) editList(n.Compiled, edit)
} }

View File

@ -191,6 +191,37 @@ func NewCaseStmt(pos src.XPos, list, body []Node) *CaseStmt {
return n return n
} }
func copyCases(list []*CaseStmt) []*CaseStmt {
if list == nil {
return nil
}
c := make([]*CaseStmt, len(list))
copy(c, list)
return c
}
func maybeDoCases(list []*CaseStmt, err error, do func(Node) error) error {
if err != nil {
return err
}
for _, x := range list {
if x != nil {
if err := do(x); err != nil {
return err
}
}
}
return nil
}
func editCases(list []*CaseStmt, edit func(Node) Node) {
for i, x := range list {
if x != nil {
list[i] = edit(x).(*CaseStmt)
}
}
}
// A ForStmt is a non-range for loop: for Init; Cond; Post { Body } // A ForStmt is a non-range for loop: for Init; Cond; Post { Body }
// Op can be OFOR or OFORUNTIL (!Cond). // Op can be OFOR or OFORUNTIL (!Cond).
type ForStmt struct { type ForStmt struct {
@ -334,18 +365,18 @@ func (n *ReturnStmt) SetOrig(x Node) { n.orig = x }
type SelectStmt struct { type SelectStmt struct {
miniStmt miniStmt
Label *types.Sym Label *types.Sym
Cases Nodes Cases []*CaseStmt
HasBreak bool HasBreak bool
// TODO(rsc): Instead of recording here, replace with a block? // TODO(rsc): Instead of recording here, replace with a block?
Compiled Nodes // compiled form, after walkswitch Compiled Nodes // compiled form, after walkswitch
} }
func NewSelectStmt(pos src.XPos, cases []Node) *SelectStmt { func NewSelectStmt(pos src.XPos, cases []*CaseStmt) *SelectStmt {
n := &SelectStmt{} n := &SelectStmt{}
n.pos = pos n.pos = pos
n.op = OSELECT n.op = OSELECT
n.Cases.Set(cases) n.Cases = cases
return n return n
} }
@ -367,7 +398,7 @@ func NewSendStmt(pos src.XPos, ch, value Node) *SendStmt {
type SwitchStmt struct { type SwitchStmt struct {
miniStmt miniStmt
Tag Node Tag Node
Cases Nodes // list of *CaseStmt Cases []*CaseStmt
Label *types.Sym Label *types.Sym
HasBreak bool HasBreak bool
@ -375,11 +406,11 @@ type SwitchStmt struct {
Compiled Nodes // compiled form, after walkswitch Compiled Nodes // compiled form, after walkswitch
} }
func NewSwitchStmt(pos src.XPos, tag Node, cases []Node) *SwitchStmt { func NewSwitchStmt(pos src.XPos, tag Node, cases []*CaseStmt) *SwitchStmt {
n := &SwitchStmt{Tag: tag} n := &SwitchStmt{Tag: tag}
n.pos = pos n.pos = pos
n.op = OSWITCH n.op = OSWITCH
n.Cases.Set(cases) n.Cases = cases
return n return n
} }

View File

@ -217,10 +217,9 @@ func EditChildren(n Node, edit func(Node) Node) {
// Note that editList only calls edit on the nodes in the list, not their children. // Note that editList only calls edit on the nodes in the list, not their children.
// If x's children should be processed, edit(x) must call EditChildren(x, edit) itself. // If x's children should be processed, edit(x) must call EditChildren(x, edit) itself.
func editList(list Nodes, edit func(Node) Node) { func editList(list Nodes, edit func(Node) Node) {
s := list
for i, x := range list { for i, x := range list {
if x != nil { if x != nil {
s[i] = edit(x) list[i] = edit(x)
} }
} }
} }

View File

@ -1202,14 +1202,14 @@ func (p *noder) switchStmt(stmt *syntax.SwitchStmt) ir.Node {
if l := n.Tag; l != nil && l.Op() == ir.OTYPESW { if l := n.Tag; l != nil && l.Op() == ir.OTYPESW {
tswitch = l.(*ir.TypeSwitchGuard) tswitch = l.(*ir.TypeSwitchGuard)
} }
n.Cases.Set(p.caseClauses(stmt.Body, tswitch, stmt.Rbrace)) n.Cases = p.caseClauses(stmt.Body, tswitch, stmt.Rbrace)
p.closeScope(stmt.Rbrace) p.closeScope(stmt.Rbrace)
return n return n
} }
func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *ir.TypeSwitchGuard, rbrace syntax.Pos) []ir.Node { func (p *noder) caseClauses(clauses []*syntax.CaseClause, tswitch *ir.TypeSwitchGuard, rbrace syntax.Pos) []*ir.CaseStmt {
nodes := make([]ir.Node, 0, len(clauses)) nodes := make([]*ir.CaseStmt, 0, len(clauses))
for i, clause := range clauses { for i, clause := range clauses {
p.setlineno(clause) p.setlineno(clause)
if i > 0 { if i > 0 {
@ -1266,8 +1266,8 @@ func (p *noder) simpleStmt(stmt syntax.SimpleStmt) []ir.Node {
return []ir.Node{p.stmt(stmt)} return []ir.Node{p.stmt(stmt)}
} }
func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []ir.Node { func (p *noder) commClauses(clauses []*syntax.CommClause, rbrace syntax.Pos) []*ir.CaseStmt {
nodes := make([]ir.Node, len(clauses)) nodes := make([]*ir.CaseStmt, len(clauses))
for i, clause := range clauses { for i, clause := range clauses {
p.setlineno(clause) p.setlineno(clause)
if i > 0 { if i > 0 {

View File

@ -1181,10 +1181,9 @@ func isNamedTypeSwitch(x ir.Node) bool {
return ok && guard.Tag != nil return ok && guard.Tag != nil
} }
func (w *exportWriter) caseList(cases []ir.Node, namedTypeSwitch bool) { func (w *exportWriter) caseList(cases []*ir.CaseStmt, namedTypeSwitch bool) {
w.uint64(uint64(len(cases))) w.uint64(uint64(len(cases)))
for _, cas := range cases { for _, cas := range cases {
cas := cas.(*ir.CaseStmt)
w.pos(cas.Pos()) w.pos(cas.Pos())
w.stmtList(cas.List) w.stmtList(cas.List)
if namedTypeSwitch { if namedTypeSwitch {

View File

@ -767,10 +767,10 @@ func (r *importReader) stmtList() []ir.Node {
return list return list
} }
func (r *importReader) caseList(switchExpr ir.Node) []ir.Node { func (r *importReader) caseList(switchExpr ir.Node) []*ir.CaseStmt {
namedTypeSwitch := isNamedTypeSwitch(switchExpr) namedTypeSwitch := isNamedTypeSwitch(switchExpr)
cases := make([]ir.Node, r.uint64()) cases := make([]*ir.CaseStmt, r.uint64())
for i := range cases { for i := range cases {
cas := ir.NewCaseStmt(r.pos(), nil, nil) cas := ir.NewCaseStmt(r.pos(), nil, nil)
cas.List.Set(r.stmtList()) cas.List.Set(r.stmtList())

View File

@ -364,8 +364,6 @@ func tcSelect(sel *ir.SelectStmt) {
lno := ir.SetPos(sel) lno := ir.SetPos(sel)
Stmts(sel.Init()) Stmts(sel.Init())
for _, ncase := range sel.Cases { for _, ncase := range sel.Cases {
ncase := ncase.(*ir.CaseStmt)
if len(ncase.List) == 0 { if len(ncase.List) == 0 {
// default // default
if def != nil { if def != nil {
@ -508,7 +506,6 @@ func tcSwitchExpr(n *ir.SwitchStmt) {
var defCase ir.Node var defCase ir.Node
var cs constSet var cs constSet
for _, ncase := range n.Cases { for _, ncase := range n.Cases {
ncase := ncase.(*ir.CaseStmt)
ls := ncase.List ls := ncase.List
if len(ls) == 0 { // default: if len(ls) == 0 { // default:
if defCase != nil { if defCase != nil {
@ -577,7 +574,6 @@ func tcSwitchType(n *ir.SwitchStmt) {
var defCase, nilCase ir.Node var defCase, nilCase ir.Node
var ts typeSet var ts typeSet
for _, ncase := range n.Cases { for _, ncase := range n.Cases {
ncase := ncase.(*ir.CaseStmt)
ls := ncase.List ls := ncase.List
if len(ls) == 0 { // default: if len(ls) == 0 { // default:
if defCase != nil { if defCase != nil {

View File

@ -2103,7 +2103,6 @@ func isTermNode(n ir.Node) bool {
} }
def := false def := false
for _, cas := range n.Cases { for _, cas := range n.Cases {
cas := cas.(*ir.CaseStmt)
if !isTermNodes(cas.Body) { if !isTermNodes(cas.Body) {
return false return false
} }
@ -2119,7 +2118,6 @@ func isTermNode(n ir.Node) bool {
return false return false
} }
for _, cas := range n.Cases { for _, cas := range n.Cases {
cas := cas.(*ir.CaseStmt)
if !isTermNodes(cas.Body) { if !isTermNodes(cas.Body) {
return false return false
} }
@ -2218,9 +2216,6 @@ func deadcodeslice(nn *ir.Nodes) {
case ir.OBLOCK: case ir.OBLOCK:
n := n.(*ir.BlockStmt) n := n.(*ir.BlockStmt)
deadcodeslice(&n.List) deadcodeslice(&n.List)
case ir.OCASE:
n := n.(*ir.CaseStmt)
deadcodeslice(&n.Body)
case ir.OFOR: case ir.OFOR:
n := n.(*ir.ForStmt) n := n.(*ir.ForStmt)
deadcodeslice(&n.Body) deadcodeslice(&n.Body)
@ -2233,10 +2228,14 @@ func deadcodeslice(nn *ir.Nodes) {
deadcodeslice(&n.Body) deadcodeslice(&n.Body)
case ir.OSELECT: case ir.OSELECT:
n := n.(*ir.SelectStmt) n := n.(*ir.SelectStmt)
deadcodeslice(&n.Cases) for _, cas := range n.Cases {
deadcodeslice(&cas.Body)
}
case ir.OSWITCH: case ir.OSWITCH:
n := n.(*ir.SwitchStmt) n := n.(*ir.SwitchStmt)
deadcodeslice(&n.Cases) for _, cas := range n.Cases {
deadcodeslice(&cas.Body)
}
} }
if cut { if cut {

View File

@ -914,7 +914,6 @@ func (o *orderState) stmt(n ir.Node) {
n := n.(*ir.SelectStmt) n := n.(*ir.SelectStmt)
t := o.markTemp() t := o.markTemp()
for _, ncas := range n.Cases { for _, ncas := range n.Cases {
ncas := ncas.(*ir.CaseStmt)
r := ncas.Comm r := ncas.Comm
ir.SetPos(ncas) ir.SetPos(ncas)
@ -996,7 +995,6 @@ func (o *orderState) stmt(n ir.Node) {
// Also insert any ninit queued during the previous loop. // Also insert any ninit queued during the previous loop.
// (The temporary cleaning must follow that ninit work.) // (The temporary cleaning must follow that ninit work.)
for _, cas := range n.Cases { for _, cas := range n.Cases {
cas := cas.(*ir.CaseStmt)
orderBlock(&cas.Body, o.free) orderBlock(&cas.Body, o.free)
cas.Body.Prepend(o.cleanTempNoPop(t)...) cas.Body.Prepend(o.cleanTempNoPop(t)...)
@ -1036,13 +1034,12 @@ func (o *orderState) stmt(n ir.Node) {
n := n.(*ir.SwitchStmt) n := n.(*ir.SwitchStmt)
if base.Debug.Libfuzzer != 0 && !hasDefaultCase(n) { if base.Debug.Libfuzzer != 0 && !hasDefaultCase(n) {
// Add empty "default:" case for instrumentation. // Add empty "default:" case for instrumentation.
n.Cases.Append(ir.NewCaseStmt(base.Pos, nil, nil)) n.Cases = append(n.Cases, ir.NewCaseStmt(base.Pos, nil, nil))
} }
t := o.markTemp() t := o.markTemp()
n.Tag = o.expr(n.Tag, nil) n.Tag = o.expr(n.Tag, nil)
for _, ncas := range n.Cases { for _, ncas := range n.Cases {
ncas := ncas.(*ir.CaseStmt)
o.exprListInPlace(ncas.List) o.exprListInPlace(ncas.List)
orderBlock(&ncas.Body, o.free) orderBlock(&ncas.Body, o.free)
} }
@ -1056,7 +1053,6 @@ func (o *orderState) stmt(n ir.Node) {
func hasDefaultCase(n *ir.SwitchStmt) bool { func hasDefaultCase(n *ir.SwitchStmt) bool {
for _, ncas := range n.Cases { for _, ncas := range n.Cases {
ncas := ncas.(*ir.CaseStmt)
if len(ncas.List) == 0 { if len(ncas.List) == 0 {
return true return true
} }

View File

@ -21,7 +21,7 @@ func walkSelect(sel *ir.SelectStmt) {
sel.PtrInit().Set(nil) sel.PtrInit().Set(nil)
init = append(init, walkSelectCases(sel.Cases)...) init = append(init, walkSelectCases(sel.Cases)...)
sel.Cases = ir.Nodes{} sel.Cases = nil
sel.Compiled.Set(init) sel.Compiled.Set(init)
walkStmtList(sel.Compiled) walkStmtList(sel.Compiled)
@ -29,7 +29,7 @@ func walkSelect(sel *ir.SelectStmt) {
base.Pos = lno base.Pos = lno
} }
func walkSelectCases(cases ir.Nodes) []ir.Node { func walkSelectCases(cases []*ir.CaseStmt) []ir.Node {
ncas := len(cases) ncas := len(cases)
sellineno := base.Pos sellineno := base.Pos
@ -40,7 +40,7 @@ func walkSelectCases(cases ir.Nodes) []ir.Node {
// optimization: one-case select: single op. // optimization: one-case select: single op.
if ncas == 1 { if ncas == 1 {
cas := cases[0].(*ir.CaseStmt) cas := cases[0]
ir.SetPos(cas) ir.SetPos(cas)
l := cas.Init() l := cas.Init()
if cas.Comm != nil { // not default: if cas.Comm != nil { // not default:
@ -75,7 +75,6 @@ func walkSelectCases(cases ir.Nodes) []ir.Node {
// this rewrite is used by both the general code and the next optimization. // this rewrite is used by both the general code and the next optimization.
var dflt *ir.CaseStmt var dflt *ir.CaseStmt
for _, cas := range cases { for _, cas := range cases {
cas := cas.(*ir.CaseStmt)
ir.SetPos(cas) ir.SetPos(cas)
n := cas.Comm n := cas.Comm
if n == nil { if n == nil {
@ -99,9 +98,9 @@ func walkSelectCases(cases ir.Nodes) []ir.Node {
// optimization: two-case select but one is default: single non-blocking op. // optimization: two-case select but one is default: single non-blocking op.
if ncas == 2 && dflt != nil { if ncas == 2 && dflt != nil {
cas := cases[0].(*ir.CaseStmt) cas := cases[0]
if cas == dflt { if cas == dflt {
cas = cases[1].(*ir.CaseStmt) cas = cases[1]
} }
n := cas.Comm n := cas.Comm
@ -170,7 +169,6 @@ func walkSelectCases(cases ir.Nodes) []ir.Node {
// register cases // register cases
for _, cas := range cases { for _, cas := range cases {
cas := cas.(*ir.CaseStmt)
ir.SetPos(cas) ir.SetPos(cas)
init = append(init, cas.Init()...) init = append(init, cas.Init()...)

View File

@ -71,7 +71,6 @@ func walkSwitchExpr(sw *ir.SwitchStmt) {
var defaultGoto ir.Node var defaultGoto ir.Node
var body ir.Nodes var body ir.Nodes
for _, ncase := range sw.Cases { for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
label := typecheck.AutoLabel(".s") label := typecheck.AutoLabel(".s")
jmp := ir.NewBranchStmt(ncase.Pos(), ir.OGOTO, label) jmp := ir.NewBranchStmt(ncase.Pos(), ir.OGOTO, label)
@ -96,7 +95,7 @@ func walkSwitchExpr(sw *ir.SwitchStmt) {
body.Append(br) body.Append(br)
} }
} }
sw.Cases.Set(nil) sw.Cases = nil
if defaultGoto == nil { if defaultGoto == nil {
br := ir.NewBranchStmt(base.Pos, ir.OBREAK, nil) br := ir.NewBranchStmt(base.Pos, ir.OBREAK, nil)
@ -259,7 +258,6 @@ func allCaseExprsAreSideEffectFree(sw *ir.SwitchStmt) bool {
// enough. // enough.
for _, ncase := range sw.Cases { for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
for _, v := range ncase.List { for _, v := range ncase.List {
if v.Op() != ir.OLITERAL { if v.Op() != ir.OLITERAL {
return false return false
@ -325,7 +323,6 @@ func walkSwitchType(sw *ir.SwitchStmt) {
var defaultGoto, nilGoto ir.Node var defaultGoto, nilGoto ir.Node
var body ir.Nodes var body ir.Nodes
for _, ncase := range sw.Cases { for _, ncase := range sw.Cases {
ncase := ncase.(*ir.CaseStmt)
caseVar := ncase.Var caseVar := ncase.Var
// For single-type cases with an interface type, // For single-type cases with an interface type,
@ -384,7 +381,7 @@ func walkSwitchType(sw *ir.SwitchStmt) {
body.Append(ncase.Body...) body.Append(ncase.Body...)
body.Append(br) body.Append(br)
} }
sw.Cases.Set(nil) sw.Cases = nil
if defaultGoto == nil { if defaultGoto == nil {
defaultGoto = br defaultGoto = br