Skip to content

Commit 0168fdb

Browse files
committed
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í <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 8598396 commit 0168fdb

File tree

3 files changed

+6
-48
lines changed

3 files changed

+6
-48
lines changed

src/cmd/compile/internal/gc/const.go

-2
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,6 @@ func evconst(n *Node) {
11951195
goto setfalse
11961196
}
11971197

1198-
goto ret
1199-
12001198
ret:
12011199
norig = saveorig(n)
12021200
*n = *nl

src/cmd/compile/internal/gc/racewalk.go

+1-36
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
140140
case OAS, OAS2FUNC:
141141
instrumentnode(&n.Left, init, 1, 0)
142142
instrumentnode(&n.Right, init, 0, 0)
143-
goto ret
144143

145144
// can't matter
146145
case OCFUNC, OVARKILL, OVARLIVE:
147-
goto ret
148146

149147
case OBLOCK:
150148
ls := n.List.Slice()
@@ -162,26 +160,21 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
162160
instrumentnode(&ls[i], &ls[i].Ninit, 0, 0)
163161
afterCall = (op == OCALLFUNC || op == OCALLMETH || op == OCALLINTER)
164162
}
165-
goto ret
166163

167164
case ODEFER:
168165
instrumentnode(&n.Left, init, 0, 0)
169-
goto ret
170166

171167
case OPROC:
172168
instrumentnode(&n.Left, init, 0, 0)
173-
goto ret
174169

175170
case OCALLINTER:
176171
instrumentnode(&n.Left, init, 0, 0)
177-
goto ret
178172

179173
// Instrument dst argument of runtime.writebarrier* calls
180174
// as we do not instrument runtime code.
181175
// typedslicecopy is instrumented in runtime.
182176
case OCALLFUNC:
183177
instrumentnode(&n.Left, init, 0, 0)
184-
goto ret
185178

186179
case ONOT,
187180
OMINUS,
@@ -190,28 +183,23 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
190183
OIMAG,
191184
OCOM:
192185
instrumentnode(&n.Left, init, wr, 0)
193-
goto ret
194186

195187
case ODOTINTER:
196188
instrumentnode(&n.Left, init, 0, 0)
197-
goto ret
198189

199190
case ODOT:
200191
instrumentnode(&n.Left, init, 0, 1)
201192
callinstr(&n, init, wr, skip)
202-
goto ret
203193

204194
case ODOTPTR: // dst = (*x).f with implicit *; otherwise it's ODOT+OIND
205195
instrumentnode(&n.Left, init, 0, 0)
206196

207197
callinstr(&n, init, wr, skip)
208-
goto ret
209198

210199
case OIND: // *p
211200
instrumentnode(&n.Left, init, 0, 0)
212201

213202
callinstr(&n, init, wr, skip)
214-
goto ret
215203

216204
case OSPTR, OLEN, OCAP:
217205
instrumentnode(&n.Left, init, 0, 0)
@@ -223,8 +211,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
223211
callinstr(&n1, init, 0, skip)
224212
}
225213

226-
goto ret
227-
228214
case OLSH,
229215
ORSH,
230216
OAND,
@@ -243,7 +229,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
243229
OCOMPLEX:
244230
instrumentnode(&n.Left, init, wr, 0)
245231
instrumentnode(&n.Right, init, wr, 0)
246-
goto ret
247232

248233
case OANDAND, OOROR:
249234
instrumentnode(&n.Left, init, wr, 0)
@@ -254,24 +239,18 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
254239
// so instrumentation goes to n->right->ninit, not init.
255240
instrumentnode(&n.Right, &n.Right.Ninit, wr, 0)
256241

257-
goto ret
258-
259242
case ONAME:
260243
callinstr(&n, init, wr, skip)
261-
goto ret
262244

263245
case OCONV:
264246
instrumentnode(&n.Left, init, wr, 0)
265-
goto ret
266247

267248
case OCONVNOP:
268249
instrumentnode(&n.Left, init, wr, 0)
269-
goto ret
270250

271251
case ODIV, OMOD:
272252
instrumentnode(&n.Left, init, wr, 0)
273253
instrumentnode(&n.Right, init, wr, 0)
274-
goto ret
275254

276255
case OINDEX:
277256
if !n.Left.Type.IsArray() {
@@ -281,14 +260,13 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
281260
instrumentnode(&n.Left, init, wr, 0)
282261

283262
instrumentnode(&n.Right, init, 0, 0)
284-
goto ret
263+
break
285264
}
286265

287266
instrumentnode(&n.Right, init, 0, 0)
288267
if !n.Left.Type.IsString() {
289268
callinstr(&n, init, wr, skip)
290269
}
291-
goto ret
292270

293271
case OSLICE, OSLICEARR, OSLICE3, OSLICE3ARR, OSLICESTR:
294272
instrumentnode(&n.Left, init, 0, 0)
@@ -297,34 +275,26 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
297275
instrumentnode(&high, init, 0, 0)
298276
instrumentnode(&max, init, 0, 0)
299277
n.SetSliceBounds(low, high, max)
300-
goto ret
301278

302279
case OADDR:
303280
instrumentnode(&n.Left, init, 0, 1)
304-
goto ret
305281

306282
// n->left is Type* which is not interesting.
307283
case OEFACE:
308284
instrumentnode(&n.Right, init, 0, 0)
309285

310-
goto ret
311-
312286
case OITAB, OIDATA:
313287
instrumentnode(&n.Left, init, 0, 0)
314-
goto ret
315288

316289
case OSTRARRAYBYTETMP:
317290
instrumentnode(&n.Left, init, 0, 0)
318-
goto ret
319291

320292
case OAS2DOTTYPE:
321293
instrumentnode(&n.Left, init, 1, 0)
322294
instrumentnode(&n.Right, init, 0, 0)
323-
goto ret
324295

325296
case ODOTTYPE, ODOTTYPE2:
326297
instrumentnode(&n.Left, init, 0, 0)
327-
goto ret
328298

329299
// should not appear in AST by now
330300
case OSEND,
@@ -376,13 +346,11 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
376346
if n.Right != nil {
377347
instrumentnode(&n.Right, &n.Right.Ninit, 0, 0)
378348
}
379-
goto ret
380349

381350
case OIF, OSWITCH:
382351
if n.Left != nil {
383352
instrumentnode(&n.Left, &n.Left.Ninit, 0, 0)
384353
}
385-
goto ret
386354

387355
// just do generic traversal
388356
case OCALLMETH,
@@ -395,7 +363,6 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
395363
OFALL,
396364
OGOTO,
397365
OLABEL:
398-
goto ret
399366

400367
// does not require instrumentation
401368
case OPRINT, // don't bother instrumenting it
@@ -411,10 +378,8 @@ func instrumentnode(np **Node, init *Nodes, wr int, skip int) {
411378
ONONAME,
412379
OLITERAL,
413380
OTYPESW: // ignored by code generation, do not instrument.
414-
goto ret
415381
}
416382

417-
ret:
418383
if n.Op != OBLOCK { // OBLOCK is handled above in a special way.
419384
instrumentlist(n.List, init)
420385
}

src/cmd/compile/internal/gc/typecheck.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -3576,19 +3576,14 @@ func typecheckdeftype(n *Node) {
35763576
if t == nil {
35773577
n.SetDiag(true)
35783578
n.Type = nil
3579-
goto ret
3580-
}
3581-
3582-
if n.Type == nil {
3579+
} else if n.Type == nil {
35833580
n.SetDiag(true)
3584-
goto ret
3581+
} else {
3582+
// copy new type and clear fields
3583+
// that don't come along.
3584+
copytype(n, t)
35853585
}
35863586

3587-
// copy new type and clear fields
3588-
// that don't come along.
3589-
copytype(n, t)
3590-
3591-
ret:
35923587
lineno = lno
35933588

35943589
// if there are no type definitions going on, it's safe to

0 commit comments

Comments
 (0)