mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/gc: shorten even more temporary lifetimes
1. Use n->alloc, not n->left, to hold the allocated temp being passed from orderstmt/orderexpr to walk. 2. Treat method values the same as closures. 3. Use killed temporary for composite literal passed to non-escaping function argument. 4. Clean temporaries promptly in if and for statements. 5. Clean temporaries promptly in select statements. As part of this, move all the temporary-generating logic out of select.c into order.c, so that the temporaries can be reclaimed. With the new temporaries, can re-enable the 1-entry select optimization. Fixes issue 7672. While we're here, fix a 1-line bug in select processing turned up by the new liveness test (but unrelated; select.c:72). Fixes #7686. 6. Clean temporaries (but not particularly promptly) in switch and range statements. 7. Clean temporary used during convT2E/convT2I. 8. Clean temporaries promptly during && and || expressions. --- CL 81940043 reduced the number of ambiguously live temps in the godoc binary from 860 to 711. CL 83090046 reduced the number from 711 to 121. This CL reduces the number from 121 to 23. 15 the 23 that remain are in fact ambiguously live. The final 8 could be fixed but are not trivial and not common enough to warrant work at this point in the release cycle. These numbers only count ambiguously live temps, not ambiguously live user-declared variables. There are 18 such variables in the godoc binary after this CL, so a total of 41 ambiguously live temps or user-declared variables. The net effect is that zeroing anything on entry to a function should now be a rare event, whereas earlier it was the common case. This is good enough for Go 1.3, and probably good enough for future releases too. Fixes #7345. LGTM=khr R=khr CC=golang-codereviews https://golang.org/cl/83000048
This commit is contained in:
parent
47acf16709
commit
96d90d0981
9 changed files with 356 additions and 188 deletions
114
test/live.go
114
test/live.go
|
|
@ -423,3 +423,117 @@ func f30(b bool) {
|
|||
print(p) // ERROR "live at call to printpointer: autotmp_[0-9]+ autotmp_[0-9]+$"
|
||||
}
|
||||
}
|
||||
|
||||
// conversion to interface should not leave temporary behind
|
||||
|
||||
func f31(b1, b2, b3 bool) {
|
||||
if b1 {
|
||||
g31("a") // ERROR "live at call to convT2E: autotmp_[0-9]+$" "live at call to g31: autotmp_[0-9]+$"
|
||||
}
|
||||
if b2 {
|
||||
h31("b") // ERROR "live at call to new: autotmp_[0-9]+$" "live at call to convT2E: autotmp_[0-9]+ autotmp_[0-9]+$" "live at call to h31: autotmp_[0-9]+$"
|
||||
}
|
||||
if b3 {
|
||||
panic("asdf") // ERROR "live at call to convT2E: autotmp_[0-9]+$" "live at call to panic: autotmp_[0-9]+$"
|
||||
}
|
||||
print(b3)
|
||||
}
|
||||
|
||||
func g31(interface{})
|
||||
func h31(...interface{})
|
||||
|
||||
// non-escaping partial functions passed to function call should die on return
|
||||
|
||||
type T32 int
|
||||
|
||||
func (t *T32) Inc() { // ERROR "live at entry"
|
||||
*t++
|
||||
}
|
||||
|
||||
var t32 T32
|
||||
|
||||
func f32(b bool) {
|
||||
if b {
|
||||
call32(t32.Inc) // ERROR "live at call to call32: autotmp_[0-9]+$"
|
||||
}
|
||||
call32(t32.Inc) // ERROR "live at call to call32: autotmp_[0-9]+$"
|
||||
call32(t32.Inc) // ERROR "live at call to call32: autotmp_[0-9]+$"
|
||||
}
|
||||
|
||||
//go:noescape
|
||||
func call32(func())
|
||||
|
||||
// temporaries introduced during if conditions and && || expressions
|
||||
// should die once the condition has been acted upon.
|
||||
|
||||
var m33 map[interface{}]int
|
||||
|
||||
func f33() {
|
||||
if m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
|
||||
println()
|
||||
return
|
||||
} else {
|
||||
println()
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
func f34() {
|
||||
if m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
|
||||
println()
|
||||
return
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
func f35() {
|
||||
if m33[nil] == 0 && m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
|
||||
println()
|
||||
return
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
func f36() {
|
||||
if m33[nil] == 0 || m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
|
||||
println()
|
||||
return
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
func f37() {
|
||||
if (m33[nil] == 0 || m33[nil] == 0) && m33[nil] == 0 { // ERROR "live at call to mapaccess1: autotmp_[0-9]+$"
|
||||
println()
|
||||
return
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
// select temps should disappear in the case bodies
|
||||
|
||||
var c38 chan string
|
||||
|
||||
func fc38() chan string
|
||||
func fi38(int) *string
|
||||
func fb38() *bool
|
||||
|
||||
func f38(b bool) {
|
||||
// we don't care what temps are printed on the lines with output.
|
||||
// we care that the println lines have no live variables
|
||||
// and therefore no output.
|
||||
if b {
|
||||
select { // ERROR "live at call"
|
||||
case <-fc38(): // ERROR "live at call"
|
||||
println()
|
||||
case fc38() <- *fi38(1): // ERROR "live at call"
|
||||
println()
|
||||
case *fi38(2) = <-fc38(): // ERROR "live at call"
|
||||
println()
|
||||
case *fi38(3), *fb38() = <-fc38(): // ERROR "live at call"
|
||||
println()
|
||||
}
|
||||
println()
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue