-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: avoid closure for captured dynamic constant #5370
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
You have not shown us a complete program. The correct compilation here depends on what g does with f. If I add func g(func()) with no body, then in the absence of information the compiler allocates a closure, correctly. If I add func g(func()) {}, then since the argument does not escape, the compiler makes a function on the stack, again correctly. So I think this is working. |
I do not believe the body of g is important for demonstration purposes. Put another way, the compiler should recognize that the program is equivalent to the following func f() { println("") } func main() { g(f) } and avoid emitting code to allocate a closure either on the stack or on the heap. Instead, the compiler should arrange to have f point to a non-closure function similar to what I have shown above. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
The text was updated successfully, but these errors were encountered: