cmd/compile: remove trivial closure reference

Trivial closures will be converted to global functions, thus they are
not closures anymore. Using fn.IsClosure function is enough, allow
removing the trivial/non-trivial closures in the code.

Change-Id: Iceb186dd92c1732b101e221ebc13406db35c69ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/611995
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Tim King <taking@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Cuong Manh Le 2024-09-09 22:03:54 +07:00 committed by Gopher Robot
parent fe69121bc5
commit d288776d91
6 changed files with 16 additions and 23 deletions

View file

@ -282,12 +282,12 @@ func (f *Func) SetWBPos(pos src.XPos) {
}
}
// IsClosure reports whether f is a function literal that captures at least one value.
func (f *Func) IsClosure() bool {
if f.OClosure == nil {
return false
}
// Trivial closure will be converted to global.
return !IsTrivialClosure(f.OClosure)
return len(f.ClosureVars) > 0
}
// FuncName returns the name (without the package) of the function f.
@ -419,12 +419,6 @@ func ClosureDebugRuntimeCheck(clo *ClosureExpr) {
}
}
// IsTrivialClosure reports whether closure clo has an
// empty list of captured vars.
func IsTrivialClosure(clo *ClosureExpr) bool {
return len(clo.Func.ClosureVars) == 0
}
// globClosgen is like Func.Closgen, but for the global scope.
var globClosgen int32