]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove toolstash scaffolding
authorMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 17:37:28 +0000 (09:37 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 5 Jan 2021 21:44:30 +0000 (21:44 +0000)
Now that CaptureVars is gone, we can remove the extra code in escape
analysis that only served to appease toolstash -cmp.

Change-Id: I8c811834f3d966e76702e2d362e3de414c94bea6
Reviewed-on: https://go-review.googlesource.com/c/go/+/281544
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/escape/escape.go
src/cmd/compile/internal/logopt/logopt_test.go
test/chancap.go
test/fixedbugs/issue4085b.go

index 2222f980038b81e61b4a145098467b39d55737ce..5df82d8cdc5648bd6eb5ad743ab8b81724cd3d80 100644 (file)
@@ -116,12 +116,6 @@ type escape struct {
        // label with a corresponding backwards "goto" (i.e.,
        // unstructured loop).
        loopDepth int
-
-       // loopSlop tracks how far off typecheck's "decldepth" variable
-       // would be from loopDepth at the same point during type checking.
-       // It's only needed to match CaptureVars's pessimism until it can be
-       // removed entirely.
-       loopSlop int
 }
 
 // An location represents an abstract location that stores a Go
@@ -131,7 +125,6 @@ type location struct {
        curfn     *ir.Func // enclosing function
        edges     []edge   // incoming edges
        loopDepth int      // loopDepth at declaration
-       loopSlop  int      // loopSlop at declaration
 
        // derefs and walkgen are used during walkOne to track the
        // minimal dereferences from the walk root.
@@ -233,14 +226,10 @@ func Batch(fns []*ir.Func, recursive bool) {
        // can decide whether closures should capture their free variables
        // by value or reference.
        for _, closure := range b.closures {
-               b.flowClosure(closure.k, closure.clo, false)
+               b.flowClosure(closure.k, closure.clo)
        }
        b.closures = nil
 
-       for _, orphan := range findOrphans(fns) {
-               b.flowClosure(b.blankLoc.asHole(), orphan, true)
-       }
-
        for _, loc := range b.allLocs {
                if why := HeapAllocReason(loc.n); why != "" {
                        b.flow(b.heapHole().addr(loc.n, why), loc)
@@ -251,46 +240,6 @@ func Batch(fns []*ir.Func, recursive bool) {
        b.finish(fns)
 }
 
-// findOrphans finds orphaned closure expressions that were originally
-// contained within a function in fns, but were lost due to earlier
-// optimizations.
-// TODO(mdempsky): Remove after CaptureVars is gone.
-func findOrphans(fns []*ir.Func) []*ir.ClosureExpr {
-       have := make(map[*ir.Func]bool)
-       for _, fn := range fns {
-               have[fn] = true
-       }
-
-       parent := func(fn *ir.Func) *ir.Func {
-               if len(fn.ClosureVars) == 0 {
-                       return nil
-               }
-               cv := fn.ClosureVars[0]
-               if cv.Defn == nil {
-                       return nil // method value wrapper
-               }
-               return cv.Outer.Curfn
-       }
-
-       outermost := func(fn *ir.Func) *ir.Func {
-               for {
-                       outer := parent(fn)
-                       if outer == nil {
-                               return fn
-                       }
-                       fn = outer
-               }
-       }
-
-       var orphans []*ir.ClosureExpr
-       for _, fn := range typecheck.Target.Decls {
-               if fn, ok := fn.(*ir.Func); ok && have[outermost(fn)] && !have[fn] {
-                       orphans = append(orphans, fn.OClosure)
-               }
-       }
-       return orphans
-}
-
 func (b *batch) with(fn *ir.Func) *escape {
        return &escape{
                batch:     b,
@@ -348,15 +297,11 @@ func (b *batch) walkFunc(fn *ir.Func) {
        }
 }
 
-func (b *batch) flowClosure(k hole, clo *ir.ClosureExpr, orphan bool) {
+func (b *batch) flowClosure(k hole, clo *ir.ClosureExpr) {
        for _, cv := range clo.Func.ClosureVars {
                n := cv.Canonical()
-               if n.Opt == nil && orphan {
-                       continue // n.Curfn must have been an orphan too
-               }
-
                loc := b.oldLoc(cv)
-               if !loc.captured && !orphan {
+               if !loc.captured {
                        base.FatalfAt(cv.Pos(), "closure variable never captured: %v", cv)
                }
 
@@ -454,9 +399,6 @@ func (e *escape) stmt(n ir.Node) {
                        if base.Flag.LowerM > 2 {
                                fmt.Printf("%v:%v non-looping label\n", base.FmtPos(base.Pos), n)
                        }
-                       if s := n.Label.Name; !strings.HasPrefix(s, ".") && !strings.Contains(s, "ยท") {
-                               e.loopSlop++
-                       }
                case looping:
                        if base.Flag.LowerM > 2 {
                                fmt.Printf("%v: %v looping label\n", base.FmtPos(base.Pos), n)
@@ -597,7 +539,6 @@ func (e *escape) stmts(l ir.Nodes) {
 func (e *escape) block(l ir.Nodes) {
        old := e.loopDepth
        e.stmts(l)
-       e.loopSlop += e.loopDepth - old
        e.loopDepth = old
 }
 
@@ -821,7 +762,7 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
 
                                        // Ignore reassignments to the variable in straightline code
                                        // preceding the first capture by a closure.
-                                       if loc.loopDepth+loc.loopSlop == e.loopDepth+e.loopSlop {
+                                       if loc.loopDepth == e.loopDepth {
                                                loc.reassigned = false
                                        }
                                }
@@ -1286,7 +1227,6 @@ func (e *escape) dcl(n *ir.Name) hole {
        }
        loc := e.oldLoc(n)
        loc.loopDepth = e.loopDepth
-       loc.loopSlop = e.loopSlop
        return loc.asHole()
 }
 
@@ -1323,7 +1263,6 @@ func (e *escape) newLoc(n ir.Node, transient bool) *location {
                n:         n,
                curfn:     e.curfn,
                loopDepth: e.loopDepth,
-               loopSlop:  e.loopSlop,
                transient: transient,
        }
        e.allLocs = append(e.allLocs, loc)
index 1d1e21b0609863bd2645f5ffada5e818eaefce6d..71976174b03517def512290e47d86a4980a02963 100644 (file)
@@ -154,7 +154,6 @@ func s15a8(x *[15]int64) [15]int64 {
                // On not-amd64, test the host architecture and os
                arches := []string{runtime.GOARCH}
                goos0 := runtime.GOOS
-               goos0 = "" + goos0             // TODO(mdempsky): Remove once CaptureVars is gone.
                if runtime.GOARCH == "amd64" { // Test many things with "linux" (wasm will get "js")
                        arches = []string{"arm", "arm64", "386", "amd64", "mips", "mips64", "ppc64le", "riscv64", "s390x", "wasm"}
                        goos0 = "linux"
index 3a4f67638a431e44edf623af5a2776e1f21dc032..8dce9247cd45ef710ef728c1d85d1e2d7c28e9e4 100644 (file)
@@ -41,7 +41,6 @@ func main() {
        n := -1
        shouldPanic("makechan: size out of range", func() { _ = make(T, n) })
        shouldPanic("makechan: size out of range", func() { _ = make(T, int64(n)) })
-       n = 0 + n // TODO(mdempsky): Remove once CaptureVars is gone.
        if ptrSize == 8 {
                // Test mem > maxAlloc
                var n2 int64 = 1 << 59
index b69e10c6ccee002783d4de213d47e637c11a6840..cf27512da0b7f11ebe258de95d3a7ea5fd41de36 100644 (file)
@@ -22,7 +22,6 @@ func main() {
        testMakeInAppend(n)
 
        var t *byte
-       n = 0 + n // TODO(mdempsky): Remove once CaptureVars is gone.
        if unsafe.Sizeof(t) == 8 {
                // Test mem > maxAlloc
                var n2 int64 = 1 << 59