From 0168fdb5520c0a77e9a27822caf307e739d4142a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Sat, 23 Sep 2017 19:39:08 +0100 Subject: [PATCH] cmd/compile: refactor some more gotos away MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 2 -- src/cmd/compile/internal/gc/racewalk.go | 37 +----------------------- src/cmd/compile/internal/gc/typecheck.go | 15 ++++------ 3 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 6fede5fd30..4d52d091b0 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -1195,8 +1195,6 @@ func evconst(n *Node) { goto setfalse } - goto ret - ret: norig = saveorig(n) *n = *nl diff --git a/src/cmd/compile/internal/gc/racewalk.go b/src/cmd/compile/internal/gc/racewalk.go index 79b6b8f40d..4a4c4126c0 100644 --- a/src/cmd/compile/internal/gc/racewalk.go +++ b/src/cmd/compile/internal/gc/racewalk.go @@ -140,11 +140,9 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { case OAS, OAS2FUNC: instrumentnode(&n.Left, init, 1, 0) instrumentnode(&n.Right, init, 0, 0) - goto ret // can't matter case OCFUNC, OVARKILL, OVARLIVE: - goto ret case OBLOCK: 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) afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER) } - goto ret case ODEFER: instrumentnode(&n.Left, init, 0, 0) - goto ret case OPROC: instrumentnode(&n.Left, init, 0, 0) - goto ret case OCALLINTER: instrumentnode(&n.Left, init, 0, 0) - goto ret // Instrument dst argument of runtime.writebarrier* calls // as we do not instrument runtime code. // typedslicecopy is instrumented in runtime. case OCALLFUNC: instrumentnode(&n.Left, init, 0, 0) - goto ret case ONOT, OMINUS, @@ -190,28 +183,23 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { OIMAG, OCOM: instrumentnode(&n.Left, init, wr, 0) - goto ret case ODOTINTER: instrumentnode(&n.Left, init, 0, 0) - goto ret case ODOT: instrumentnode(&n.Left, init, 0, 1) callinstr(&n, init, wr, skip) - goto ret case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND instrumentnode(&n.Left, init, 0, 0) callinstr(&n, init, wr, skip) - goto ret case OIND: // *p instrumentnode(&n.Left, init, 0, 0) callinstr(&n, init, wr, skip) - goto ret case OSPTR, OLEN, OCAP: 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) } - goto ret - case OLSH, ORSH, OAND, @@ -243,7 +229,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { OCOMPLEX: instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Right, init, wr, 0) - goto ret case OANDAND, OOROR: 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. instrumentnode(&n.Right, &n.Right.Ninit, wr, 0) - goto ret - case ONAME: callinstr(&n, init, wr, skip) - goto ret case OCONV: instrumentnode(&n.Left, init, wr, 0) - goto ret case OCONVNOP: instrumentnode(&n.Left, init, wr, 0) - goto ret case ODIV, OMOD: instrumentnode(&n.Left, init, wr, 0) instrumentnode(&n.Right, init, wr, 0) - goto ret case OINDEX: 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.Right, init, 0, 0) - goto ret + break } instrumentnode(&n.Right, init, 0, 0) if !n.Left.Type.IsString() { callinstr(&n, init, wr, skip) } - goto ret case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR: 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(&max, init, 0, 0) n.SetSliceBounds(low, high, max) - goto ret case OADDR: instrumentnode(&n.Left, init, 0, 1) - goto ret // n->left is Type* which is not interesting. case OEFACE: instrumentnode(&n.Right, init, 0, 0) - goto ret - case OITAB, OIDATA: instrumentnode(&n.Left, init, 0, 0) - goto ret case OSTRARRAYBYTETMP: instrumentnode(&n.Left, init, 0, 0) - goto ret case OAS2DOTTYPE: instrumentnode(&n.Left, init, 1, 0) instrumentnode(&n.Right, init, 0, 0) - goto ret case ODOTTYPE, ODOTTYPE2: instrumentnode(&n.Left, init, 0, 0) - goto ret // should not appear in AST by now case OSEND, @@ -376,13 +346,11 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { if n.Right != nil { instrumentnode(&n.Right, &n.Right.Ninit, 0, 0) } - goto ret case OIF, OSWITCH: if n.Left != nil { instrumentnode(&n.Left, &n.Left.Ninit, 0, 0) } - goto ret // just do generic traversal case OCALLMETH, @@ -395,7 +363,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { OFALL, OGOTO, OLABEL: - goto ret // does not require instrumentation case OPRINT, // don't bother instrumenting it @@ -411,10 +378,8 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) { ONONAME, OLITERAL, OTYPESW: // ignored by code generation, do not instrument. - goto ret } -ret: if n.Op != OBLOCK { // OBLOCK is handled above in a special way. instrumentlist(n.List, init) } diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index af4e33d2fb..3f14b9340c 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3576,19 +3576,14 @@ func typecheckdeftype(n *Node) { if t == nil { n.SetDiag(true) n.Type = nil - goto ret - } - - if n.Type == nil { + } else if n.Type == nil { 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 // if there are no type definitions going on, it's safe to -- 2.48.1