-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Milestone
Description
I notice that the use of a local variable to hold a function (e.g. for brevity) doesn't prevent the compiler from treating the variable as an alias for the function, and dispatching calls statically. However, if the variable is referenced from an inner closure, it is treated as a true variable, resulting in a dynamic call:
func f() any {
escape := html.EscapeString
println(escape("foo")) // static call
return func() {
println(escape("foo")) // dynamic call
}
}The closure may be latent, in the case of a range-over-func:
func f(seq iter.Seq[string]) {
escape := html.EscapeString
println(escape("foo")) // static call
for s := range seq {
println(escape(s)) // dynamic call
}
}This is another facet of #73524 (comment), where closures defeat constant propagation of outer single-assignment variables.
Metadata
Metadata
Assignees
Labels
FeatureRequestIssues asking for a new feature that does not need a proposal.Issues asking for a new feature that does not need a proposal.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.Issues related to the Go compiler and/or runtime.
Type
Projects
Status
Todo