mirror of
https://github.com/golang/go
synced 2024-11-20 03:14:43 -07:00
cmd/compile: refactor some more gotos away
The ones in racewalk.go are almost all useless, since they were just breaks. typecheck.go wasn't trivial, but still doable with an if/else chain. Also remove a single silly goto in const.go, while at it. Change-Id: I776a78df6bb3b6bd4f7e5feec546c772baf4e02e Reviewed-on: https://go-review.googlesource.com/65652 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
8598396d81
commit
0168fdb552
@ -1195,8 +1195,6 @@ func evconst(n *Node) {
|
|||||||
goto setfalse
|
goto setfalse
|
||||||
}
|
}
|
||||||
|
|
||||||
goto ret
|
|
||||||
|
|
||||||
ret:
|
ret:
|
||||||
norig = saveorig(n)
|
norig = saveorig(n)
|
||||||
*n = *nl
|
*n = *nl
|
||||||
|
@ -140,11 +140,9 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
case OAS, OAS2FUNC:
|
case OAS, OAS2FUNC:
|
||||||
instrumentnode(&n.Left, init, 1, 0)
|
instrumentnode(&n.Left, init, 1, 0)
|
||||||
instrumentnode(&n.Right, init, 0, 0)
|
instrumentnode(&n.Right, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
// can't matter
|
// can't matter
|
||||||
case OCFUNC, OVARKILL, OVARLIVE:
|
case OCFUNC, OVARKILL, OVARLIVE:
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OBLOCK:
|
case OBLOCK:
|
||||||
ls := n.List.Slice()
|
ls := n.List.Slice()
|
||||||
@ -162,26 +160,21 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
instrumentnode(&ls[i], &ls[i].Ninit, 0, 0)
|
instrumentnode(&ls[i], &ls[i].Ninit, 0, 0)
|
||||||
afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER)
|
afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER)
|
||||||
}
|
}
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODEFER:
|
case ODEFER:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OPROC:
|
case OPROC:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OCALLINTER:
|
case OCALLINTER:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
// Instrument dst argument of runtime.writebarrier* calls
|
// Instrument dst argument of runtime.writebarrier* calls
|
||||||
// as we do not instrument runtime code.
|
// as we do not instrument runtime code.
|
||||||
// typedslicecopy is instrumented in runtime.
|
// typedslicecopy is instrumented in runtime.
|
||||||
case OCALLFUNC:
|
case OCALLFUNC:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ONOT,
|
case ONOT,
|
||||||
OMINUS,
|
OMINUS,
|
||||||
@ -190,28 +183,23 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
OIMAG,
|
OIMAG,
|
||||||
OCOM:
|
OCOM:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODOTINTER:
|
case ODOTINTER:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODOT:
|
case ODOT:
|
||||||
instrumentnode(&n.Left, init, 0, 1)
|
instrumentnode(&n.Left, init, 0, 1)
|
||||||
callinstr(&n, init, wr, skip)
|
callinstr(&n, init, wr, skip)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
|
case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
|
|
||||||
callinstr(&n, init, wr, skip)
|
callinstr(&n, init, wr, skip)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OIND: // *p
|
case OIND: // *p
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
|
|
||||||
callinstr(&n, init, wr, skip)
|
callinstr(&n, init, wr, skip)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OSPTR, OLEN, OCAP:
|
case OSPTR, OLEN, OCAP:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
@ -223,8 +211,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
callinstr(&n1, init, 0, skip)
|
callinstr(&n1, init, 0, skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OLSH,
|
case OLSH,
|
||||||
ORSH,
|
ORSH,
|
||||||
OAND,
|
OAND,
|
||||||
@ -243,7 +229,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
OCOMPLEX:
|
OCOMPLEX:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
instrumentnode(&n.Right, init, wr, 0)
|
instrumentnode(&n.Right, init, wr, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OANDAND, OOROR:
|
case OANDAND, OOROR:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
@ -254,24 +239,18 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
// so instrumentation goes to n->right->ninit, not init.
|
// so instrumentation goes to n->right->ninit, not init.
|
||||||
instrumentnode(&n.Right, &n.Right.Ninit, wr, 0)
|
instrumentnode(&n.Right, &n.Right.Ninit, wr, 0)
|
||||||
|
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ONAME:
|
case ONAME:
|
||||||
callinstr(&n, init, wr, skip)
|
callinstr(&n, init, wr, skip)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OCONV:
|
case OCONV:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OCONVNOP:
|
case OCONVNOP:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODIV, OMOD:
|
case ODIV, OMOD:
|
||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
instrumentnode(&n.Right, init, wr, 0)
|
instrumentnode(&n.Right, init, wr, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OINDEX:
|
case OINDEX:
|
||||||
if !n.Left.Type.IsArray() {
|
if !n.Left.Type.IsArray() {
|
||||||
@ -281,14 +260,13 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
instrumentnode(&n.Left, init, wr, 0)
|
instrumentnode(&n.Left, init, wr, 0)
|
||||||
|
|
||||||
instrumentnode(&n.Right, init, 0, 0)
|
instrumentnode(&n.Right, init, 0, 0)
|
||||||
goto ret
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
instrumentnode(&n.Right, init, 0, 0)
|
instrumentnode(&n.Right, init, 0, 0)
|
||||||
if !n.Left.Type.IsString() {
|
if !n.Left.Type.IsString() {
|
||||||
callinstr(&n, init, wr, skip)
|
callinstr(&n, init, wr, skip)
|
||||||
}
|
}
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
|
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
@ -297,34 +275,26 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
instrumentnode(&high, init, 0, 0)
|
instrumentnode(&high, init, 0, 0)
|
||||||
instrumentnode(&max, init, 0, 0)
|
instrumentnode(&max, init, 0, 0)
|
||||||
n.SetSliceBounds(low, high, max)
|
n.SetSliceBounds(low, high, max)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OADDR:
|
case OADDR:
|
||||||
instrumentnode(&n.Left, init, 0, 1)
|
instrumentnode(&n.Left, init, 0, 1)
|
||||||
goto ret
|
|
||||||
|
|
||||||
// n->left is Type* which is not interesting.
|
// n->left is Type* which is not interesting.
|
||||||
case OEFACE:
|
case OEFACE:
|
||||||
instrumentnode(&n.Right, init, 0, 0)
|
instrumentnode(&n.Right, init, 0, 0)
|
||||||
|
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OITAB, OIDATA:
|
case OITAB, OIDATA:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OSTRARRAYBYTETMP:
|
case OSTRARRAYBYTETMP:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OAS2DOTTYPE:
|
case OAS2DOTTYPE:
|
||||||
instrumentnode(&n.Left, init, 1, 0)
|
instrumentnode(&n.Left, init, 1, 0)
|
||||||
instrumentnode(&n.Right, init, 0, 0)
|
instrumentnode(&n.Right, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
case ODOTTYPE, ODOTTYPE2:
|
case ODOTTYPE, ODOTTYPE2:
|
||||||
instrumentnode(&n.Left, init, 0, 0)
|
instrumentnode(&n.Left, init, 0, 0)
|
||||||
goto ret
|
|
||||||
|
|
||||||
// should not appear in AST by now
|
// should not appear in AST by now
|
||||||
case OSEND,
|
case OSEND,
|
||||||
@ -376,13 +346,11 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
if n.Right != nil {
|
if n.Right != nil {
|
||||||
instrumentnode(&n.Right, &n.Right.Ninit, 0, 0)
|
instrumentnode(&n.Right, &n.Right.Ninit, 0, 0)
|
||||||
}
|
}
|
||||||
goto ret
|
|
||||||
|
|
||||||
case OIF, OSWITCH:
|
case OIF, OSWITCH:
|
||||||
if n.Left != nil {
|
if n.Left != nil {
|
||||||
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0)
|
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0)
|
||||||
}
|
}
|
||||||
goto ret
|
|
||||||
|
|
||||||
// just do generic traversal
|
// just do generic traversal
|
||||||
case OCALLMETH,
|
case OCALLMETH,
|
||||||
@ -395,7 +363,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
OFALL,
|
OFALL,
|
||||||
OGOTO,
|
OGOTO,
|
||||||
OLABEL:
|
OLABEL:
|
||||||
goto ret
|
|
||||||
|
|
||||||
// does not require instrumentation
|
// does not require instrumentation
|
||||||
case OPRINT, // don't bother instrumenting it
|
case OPRINT, // don't bother instrumenting it
|
||||||
@ -411,10 +378,8 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
|
|||||||
ONONAME,
|
ONONAME,
|
||||||
OLITERAL,
|
OLITERAL,
|
||||||
OTYPESW: // ignored by code generation, do not instrument.
|
OTYPESW: // ignored by code generation, do not instrument.
|
||||||
goto ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret:
|
|
||||||
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
|
||||||
instrumentlist(n.List, init)
|
instrumentlist(n.List, init)
|
||||||
}
|
}
|
||||||
|
@ -3576,19 +3576,14 @@ func typecheckdeftype(n *Node) {
|
|||||||
if t == nil {
|
if t == nil {
|
||||||
n.SetDiag(true)
|
n.SetDiag(true)
|
||||||
n.Type = nil
|
n.Type = nil
|
||||||
goto ret
|
} else if n.Type == nil {
|
||||||
}
|
|
||||||
|
|
||||||
if n.Type == nil {
|
|
||||||
n.SetDiag(true)
|
n.SetDiag(true)
|
||||||
goto ret
|
} else {
|
||||||
|
// copy new type and clear fields
|
||||||
|
// that don't come along.
|
||||||
|
copytype(n, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy new type and clear fields
|
|
||||||
// that don't come along.
|
|
||||||
copytype(n, t)
|
|
||||||
|
|
||||||
ret:
|
|
||||||
lineno = lno
|
lineno = lno
|
||||||
|
|
||||||
// if there are no type definitions going on, it's safe to
|
// if there are no type definitions going on, it's safe to
|
||||||
|
Loading…
Reference in New Issue
Block a user