Skip to content

cmd/internal/gc: static initialization for function variables #10081

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

Closed
mdempsky opened this issue Mar 4, 2015 · 2 comments
Closed

cmd/internal/gc: static initialization for function variables #10081

mdempsky opened this issue Mar 4, 2015 · 2 comments
Milestone

Comments

@mdempsky
Copy link
Contributor

mdempsky commented Mar 4, 2015

Currently, this file:

package bug
func f() {}
var g = f

requires a dynamic initializer to assign g. This seems unnecessary though, because the compiler has already statically allocated the (empty) function closure for f, so g could just be statically initialized to point to that closure.

gopherbot pushed a commit that referenced this issue Mar 5, 2015
Previously, gc would compile code like

    func foo() { ... }
    var bar = foo

by emitting a static closure to wrap "foo", but then emitting runtime
initialization code to assign the closure to "bar".  This CL changes
gc to instead statically initialize "bar".

Notably, this change shrinks the "go" tool's text segment by ~7.4kB on
linux/amd64 while only increasing the data segment by ~100B:

   text	   data	    bss	    dec	    hex	filename
7237819	 122412	 215616	7575847	 739927	go.before
7230398	 122540	 215232	7568170	 737b2a	go.after

Fixes issue #10081.

Change-Id: If5e26cf46b323393ba6f2199a82a06e9e4baf411
Reviewed-on: https://go-review.googlesource.com/6880
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
@jnjackins
Copy link
Contributor

I think gopherbot forgot to close this issue.

@minux minux closed this as completed Mar 10, 2015
@minux
Copy link
Member

minux commented Mar 10, 2015

FTR, the syntax used in that revision is not recognized by github.

@mikioh mikioh added this to the Go1.5 milestone Mar 10, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants