aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-24 17:36:59 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-24 17:37:23 -0800
commit6d8d11876287c86424fd6b33cf5e459e8bfa06fa (patch)
tree61641e43a23bf1693e111ca9c9785ea54565f90a
parent9456804e860ac6e5a60d4e479182d53328069d13 (diff)
parent063c72f06d8673f3a2a03fd549c61935ca3e5cc5 (diff)
downloadgo-6d8d11876287c86424fd6b33cf5e459e8bfa06fa.tar.gz
go-6d8d11876287c86424fd6b33cf5e459e8bfa06fa.zip
[dev.typeparams] all: merge dev.regabi (063c72f) into dev.typeparams
Eager re-sync-branch to keep Git history reasonably accurate, since Git lacks a better way of encoding partial merges like CL 286172. Conflicts: - src/cmd/compile/internal/inline/inl.go - src/cmd/compile/internal/noder/import.go - src/cmd/compile/internal/noder/noder.go Merge List: + 2021-01-25 063c72f06d [dev.regabi] cmd/compile: backport changes from dev.typeparams (9456804) + 2021-01-23 d05d6fab32 [dev.regabi] cmd/compile: replace ir.Name map with ir.NameSet for SSA 2 + 2021-01-23 48badc5fa8 [dev.regabi] cmd/compile: fix escape analysis problem with closures + 2021-01-23 51e1819a8d [dev.regabi] cmd/compile: scan body of closure in tooHairy to check for disallowed nodes Change-Id: I48c0435f7aaf56f4aec26518a7459e9d95a51e9c
-rw-r--r--src/cmd/compile/internal/escape/escape.go10
-rw-r--r--src/cmd/compile/internal/inline/inl.go10
-rw-r--r--src/cmd/compile/internal/noder/import.go5
-rw-r--r--src/cmd/compile/internal/ssa/deadstore.go8
-rw-r--r--test/closure6.go18
5 files changed, 45 insertions, 6 deletions
diff --git a/src/cmd/compile/internal/escape/escape.go b/src/cmd/compile/internal/escape/escape.go
index 883e68a730..58cad73c76 100644
--- a/src/cmd/compile/internal/escape/escape.go
+++ b/src/cmd/compile/internal/escape/escape.go
@@ -781,6 +781,16 @@ func (e *escape) exprSkipInit(k hole, n ir.Node) {
}
}
+ for _, n := range fn.Dcl {
+ // Add locations for local variables of the
+ // closure, if needed, in case we're not including
+ // the closure func in the batch for escape
+ // analysis (happens for escape analysis called
+ // from reflectdata.methodWrapper)
+ if n.Op() == ir.ONAME && n.Opt == nil {
+ e.with(fn).newLoc(n, false)
+ }
+ }
e.walkFunc(fn)
}
diff --git a/src/cmd/compile/internal/inline/inl.go b/src/cmd/compile/internal/inline/inl.go
index f0be169f56..bbbdaa63d4 100644
--- a/src/cmd/compile/internal/inline/inl.go
+++ b/src/cmd/compile/internal/inline/inl.go
@@ -361,10 +361,16 @@ func (v *hairyVisitor) doNode(n ir.Node) bool {
return true
}
- // TODO(danscales) - fix some bugs when budget is lowered below 30
+ // TODO(danscales) - fix some bugs when budget is lowered below 15
// Maybe make budget proportional to number of closure variables, e.g.:
//v.budget -= int32(len(n.(*ir.ClosureExpr).Func.ClosureVars) * 3)
- v.budget -= 30
+ v.budget -= 15
+ // Scan body of closure (which DoChildren doesn't automatically
+ // do) to check for disallowed ops in the body and include the
+ // body in the budget.
+ if doList(n.(*ir.ClosureExpr).Func.Body, v.do) {
+ return true
+ }
case ir.ORANGE,
ir.OSELECT,
diff --git a/src/cmd/compile/internal/noder/import.go b/src/cmd/compile/internal/noder/import.go
index aa02c01cff..89a2598833 100644
--- a/src/cmd/compile/internal/noder/import.go
+++ b/src/cmd/compile/internal/noder/import.go
@@ -176,6 +176,11 @@ func resolveImportPath(path string) (string, error) {
// TODO(mdempsky): Return an error instead.
func importfile(decl *syntax.ImportDecl) *types.Pkg {
+ if decl.Path.Kind != syntax.StringLit {
+ base.Errorf("import path must be a string")
+ return nil
+ }
+
path, err := strconv.Unquote(decl.Path.Value)
if err != nil {
base.Errorf("import path must be a string")
diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go
index 0cf9931dbc..31d3f62d4e 100644
--- a/src/cmd/compile/internal/ssa/deadstore.go
+++ b/src/cmd/compile/internal/ssa/deadstore.go
@@ -299,7 +299,7 @@ func elimUnreadAutos(f *Func) {
// Loop over all ops that affect autos taking note of which
// autos we need and also stores that we might be able to
// eliminate.
- seen := make(map[*ir.Name]bool)
+ var seen ir.NameSet
var stores []*Value
for _, b := range f.Blocks {
for _, v := range b.Values {
@@ -317,7 +317,7 @@ func elimUnreadAutos(f *Func) {
// If we haven't seen the auto yet
// then this might be a store we can
// eliminate.
- if !seen[n] {
+ if !seen.Has(n) {
stores = append(stores, v)
}
default:
@@ -327,7 +327,7 @@ func elimUnreadAutos(f *Func) {
// because dead loads haven't been
// eliminated yet.
if v.Uses > 0 {
- seen[n] = true
+ seen.Add(n)
}
}
}
@@ -336,7 +336,7 @@ func elimUnreadAutos(f *Func) {
// Eliminate stores to unread autos.
for _, store := range stores {
n, _ := store.Aux.(*ir.Name)
- if seen[n] {
+ if seen.Has(n) {
continue
}
diff --git a/test/closure6.go b/test/closure6.go
new file mode 100644
index 0000000000..b5592ad3d3
--- /dev/null
+++ b/test/closure6.go
@@ -0,0 +1,18 @@
+// compile
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+type Float64Slice []float64
+
+func (a Float64Slice) Search1(x float64) int {
+ f := func(q int) bool { return a[q] >= x }
+ i := 0
+ if !f(3) {
+ i = 5
+ }
+ return i
+}