]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: remove a few unnecessary gotos
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 12 Sep 2017 20:51:17 +0000 (22:51 +0200)
committerDaniel Martí <mvdan@mvdan.cc>
Fri, 22 Sep 2017 16:55:47 +0000 (16:55 +0000)
Rework the logic to remove them. These were the low hanging fruit,
with labels that were used only once and logic that was fairly
straightforward.

Change-Id: I02a01c59c247b8b2972d8d73ff23f96f271de038
Reviewed-on: https://go-review.googlesource.com/63410
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/reflect.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index d268c89e69a057e1b5e4615db49a623ae504244f..0023f65a10d497560bf50086e3d87ce2433581d8 100644 (file)
@@ -1165,19 +1165,17 @@ func dtypesym(t *types.Type) *types.Sym {
                dupok = obj.DUPOK
        }
 
-       if myimportpath == "runtime" && (tbase == types.Types[tbase.Etype] || tbase == types.Bytetype || tbase == types.Runetype || tbase == types.Errortype) { // int, float, etc
-               goto ok
-       }
-
-       // named types from other files are defined only by those files
-       if tbase.Sym != nil && !tbase.Local() {
-               return s
-       }
-       if isforw[tbase.Etype] {
-               return s
+       if myimportpath != "runtime" || (tbase != types.Types[tbase.Etype] && tbase != types.Bytetype && tbase != types.Runetype && tbase != types.Errortype) { // int, float, etc
+               // named types from other files are defined only by those files
+               if tbase.Sym != nil && !tbase.Local() {
+                       return s
+               }
+               // TODO(mdempsky): Investigate whether this can happen.
+               if isforw[tbase.Etype] {
+                       return s
+               }
        }
 
-ok:
        ot := 0
        lsym := s.Linksym()
        switch t.Etype {
index 647694d68a43f7bfd770466bd5e016ca10e63a58..08658af603a9488743f2b3d7fdbd548f41d2ca2c 100644 (file)
@@ -1847,11 +1847,12 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
        // and then do one loop.
 
        if t.IsInterface() {
+       Outer:
                for _, im := range iface.Fields().Slice() {
                        for _, tm := range t.Fields().Slice() {
                                if tm.Sym == im.Sym {
                                        if eqtype(tm.Type, im.Type) {
-                                               goto found
+                                               continue Outer
                                        }
                                        *m = im
                                        *samename = tm
@@ -1864,7 +1865,6 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
                        *samename = nil
                        *ptr = 0
                        return false
-               found:
                }
 
                return true
index 23fdb3486e2bb1b369305877d002932a29e29114..af4e33d2fb4423c2ffcd003efa2636a1a0c6d34f 100644 (file)
@@ -621,6 +621,7 @@ func typecheck1(n *Node, top int) *Node {
                        // the only conversion that isn't a no-op is concrete == interface.
                        // in that case, check comparability of the concrete type.
                        // The conversion allocates, so only do it if the concrete type is huge.
+                       converted := false
                        if r.Type.Etype != TBLANK {
                                aop = assignop(l.Type, r.Type, nil)
                                if aop != 0 {
@@ -639,11 +640,11 @@ func typecheck1(n *Node, top int) *Node {
                                        }
 
                                        t = r.Type
-                                       goto converted
+                                       converted = true
                                }
                        }
 
-                       if l.Type.Etype != TBLANK {
+                       if !converted && l.Type.Etype != TBLANK {
                                aop = assignop(r.Type, l.Type, nil)
                                if aop != 0 {
                                        if l.Type.IsInterface() && !r.Type.IsInterface() && !IsComparable(r.Type) {
@@ -664,7 +665,6 @@ func typecheck1(n *Node, top int) *Node {
                                }
                        }
 
-               converted:
                        et = t.Etype
                }
 
index b0c98eea8389a6badf33b0c28a2b097262c0647c..393842d67687941599c21347c607dd3f752e8038 100644 (file)
@@ -1999,8 +1999,6 @@ func mkdotargslice(typ *types.Type, args []*Node, init *Nodes, ddd *Node) *Node
 //     return expr-list
 //     func(expr-list)
 func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, init *Nodes) []*Node {
-       var nn []*Node
-
        // f(g()) where g has multiple return values
        if len(rhs) == 1 && rhs[0].Type.IsFuncArgStruct() {
                // optimization - can do block copy
@@ -2008,8 +2006,9 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
                        nl := nodarg(lhs, fp)
                        nr := nod(OCONVNOP, rhs[0], nil)
                        nr.Type = nl.Type
-                       nn = []*Node{convas(nod(OAS, nl, nr), init)}
-                       goto ret
+                       n := convas(nod(OAS, nl, nr), init)
+                       n.SetTypecheck(1)
+                       return []*Node{n}
                }
 
                // conversions involved.
@@ -2033,6 +2032,7 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
        // If there's a ... parameter (which is only valid as the final
        // parameter) and this is not a ... call expression,
        // then assign the remaining arguments as a slice.
+       var nn []*Node
        for i, nl := range lhs.FieldSlice() {
                var nr *Node
                if nl.Isddd() && !isddd {
@@ -2043,13 +2043,10 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
 
                a := nod(OAS, nodarg(nl, fp), nr)
                a = convas(a, init)
+               a.SetTypecheck(1)
                nn = append(nn, a)
        }
 
-ret:
-       for _, n := range nn {
-               n.SetTypecheck(1)
-       }
        return nn
 }