Commit 83f0af17 authored by Daniel Martí's avatar Daniel Martí

cmd/compile: remove a few unnecessary gotos

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