Assigned bool // is the variable ever assigned to
Captured bool // is the variable captured by a closure
Byval bool // is the variable captured by value or by reference
- Reslice bool // this is a reslice x = x[0:y] or x = append(x, ...)
Likely int8 // likeliness of if statement
Hasbreak bool // has break statement
Needzero bool // if it contains pointers, needs to be zeroed on function entry
if n.Left.Typecheck == 0 {
typecheck(&n.Left, Erv|Easgn)
}
-
- // Recognize slices being updated in place, for better code generation later.
- // Don't rewrite if using race detector, to avoid needing to teach race detector
- // about this optimization.
- if n.Left != nil && n.Left.Op != OINDEXMAP && n.Right != nil && flag_race == 0 {
- switch n.Right.Op {
- // For x = x[0:y], x can be updated in place, without touching pointer.
- // TODO(rsc): Reenable once it is actually updated in place without touching the pointer.
- case OSLICE, OSLICE3, OSLICESTR:
- if false && samesafeexpr(n.Left, n.Right.Left) && (n.Right.Right.Left == nil || iszero(n.Right.Right.Left)) {
- n.Right.Reslice = true
- }
-
- // For x = append(x, ...), x can be updated in place when there is capacity,
- // without touching the pointer; otherwise the emitted code to growslice
- // can take care of updating the pointer, and only in that case.
- // TODO(rsc): Reenable once the emitted code does update the pointer.
- case OAPPEND:
- if false && n.Right.List != nil && samesafeexpr(n.Left, n.Right.List.N) {
- n.Right.Reslice = true
- }
- }
- }
}
func checkassignto(src *Type, dst *Node) {
return false
}
- // No write barrier for reslice: x = x[0:y] or x = append(x, ...).
- // Both are compiled to modify x directly.
- // In the case of append, a write barrier may still be needed
- // if the underlying array grows, but the append code can
- // generate the write barrier directly in that case.
- // (It does not yet, but the cost of the write barrier will be
- // small compared to the cost of the allocation.)
- if r.Reslice {
- switch r.Op {
- case OSLICE, OSLICE3, OSLICESTR, OAPPEND:
- break
-
- default:
- Dump("bad reslice-l", l)
- Dump("bad reslice-r", r)
- }
-
- return false
- }
-
// Otherwise, be conservative and use write barrier.
return true
}