]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: turn some pointer params into results
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 24 Oct 2017 16:15:30 +0000 (17:15 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 2 Nov 2017 20:46:12 +0000 (20:46 +0000)
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>

src/cmd/compile/internal/gc/range.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index 32f22172c8cb1268bd24f7640dd7866de9bcac8e..31a3340af004bbaeeb11e2f83805685ec3d5fd2d 100644 (file)
@@ -13,7 +13,7 @@ import (
 
 // range
 func typecheckrange(n *Node) {
-       var toomany int
+       var toomany bool
        var why string
        var t1 *types.Type
        var t2 *types.Type
@@ -50,7 +50,7 @@ func typecheckrange(n *Node) {
        }
        n.Type = t
 
-       toomany = 0
+       toomany = false
        switch t.Etype {
        default:
                yyerrorl(n.Pos, "cannot range over %L", n.Right)
@@ -73,7 +73,7 @@ func typecheckrange(n *Node) {
                t1 = t.Elem()
                t2 = nil
                if n.List.Len() == 2 {
-                       toomany = 1
+                       toomany = true
                }
 
        case TSTRING:
@@ -81,7 +81,7 @@ func typecheckrange(n *Node) {
                t2 = types.Runetype
        }
 
-       if n.List.Len() > 2 || toomany != 0 {
+       if n.List.Len() > 2 || toomany {
                yyerrorl(n.Pos, "too many variables in range")
        }
 
index 4eb2dae5562c6efeddecaeb4b39021debe0b77c4..b7d530c98c816aa07517b2b2d197f92a5a9c0ac4 100644 (file)
@@ -1800,35 +1800,32 @@ func hashmem(t *types.Type) *Node {
        return n
 }
 
-func ifacelookdot(s *types.Sym, t *types.Type, followptr *bool, ignorecase bool) *types.Field {
-       *followptr = false
-
+func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) (m *types.Field, followptr bool) {
        if t == nil {
-               return nil
+               return nil, false
        }
 
-       var m *types.Field
        path, ambig := dotpath(s, t, &m, ignorecase)
        if path == nil {
                if ambig {
                        yyerror("%v.%v is ambiguous", t, s)
                }
-               return nil
+               return nil, false
        }
 
        for _, d := range path {
                if d.field.Type.IsPtr() {
-                       *followptr = true
+                       followptr = true
                        break
                }
        }
 
        if m.Type.Etype != TFUNC || m.Type.Recv() == nil {
                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 {
@@ -1873,11 +1870,10 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
                if im.Broke() {
                        continue
                }
-               var followptr bool
-               tm := ifacelookdot(im.Sym, t, &followptr, false)
+               tm, followptr := ifacelookdot(im.Sym, t, false)
                if tm == nil || tm.Nointerface() || !eqtype(tm.Type, im.Type) {
                        if tm == nil {
-                               tm = ifacelookdot(im.Sym, t, &followptr, true)
+                               tm, followptr = ifacelookdot(im.Sym, t, true)
                        }
                        *m = im
                        *samename = tm
index f6e3633b0eb4c5392905052ef37898e0a97f5e63..11da26f3bdd204ee0c03012badef8ba5de6c41d7 100644 (file)
@@ -3910,17 +3910,17 @@ func (n *Node) isterminating() bool {
                if n.HasBreak() {
                        return false
                }
-               def := 0
+               def := false
                for _, n1 := range n.List.Slice() {
                        if !n1.Nbody.isterminating() {
                                return false
                        }
                        if n1.List.Len() == 0 { // default
-                               def = 1
+                               def = true
                        }
                }
 
-               if n.Op != OSELECT && def == 0 {
+               if n.Op != OSELECT && !def {
                        return false
                }
                return true
index 11825d9eac4f4c2bda7a53da7e016daf8446d63c..847f6991ee95f7467c4074674762bcc24553cb2d 100644 (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 variables
        // whose addresses have been taken.
-       memwrite := 0
-
-       varwrite := 0
+       memwrite := false
+       varwrite := false
        for _, an := range all[:i] {
                a := outervalue(an.Left)
 
@@ -2492,18 +2491,18 @@ func aliased(n *Node, all []*Node, i int) bool {
                }
 
                if a.Op != ONAME {
-                       memwrite = 1
+                       memwrite = true
                        continue
                }
 
                switch n.Class() {
                default:
-                       varwrite = 1
+                       varwrite = true
                        continue
 
                case PAUTO, PPARAM, PPARAMOUT:
                        if n.Addrtaken() {
-                               varwrite = 1
+                               varwrite = true
                                continue
                        }
 
@@ -2519,7 +2518,7 @@ func aliased(n *Node, all []*Node, i int) bool {
        // that are being written.
 
        // If no computed addresses are affected by the writes, no aliasing.
-       if memwrite == 0 && varwrite == 0 {
+       if !memwrite && !varwrite {
                return false
        }
 
@@ -3208,7 +3207,7 @@ func copyany(n *Node, init *Nodes, runtimecall bool) *Node {
        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
        // a struct/array containing a non-memory field/element.
        // Small memory is handled inline, and single non-memory
@@ -3217,8 +3216,7 @@ func eqfor(t *types.Type, needsize *int) *Node {
        case AMEM:
                n := syslook("memequal")
                n = substArgTypes(n, t, t)
-               *needsize = 1
-               return n
+               return n, true
        case ASPECIAL:
                sym := typesymprefix(".eq", t)
                n := newname(sym)
@@ -3229,11 +3227,10 @@ func eqfor(t *types.Type, needsize *int) *Node {
                ntype.Rlist.Append(anonfield(types.Types[TBOOL]))
                ntype = typecheck(ntype, Etype)
                n.Type = ntype.Type
-               *needsize = 0
-               return n
+               return n, false
        }
        Fatalf("eqfor %v", t)
-       return nil
+       return nil, false
 }
 
 // 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)
                init.Append(ar)
 
-               var needsize int
-               call := nod(OCALL, eqfor(t, &needsize), nil)
+               fn, needsize := eqfor(t)
+               call := nod(OCALL, fn, nil)
                call.List.Append(pl)
                call.List.Append(pr)
-               if needsize != 0 {
+               if needsize {
                        call.List.Append(nodintconst(t.Width))
                }
                res := call