mirror of
https://github.com/golang/go
synced 2024-10-01 18:28:32 -06:00
cmd/internal/gc: more int to bool cleanups
- make paramoutheap return a bool - convert Node.Assigned to a bool - convert Node.Captured to a bool - convert Node.Byval to a bool - convert Node.Dupok to a bool - convert Node.Wrapper to a bool - convert Node.Reslice to a bool Change-Id: I5b57c019f936c31d53db4db14459fb2b0aa72305 Reviewed-on: https://go-review.googlesource.com/7030 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Dave Cheney <dave@cheney.net>
This commit is contained in:
parent
09b49bf18d
commit
b006d38acc
@ -84,8 +84,8 @@ func typecheckclosure(func_ *Node, top int) {
|
|||||||
|
|
||||||
for l := func_.Cvars; l != nil; l = l.Next {
|
for l := func_.Cvars; l != nil; l = l.Next {
|
||||||
n = l.N.Closure
|
n = l.N.Closure
|
||||||
if n.Captured == 0 {
|
if !n.Captured {
|
||||||
n.Captured = 1
|
n.Captured = true
|
||||||
if n.Decldepth == 0 {
|
if n.Decldepth == 0 {
|
||||||
Fatal("typecheckclosure: var %v does not have decldepth assigned", Nconv(n, obj.FmtShort))
|
Fatal("typecheckclosure: var %v does not have decldepth assigned", Nconv(n, obj.FmtShort))
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func typecheckclosure(func_ *Node, top int) {
|
|||||||
// Ignore assignments to the variable in straightline code
|
// Ignore assignments to the variable in straightline code
|
||||||
// preceding the first capturing by a closure.
|
// preceding the first capturing by a closure.
|
||||||
if n.Decldepth == decldepth {
|
if n.Decldepth == decldepth {
|
||||||
n.Assigned = 0
|
n.Assigned = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -254,8 +254,8 @@ func capturevars(xfunc *Node) {
|
|||||||
v.Outerexpr = nil
|
v.Outerexpr = nil
|
||||||
|
|
||||||
// out parameters will be assigned to implicitly upon return.
|
// out parameters will be assigned to implicitly upon return.
|
||||||
if outer.Class != PPARAMOUT && !v.Closure.Addrtaken && v.Closure.Assigned == 0 && v.Type.Width <= 128 {
|
if outer.Class != PPARAMOUT && !v.Closure.Addrtaken && !v.Closure.Assigned && v.Type.Width <= 128 {
|
||||||
v.Byval = 1
|
v.Byval = true
|
||||||
} else {
|
} else {
|
||||||
v.Closure.Addrtaken = true
|
v.Closure.Addrtaken = true
|
||||||
outer = Nod(OADDR, outer, nil)
|
outer = Nod(OADDR, outer, nil)
|
||||||
@ -267,10 +267,10 @@ func capturevars(xfunc *Node) {
|
|||||||
name = v.Curfn.Nname.Sym
|
name = v.Curfn.Nname.Sym
|
||||||
}
|
}
|
||||||
how := "ref"
|
how := "ref"
|
||||||
if v.Byval != 0 {
|
if v.Byval {
|
||||||
how = "value"
|
how = "value"
|
||||||
}
|
}
|
||||||
Warnl(int(v.Lineno), "%v capturing by %s: %v (addr=%d assign=%d width=%d)", Sconv(name, 0), how, Sconv(v.Sym, 0), v.Closure.Addrtaken, v.Closure.Assigned, int32(v.Type.Width))
|
Warnl(int(v.Lineno), "%v capturing by %s: %v (addr=%v assign=%v width=%d)", Sconv(name, 0), how, Sconv(v.Sym, 0), v.Closure.Addrtaken, v.Closure.Assigned, int32(v.Type.Width))
|
||||||
}
|
}
|
||||||
|
|
||||||
typecheck(&outer, Erv)
|
typecheck(&outer, Erv)
|
||||||
@ -322,7 +322,7 @@ func transformclosure(xfunc *Node) {
|
|||||||
}
|
}
|
||||||
fld = typ(TFIELD)
|
fld = typ(TFIELD)
|
||||||
fld.Funarg = 1
|
fld.Funarg = 1
|
||||||
if v.Byval != 0 {
|
if v.Byval {
|
||||||
// If v is captured by value, we merely downgrade it to PPARAM.
|
// If v is captured by value, we merely downgrade it to PPARAM.
|
||||||
v.Class = PPARAM
|
v.Class = PPARAM
|
||||||
|
|
||||||
@ -378,14 +378,14 @@ func transformclosure(xfunc *Node) {
|
|||||||
cv = Nod(OCLOSUREVAR, nil, nil)
|
cv = Nod(OCLOSUREVAR, nil, nil)
|
||||||
|
|
||||||
cv.Type = v.Type
|
cv.Type = v.Type
|
||||||
if v.Byval == 0 {
|
if !v.Byval {
|
||||||
cv.Type = Ptrto(v.Type)
|
cv.Type = Ptrto(v.Type)
|
||||||
}
|
}
|
||||||
offset = Rnd(offset, int64(cv.Type.Align))
|
offset = Rnd(offset, int64(cv.Type.Align))
|
||||||
cv.Xoffset = offset
|
cv.Xoffset = offset
|
||||||
offset += cv.Type.Width
|
offset += cv.Type.Width
|
||||||
|
|
||||||
if v.Byval != 0 && v.Type.Width <= int64(2*Widthptr) && Thearch.Thechar == '6' {
|
if v.Byval && v.Type.Width <= int64(2*Widthptr) && Thearch.Thechar == '6' {
|
||||||
// If it is a small variable captured by value, downgrade it to PAUTO.
|
// If it is a small variable captured by value, downgrade it to PAUTO.
|
||||||
// This optimization is currently enabled only for amd64, see:
|
// This optimization is currently enabled only for amd64, see:
|
||||||
// https://github.com/golang/go/issues/9865
|
// https://github.com/golang/go/issues/9865
|
||||||
@ -406,7 +406,7 @@ func transformclosure(xfunc *Node) {
|
|||||||
addr.Curfn = xfunc
|
addr.Curfn = xfunc
|
||||||
xfunc.Dcl = list(xfunc.Dcl, addr)
|
xfunc.Dcl = list(xfunc.Dcl, addr)
|
||||||
v.Heapaddr = addr
|
v.Heapaddr = addr
|
||||||
if v.Byval != 0 {
|
if v.Byval {
|
||||||
cv = Nod(OADDR, cv, nil)
|
cv = Nod(OADDR, cv, nil)
|
||||||
}
|
}
|
||||||
body = list(body, Nod(OAS, addr, cv))
|
body = list(body, Nod(OAS, addr, cv))
|
||||||
@ -453,7 +453,7 @@ func walkclosure(func_ *Node, init **NodeList) *Node {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
typ1 = typenod(v.Type)
|
typ1 = typenod(v.Type)
|
||||||
if v.Byval == 0 {
|
if !v.Byval {
|
||||||
typ1 = Nod(OIND, typ1, nil)
|
typ1 = Nod(OIND, typ1, nil)
|
||||||
}
|
}
|
||||||
typ.List = list(typ.List, Nod(ODCLFIELD, newname(v.Sym), typ1))
|
typ.List = list(typ.List, Nod(ODCLFIELD, newname(v.Sym), typ1))
|
||||||
@ -588,7 +588,7 @@ func makepartialcall(fn *Node, t0 *Type, meth *Node) *Node {
|
|||||||
|
|
||||||
xtype.Rlist = l
|
xtype.Rlist = l
|
||||||
|
|
||||||
xfunc.Dupok = 1
|
xfunc.Dupok = true
|
||||||
xfunc.Nname = newname(sym)
|
xfunc.Nname = newname(sym)
|
||||||
xfunc.Nname.Sym.Flags |= SymExported // disable export
|
xfunc.Nname.Sym.Flags |= SymExported // disable export
|
||||||
xfunc.Nname.Ntype = xtype
|
xfunc.Nname.Ntype = xtype
|
||||||
|
@ -719,7 +719,7 @@ func esc(e *EscState, n *Node, up *Node) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
a = v.Closure
|
a = v.Closure
|
||||||
if v.Byval == 0 {
|
if !v.Byval {
|
||||||
a = Nod(OADDR, a, nil)
|
a = Nod(OADDR, a, nil)
|
||||||
a.Lineno = v.Lineno
|
a.Lineno = v.Lineno
|
||||||
a.Escloopdepth = e.loopdepth
|
a.Escloopdepth = e.loopdepth
|
||||||
|
@ -285,7 +285,7 @@ func Jconv(n *Node, flag int) string {
|
|||||||
fp += " addrtaken"
|
fp += " addrtaken"
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Assigned != 0 {
|
if n.Assigned {
|
||||||
fp += " assigned"
|
fp += " assigned"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,10 +442,10 @@ func compile(fn *Node) {
|
|||||||
nam = nil
|
nam = nil
|
||||||
}
|
}
|
||||||
ptxt = Thearch.Gins(obj.ATEXT, nam, &nod1)
|
ptxt = Thearch.Gins(obj.ATEXT, nam, &nod1)
|
||||||
if fn.Dupok != 0 {
|
if fn.Dupok {
|
||||||
ptxt.From3.Offset |= obj.DUPOK
|
ptxt.From3.Offset |= obj.DUPOK
|
||||||
}
|
}
|
||||||
if fn.Wrapper != 0 {
|
if fn.Wrapper {
|
||||||
ptxt.From3.Offset |= obj.WRAPPER
|
ptxt.From3.Offset |= obj.WRAPPER
|
||||||
}
|
}
|
||||||
if fn.Needctxt {
|
if fn.Needctxt {
|
||||||
|
@ -893,7 +893,7 @@ func mergetemp(firstp *obj.Prog) {
|
|||||||
for j = nfree; j < len(var_); j++ {
|
for j = nfree; j < len(var_); j++ {
|
||||||
v1 = inuse[j]
|
v1 = inuse[j]
|
||||||
if debugmerge > 0 && Debug['v'] != 0 {
|
if debugmerge > 0 && Debug['v'] != 0 {
|
||||||
fmt.Printf("consider %v: maybe %v: type=%v,%v addrtaken=%d,%d\n", Nconv(v.node, obj.FmtSharp), Nconv(v1.node, obj.FmtSharp), Tconv(t, 0), Tconv(v1.node.Type, 0), v.node.Addrtaken, v1.node.Addrtaken)
|
fmt.Printf("consider %v: maybe %v: type=%v,%v addrtaken=%v,%v\n", Nconv(v.node, obj.FmtSharp), Nconv(v1.node, obj.FmtSharp), Tconv(t, 0), Tconv(v1.node.Type, 0), v.node.Addrtaken, v1.node.Addrtaken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Require the types to match but also require the addrtaken bits to match.
|
// Require the types to match but also require the addrtaken bits to match.
|
||||||
|
@ -2474,7 +2474,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
|
|||||||
n.Left = newname(methodsym(method.Sym, methodrcvr, 0))
|
n.Left = newname(methodsym(method.Sym, methodrcvr, 0))
|
||||||
fn.Nbody = list(fn.Nbody, n)
|
fn.Nbody = list(fn.Nbody, n)
|
||||||
} else {
|
} else {
|
||||||
fn.Wrapper = 1 // ignore frame for panic+recover matching
|
fn.Wrapper = true // ignore frame for panic+recover matching
|
||||||
call := Nod(OCALL, dot, nil)
|
call := Nod(OCALL, dot, nil)
|
||||||
call.List = args
|
call.List = args
|
||||||
call.Isddd = uint8(isddd)
|
call.Isddd = uint8(isddd)
|
||||||
@ -2496,7 +2496,7 @@ func genwrapper(rcvr *Type, method *Type, newnam *Sym, iface int) {
|
|||||||
|
|
||||||
// wrappers where T is anonymous (struct or interface) can be duplicated.
|
// wrappers where T is anonymous (struct or interface) can be duplicated.
|
||||||
if rcvr.Etype == TSTRUCT || rcvr.Etype == TINTER || Isptr[rcvr.Etype] && rcvr.Type.Etype == TSTRUCT {
|
if rcvr.Etype == TSTRUCT || rcvr.Etype == TINTER || Isptr[rcvr.Etype] && rcvr.Type.Etype == TSTRUCT {
|
||||||
fn.Dupok = 1
|
fn.Dupok = true
|
||||||
}
|
}
|
||||||
typecheck(&fn, Etop)
|
typecheck(&fn, Etop)
|
||||||
typechecklist(fn.Nbody, Etop)
|
typechecklist(fn.Nbody, Etop)
|
||||||
@ -2751,7 +2751,7 @@ func genhash(sym *Sym, t *Type) {
|
|||||||
|
|
||||||
funcbody(fn)
|
funcbody(fn)
|
||||||
Curfn = fn
|
Curfn = fn
|
||||||
fn.Dupok = 1
|
fn.Dupok = true
|
||||||
typecheck(&fn, Etop)
|
typecheck(&fn, Etop)
|
||||||
typechecklist(fn.Nbody, Etop)
|
typechecklist(fn.Nbody, Etop)
|
||||||
Curfn = nil
|
Curfn = nil
|
||||||
@ -2971,7 +2971,7 @@ func geneq(sym *Sym, t *Type) {
|
|||||||
|
|
||||||
funcbody(fn)
|
funcbody(fn)
|
||||||
Curfn = fn
|
Curfn = fn
|
||||||
fn.Dupok = 1
|
fn.Dupok = true
|
||||||
typecheck(&fn, Etop)
|
typecheck(&fn, Etop)
|
||||||
typechecklist(fn.Nbody, Etop)
|
typechecklist(fn.Nbody, Etop)
|
||||||
Curfn = nil
|
Curfn = nil
|
||||||
|
@ -48,12 +48,12 @@ type Node struct {
|
|||||||
Readonly bool
|
Readonly bool
|
||||||
Implicit uint8
|
Implicit uint8
|
||||||
Addrtaken bool // address taken, even if not moved to heap
|
Addrtaken bool // address taken, even if not moved to heap
|
||||||
Assigned uint8 // is the variable ever assigned to
|
Assigned bool // is the variable ever assigned to
|
||||||
Captured uint8 // is the variable captured by a closure
|
Captured bool // is the variable captured by a closure
|
||||||
Byval uint8 // is the variable captured by value or by reference
|
Byval bool // is the variable captured by value or by reference
|
||||||
Dupok uint8 // duplicate definitions ok (for func)
|
Dupok bool // duplicate definitions ok (for func)
|
||||||
Wrapper uint8 // is method wrapper (for func)
|
Wrapper bool // is method wrapper (for func)
|
||||||
Reslice uint8 // this is a reslice x = x[0:y] or x = append(x, ...)
|
Reslice bool // this is a reslice x = x[0:y] or x = append(x, ...)
|
||||||
Likely int8 // likeliness of if statement
|
Likely int8 // likeliness of if statement
|
||||||
Hasbreak bool // has break statement
|
Hasbreak bool // has break statement
|
||||||
Needzero bool // if it contains pointers, needs to be zeroed on function entry
|
Needzero bool // if it contains pointers, needs to be zeroed on function entry
|
||||||
|
@ -3258,15 +3258,15 @@ func checkassign(stmt *Node, n *Node) {
|
|||||||
r := outervalue(n)
|
r := outervalue(n)
|
||||||
var l *Node
|
var l *Node
|
||||||
for l = n; l != r; l = l.Left {
|
for l = n; l != r; l = l.Left {
|
||||||
l.Assigned = 1
|
l.Assigned = true
|
||||||
if l.Closure != nil {
|
if l.Closure != nil {
|
||||||
l.Closure.Assigned = 1
|
l.Closure.Assigned = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Assigned = 1
|
l.Assigned = true
|
||||||
if l.Closure != nil {
|
if l.Closure != nil {
|
||||||
l.Closure.Assigned = 1
|
l.Closure.Assigned = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3370,7 +3370,7 @@ func typecheckas(n *Node) {
|
|||||||
OSLICE3,
|
OSLICE3,
|
||||||
OSLICESTR:
|
OSLICESTR:
|
||||||
if false && samesafeexpr(n.Left, n.Right.Left) && (n.Right.Right.Left == nil || iszero(n.Right.Right.Left)) {
|
if false && samesafeexpr(n.Left, n.Right.Left) && (n.Right.Right.Left == nil || iszero(n.Right.Right.Left)) {
|
||||||
n.Right.Reslice = 1
|
n.Right.Reslice = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// For x = append(x, ...), x can be updated in place when there is capacity,
|
// For x = append(x, ...), x can be updated in place when there is capacity,
|
||||||
@ -3379,7 +3379,7 @@ func typecheckas(n *Node) {
|
|||||||
// TODO(rsc): Reenable once the emitted code does update the pointer.
|
// TODO(rsc): Reenable once the emitted code does update the pointer.
|
||||||
case OAPPEND:
|
case OAPPEND:
|
||||||
if false && n.Right.List != nil && samesafeexpr(n.Left, n.Right.List.N) {
|
if false && n.Right.List != nil && samesafeexpr(n.Left, n.Right.List.N) {
|
||||||
n.Right.Reslice = 1
|
n.Right.Reslice = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,21 +91,21 @@ func samelist(a *NodeList, b *NodeList) bool {
|
|||||||
return a == b
|
return a == b
|
||||||
}
|
}
|
||||||
|
|
||||||
func paramoutheap(fn *Node) int {
|
func paramoutheap(fn *Node) bool {
|
||||||
for l := fn.Dcl; l != nil; l = l.Next {
|
for l := fn.Dcl; l != nil; l = l.Next {
|
||||||
switch l.N.Class {
|
switch l.N.Class {
|
||||||
case PPARAMOUT,
|
case PPARAMOUT,
|
||||||
PPARAMOUT | PHEAP:
|
PPARAMOUT | PHEAP:
|
||||||
return bool2int(l.N.Addrtaken)
|
return l.N.Addrtaken
|
||||||
|
|
||||||
// stop early - parameters are over
|
// stop early - parameters are over
|
||||||
case PAUTO,
|
case PAUTO,
|
||||||
PAUTO | PHEAP:
|
PAUTO | PHEAP:
|
||||||
return 0
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds "adjust" to all the argument locations for the call n.
|
// adds "adjust" to all the argument locations for the call n.
|
||||||
@ -284,7 +284,7 @@ func walkstmt(np **Node) {
|
|||||||
if n.List == nil {
|
if n.List == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if (Curfn.Type.Outnamed != 0 && count(n.List) > 1) || paramoutheap(Curfn) != 0 {
|
if (Curfn.Type.Outnamed != 0 && count(n.List) > 1) || paramoutheap(Curfn) {
|
||||||
// assign to the function out parameters,
|
// assign to the function out parameters,
|
||||||
// so that reorder3 can fix up conflicts
|
// so that reorder3 can fix up conflicts
|
||||||
var rl *NodeList
|
var rl *NodeList
|
||||||
@ -2174,7 +2174,7 @@ func needwritebarrier(l *Node, r *Node) bool {
|
|||||||
// generate the write barrier directly in that case.
|
// generate the write barrier directly in that case.
|
||||||
// (It does not yet, but the cost of the write barrier will be
|
// (It does not yet, but the cost of the write barrier will be
|
||||||
// small compared to the cost of the allocation.)
|
// small compared to the cost of the allocation.)
|
||||||
if r.Reslice != 0 {
|
if r.Reslice {
|
||||||
switch r.Op {
|
switch r.Op {
|
||||||
case OSLICE,
|
case OSLICE,
|
||||||
OSLICE3,
|
OSLICE3,
|
||||||
|
Loading…
Reference in New Issue
Block a user