Commit 3366f515 authored by Daniel Martí's avatar Daniel Martí

cmd/compile: tweaks to unindent some code

Prioritized the chunks of code with 8 or more levels of indentation.
Basically early breaks/returns and joining nested ifs.

Change-Id: I6817df1303226acf2eb904a29f2db720e4f7427a
Reviewed-on: https://go-review.googlesource.com/55630
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarJosh Bleecher Snyder <josharian@gmail.com>
parent 064ae118
...@@ -463,9 +463,8 @@ func walkclosure(func_ *Node, init *Nodes) *Node { ...@@ -463,9 +463,8 @@ func walkclosure(func_ *Node, init *Nodes) *Node {
Warnl(func_.Pos, "closure converted to global") Warnl(func_.Pos, "closure converted to global")
} }
return func_.Func.Closure.Func.Nname return func_.Func.Closure.Func.Nname
} else {
closuredebugruntimecheck(func_)
} }
closuredebugruntimecheck(func_)
// Create closure in the form of a composite literal. // Create closure in the form of a composite literal.
// supposing the closure captures an int i and a string s // supposing the closure captures an int i and a string s
......
...@@ -1554,20 +1554,20 @@ func (e *EscState) esccall(call *Node, parent *Node) { ...@@ -1554,20 +1554,20 @@ func (e *EscState) esccall(call *Node, parent *Node) {
call.Right = arg call.Right = arg
} }
e.escassignWhyWhere(n, arg, "arg to recursive call", call) // TODO this message needs help. e.escassignWhyWhere(n, arg, "arg to recursive call", call) // TODO this message needs help.
if arg != args[0] { if arg == args[0] {
// "..." arguments are untracked args = args[1:]
for _, a := range args {
if Debug['m'] > 3 {
fmt.Printf("%v::esccall:: ... <- %S, untracked\n", linestr(lineno), a)
}
e.escassignSinkWhyWhere(arg, a, "... arg to recursive call", call)
}
// No more PPARAM processing, but keep
// going for PPARAMOUT.
args = nil
continue continue
} }
args = args[1:] // "..." arguments are untracked
for _, a := range args {
if Debug['m'] > 3 {
fmt.Printf("%v::esccall:: ... <- %S, untracked\n", linestr(lineno), a)
}
e.escassignSinkWhyWhere(arg, a, "... arg to recursive call", call)
}
// No more PPARAM processing, but keep
// going for PPARAMOUT.
args = nil
case PPARAMOUT: case PPARAMOUT:
cE.Retval.Append(n) cE.Retval.Append(n)
......
...@@ -233,24 +233,25 @@ func (s *phiState) insertVarPhis(n int, var_ *Node, defs []*ssa.Block, typ *type ...@@ -233,24 +233,25 @@ func (s *phiState) insertVarPhis(n int, var_ *Node, defs []*ssa.Block, typ *type
// a D-edge, or an edge whose target is in currentRoot's subtree. // a D-edge, or an edge whose target is in currentRoot's subtree.
continue continue
} }
if !hasPhi.contains(c.ID) { if hasPhi.contains(c.ID) {
// Add a phi to block c for variable n. continue
hasPhi.add(c.ID) }
v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right? // Add a phi to block c for variable n.
// Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building. hasPhi.add(c.ID)
s.s.addNamedValue(var_, v) v := c.NewValue0I(currentRoot.Pos, ssa.OpPhi, typ, int64(n)) // TODO: line number right?
for i := 0; i < len(c.Preds); i++ { // Note: we store the variable number in the phi's AuxInt field. Used temporarily by phi building.
v.AddArg(s.placeholder) // Actual args will be filled in by resolveFwdRefs. s.s.addNamedValue(var_, v)
} for i := 0; i < len(c.Preds); i++ {
if debugPhi { v.AddArg(s.placeholder) // Actual args will be filled in by resolveFwdRefs.
fmt.Printf("new phi for var%d in %s: %s\n", n, c, v) }
} if debugPhi {
if !hasDef.contains(c.ID) { fmt.Printf("new phi for var%d in %s: %s\n", n, c, v)
// There's now a new definition of this variable in block c. }
// Add it to the priority queue to explore. if !hasDef.contains(c.ID) {
heap.Push(priq, c) // There's now a new definition of this variable in block c.
hasDef.add(c.ID) // Add it to the priority queue to explore.
} heap.Push(priq, c)
hasDef.add(c.ID)
} }
} }
......
...@@ -497,14 +497,12 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int { ...@@ -497,14 +497,12 @@ func dgopkgpathOff(s *obj.LSym, ot int, pkg *types.Pkg) int {
func isExportedField(ft *types.Field) (bool, *types.Pkg) { func isExportedField(ft *types.Field) (bool, *types.Pkg) {
if ft.Sym != nil && ft.Embedded == 0 { if ft.Sym != nil && ft.Embedded == 0 {
return exportname(ft.Sym.Name), ft.Sym.Pkg return exportname(ft.Sym.Name), ft.Sym.Pkg
} else {
if ft.Type.Sym != nil &&
(ft.Type.Sym.Pkg == builtinpkg || !exportname(ft.Type.Sym.Name)) {
return false, ft.Type.Sym.Pkg
} else {
return true, nil
}
} }
if ft.Type.Sym != nil &&
(ft.Type.Sym.Pkg == builtinpkg || !exportname(ft.Type.Sym.Name)) {
return false, ft.Type.Sym.Pkg
}
return true, nil
} }
// dnameField dumps a reflect.name for a struct field. // dnameField dumps a reflect.name for a struct field.
......
...@@ -480,9 +480,8 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { ...@@ -480,9 +480,8 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
n := *l n := *l
gdata(&n, r.Func.Closure.Func.Nname, Widthptr) gdata(&n, r.Func.Closure.Func.Nname, Widthptr)
return true return true
} else {
closuredebugruntimecheck(r)
} }
closuredebugruntimecheck(r)
case OCONVIFACE: case OCONVIFACE:
// This logic is mirrored in isStaticCompositeLiteral. // This logic is mirrored in isStaticCompositeLiteral.
......
...@@ -661,24 +661,26 @@ func (s *state) stmt(n *Node) { ...@@ -661,24 +661,26 @@ func (s *state) stmt(n *Node) {
} }
rhs = nil rhs = nil
case OAPPEND: case OAPPEND:
// If we're writing the result of an append back to the same slice, // Check whether we're writing the result of an append back to the same slice.
// handle it specially to avoid write barriers on the fast (non-growth) path. // If so, we handle it specially to avoid write barriers on the fast
// (non-growth) path.
if !samesafeexpr(n.Left, rhs.List.First()) {
break
}
// If the slice can be SSA'd, it'll be on the stack, // If the slice can be SSA'd, it'll be on the stack,
// so there will be no write barriers, // so there will be no write barriers,
// so there's no need to attempt to prevent them. // so there's no need to attempt to prevent them.
if samesafeexpr(n.Left, rhs.List.First()) { if s.canSSA(n.Left) {
if !s.canSSA(n.Left) { if Debug_append > 0 { // replicating old diagnostic message
if Debug_append > 0 { Warnl(n.Pos, "append: len-only update (in local slice)")
Warnl(n.Pos, "append: len-only update")
}
s.append(rhs, true)
return
} else {
if Debug_append > 0 { // replicating old diagnostic message
Warnl(n.Pos, "append: len-only update (in local slice)")
}
} }
break
}
if Debug_append > 0 {
Warnl(n.Pos, "append: len-only update")
} }
s.append(rhs, true)
return
} }
} }
......
...@@ -2636,54 +2636,52 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *types.Type, nl Nodes, ...@@ -2636,54 +2636,52 @@ func typecheckaste(op Op, call *Node, isddd bool, tstruct *types.Type, nl Nodes,
n = nil n = nil
if nl.Len() == 1 { if nl.Len() == 1 {
n = nl.First() n = nl.First()
if n.Type != nil { if n.Type != nil && n.Type.IsFuncArgStruct() {
if n.Type.IsFuncArgStruct() { if !hasddd(tstruct) {
if !hasddd(tstruct) { n1 := tstruct.NumFields()
n1 := tstruct.NumFields() n2 := n.Type.NumFields()
n2 := n.Type.NumFields() if n2 > n1 {
if n2 > n1 { goto toomany
goto toomany
}
if n2 < n1 {
goto notenough
}
} }
if n2 < n1 {
goto notenough
}
}
lfs := tstruct.FieldSlice() lfs := tstruct.FieldSlice()
rfs := n.Type.FieldSlice() rfs := n.Type.FieldSlice()
var why string var why string
for i, tl := range lfs { for i, tl := range lfs {
if tl.Isddd() { if tl.Isddd() {
for _, tn := range rfs[i:] { for _, tn := range rfs[i:] {
if assignop(tn.Type, tl.Type.Elem(), &why) == 0 { if assignop(tn.Type, tl.Type.Elem(), &why) == 0 {
if call != nil { if call != nil {
yyerror("cannot use %v as type %v in argument to %v%s", tn.Type, tl.Type.Elem(), call, why) yyerror("cannot use %v as type %v in argument to %v%s", tn.Type, tl.Type.Elem(), call, why)
} else { } else {
yyerror("cannot use %v as type %v in %s%s", tn.Type, tl.Type.Elem(), desc(), why) yyerror("cannot use %v as type %v in %s%s", tn.Type, tl.Type.Elem(), desc(), why)
}
} }
} }
goto out
} }
goto out
}
if i >= len(rfs) { if i >= len(rfs) {
goto notenough goto notenough
} }
tn := rfs[i] tn := rfs[i]
if assignop(tn.Type, tl.Type, &why) == 0 { if assignop(tn.Type, tl.Type, &why) == 0 {
if call != nil { if call != nil {
yyerror("cannot use %v as type %v in argument to %v%s", tn.Type, tl.Type, call, why) yyerror("cannot use %v as type %v in argument to %v%s", tn.Type, tl.Type, call, why)
} else { } else {
yyerror("cannot use %v as type %v in %s%s", tn.Type, tl.Type, desc(), why) yyerror("cannot use %v as type %v in %s%s", tn.Type, tl.Type, desc(), why)
}
} }
} }
}
if len(rfs) > len(lfs) { if len(rfs) > len(lfs) {
goto toomany goto toomany
}
goto out
} }
goto out
} }
} }
......
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