cmd/compile: turn some pointer params into results

These are likely from the time when gc was written in C. There is no
need for any of these to be passed pointers, as the previous values are
not kept in any way, and the pointers are never nil. Others were left
untouched as they fell into one of these useful cases.

While at it, also turn some 0/1 integers into booleans.

Passes toolstash -cmp on std cmd.

Change-Id: Id3a9c9e84ef89536c4dc69a7fdbacd0fd7a76a9b
Reviewed-on: https://go-review.googlesource.com/72990
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Daniel Martí 2017-10-24 17:15:30 +01:00
parent f3884680fc
commit d5960e3043
4 changed files with 28 additions and 35 deletions

View file

@ -13,7 +13,7 @@ import (
// range // range
func typecheckrange(n *Node) { func typecheckrange(n *Node) {
var toomany int var toomany bool
var why string var why string
var t1 *types.Type var t1 *types.Type
var t2 *types.Type var t2 *types.Type
@ -50,7 +50,7 @@ func typecheckrange(n *Node) {
} }
n.Type = t n.Type = t
toomany = 0 toomany = false
switch t.Etype { switch t.Etype {
default: default:
yyerrorl(n.Pos, "cannot range over %L", n.Right) yyerrorl(n.Pos, "cannot range over %L", n.Right)
@ -73,7 +73,7 @@ func typecheckrange(n *Node) {
t1 = t.Elem() t1 = t.Elem()
t2 = nil t2 = nil
if n.List.Len() == 2 { if n.List.Len() == 2 {
toomany = 1 toomany = true
} }
case TSTRING: case TSTRING:
@ -81,7 +81,7 @@ func typecheckrange(n *Node) {
t2 = types.Runetype t2 = types.Runetype
} }
if n.List.Len() > 2 || toomany != 0 { if n.List.Len() > 2 || toomany {
yyerrorl(n.Pos, "too many variables in range") yyerrorl(n.Pos, "too many variables in range")
} }

View file

@ -1800,35 +1800,32 @@ func hashmem(t *types.Type) *Node {
return n return n
} }
func ifacelookdot(s *types.Sym, t *types.Type, followptr *bool, ignorecase bool) *types.Field { func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) (m *types.Field, followptr bool) {
*followptr = false
if t == nil { if t == nil {
return nil return nil, false
} }
var m *types.Field
path, ambig := dotpath(s, t, &m, ignorecase) path, ambig := dotpath(s, t, &m, ignorecase)
if path == nil { if path == nil {
if ambig { if ambig {
yyerror("%v.%v is ambiguous", t, s) yyerror("%v.%v is ambiguous", t, s)
} }
return nil return nil, false
} }
for _, d := range path { for _, d := range path {
if d.field.Type.IsPtr() { if d.field.Type.IsPtr() {
*followptr = true followptr = true
break break
} }
} }
if m.Type.Etype != TFUNC || m.Type.Recv() == nil { if m.Type.Etype != TFUNC || m.Type.Recv() == nil {
yyerror("%v.%v is a field, not a method", t, s) yyerror("%v.%v is a field, not a method", t, s)
return nil return nil, followptr
} }
return m return m, followptr
} }
func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool { func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool {
@ -1873,11 +1870,10 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
if im.Broke() { if im.Broke() {
continue continue
} }
var followptr bool tm, followptr := ifacelookdot(im.Sym, t, false)
tm := ifacelookdot(im.Sym, t, &followptr, false)
if tm == nil || tm.Nointerface() || !eqtype(tm.Type, im.Type) { if tm == nil || tm.Nointerface() || !eqtype(tm.Type, im.Type) {
if tm == nil { if tm == nil {
tm = ifacelookdot(im.Sym, t, &followptr, true) tm, followptr = ifacelookdot(im.Sym, t, true)
} }
*m = im *m = im
*samename = tm *samename = tm

View file

@ -3910,17 +3910,17 @@ func (n *Node) isterminating() bool {
if n.HasBreak() { if n.HasBreak() {
return false return false
} }
def := 0 def := false
for _, n1 := range n.List.Slice() { for _, n1 := range n.List.Slice() {
if !n1.Nbody.isterminating() { if !n1.Nbody.isterminating() {
return false return false
} }
if n1.List.Len() == 0 { // default if n1.List.Len() == 0 { // default
def = 1 def = true
} }
} }
if n.Op != OSELECT && def == 0 { if n.Op != OSELECT && !def {
return false return false
} }
return true return true

View file

@ -2481,9 +2481,8 @@ func aliased(n *Node, all []*Node, i int) bool {
// Also record whether there are any writes to main memory. // Also record whether there are any writes to main memory.
// Also record whether there are any writes to variables // Also record whether there are any writes to variables
// whose addresses have been taken. // whose addresses have been taken.
memwrite := 0 memwrite := false
varwrite := false
varwrite := 0
for _, an := range all[:i] { for _, an := range all[:i] {
a := outervalue(an.Left) a := outervalue(an.Left)
@ -2492,18 +2491,18 @@ func aliased(n *Node, all []*Node, i int) bool {
} }
if a.Op != ONAME { if a.Op != ONAME {
memwrite = 1 memwrite = true
continue continue
} }
switch n.Class() { switch n.Class() {
default: default:
varwrite = 1 varwrite = true
continue continue
case PAUTO, PPARAM, PPARAMOUT: case PAUTO, PPARAM, PPARAMOUT:
if n.Addrtaken() { if n.Addrtaken() {
varwrite = 1 varwrite = true
continue continue
} }
@ -2519,7 +2518,7 @@ func aliased(n *Node, all []*Node, i int) bool {
// that are being written. // that are being written.
// If no computed addresses are affected by the writes, no aliasing. // If no computed addresses are affected by the writes, no aliasing.
if memwrite == 0 && varwrite == 0 { if !memwrite && !varwrite {
return false return false
} }
@ -3208,7 +3207,7 @@ func copyany(n *Node, init *Nodes, runtimecall bool) *Node {
return nlen return nlen
} }
func eqfor(t *types.Type, needsize *int) *Node { func eqfor(t *types.Type) (n *Node, needsize bool) {
// Should only arrive here with large memory or // Should only arrive here with large memory or
// a struct/array containing a non-memory field/element. // a struct/array containing a non-memory field/element.
// Small memory is handled inline, and single non-memory // Small memory is handled inline, and single non-memory
@ -3217,8 +3216,7 @@ func eqfor(t *types.Type, needsize *int) *Node {
case AMEM: case AMEM:
n := syslook("memequal") n := syslook("memequal")
n = substArgTypes(n, t, t) n = substArgTypes(n, t, t)
*needsize = 1 return n, true
return n
case ASPECIAL: case ASPECIAL:
sym := typesymprefix(".eq", t) sym := typesymprefix(".eq", t)
n := newname(sym) n := newname(sym)
@ -3229,11 +3227,10 @@ func eqfor(t *types.Type, needsize *int) *Node {
ntype.Rlist.Append(anonfield(types.Types[TBOOL])) ntype.Rlist.Append(anonfield(types.Types[TBOOL]))
ntype = typecheck(ntype, Etype) ntype = typecheck(ntype, Etype)
n.Type = ntype.Type n.Type = ntype.Type
*needsize = 0 return n, false
return n
} }
Fatalf("eqfor %v", t) Fatalf("eqfor %v", t)
return nil return nil, false
} }
// The result of walkcompare MUST be assigned back to n, e.g. // The result of walkcompare MUST be assigned back to n, e.g.
@ -3353,11 +3350,11 @@ func walkcompare(n *Node, init *Nodes) *Node {
ar = typecheck(ar, Etop) ar = typecheck(ar, Etop)
init.Append(ar) init.Append(ar)
var needsize int fn, needsize := eqfor(t)
call := nod(OCALL, eqfor(t, &needsize), nil) call := nod(OCALL, fn, nil)
call.List.Append(pl) call.List.Append(pl)
call.List.Append(pr) call.List.Append(pr)
if needsize != 0 { if needsize {
call.List.Append(nodintconst(t.Width)) call.List.Append(nodintconst(t.Width))
} }
res := call res := call