Skip to content

cmd/compile: cleanup the extra "func" in closure name #55980

@cuonglm

Description

@cuonglm

Coming here from https://go-review.googlesource.com/c/go/+/437216/2..3/test/closure3.dir/main.go#b255.

Currently, the compiler names the closures base on the outer function:

package main

func main() {
	a := 2
	if r := func(x int) int {
		b := 3
		return func(y int) int {
			c := 5
			return func(z int) int {
				return a*x + b*y + c*z
			}(10)
		}(100)
	}(1000); r != 2350 {
		panic("r != 2350")
	}
}

For:

return func(z int) int {
	return a*x + b*y + c*z
}(10)

Unified IR generates main.func1.func2, while the old frontend generates main.func1.2. The discrepancy happens when calling ir.NameClosure. The old frontend use the immediate outer function (return func(y int) int { ... }) as outer function, while Unified IR use the outer most (func main() { ... }).

@mdempsky think that the func prefix may not be necessary, and we can remove it.

Metadata

Metadata

Labels

NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions