Skip to content
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: dead-code elimination for empty init functions #34869

Closed
mdempsky opened this issue Oct 13, 2019 · 3 comments
Closed

cmd/compile: dead-code elimination for empty init functions #34869

mdempsky opened this issue Oct 13, 2019 · 3 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

Adding these functions to a package should have no effect:

func init() {}
func init() { if false { panic(0) } }

However, today they currently still emit empty functions (complete with DWARF debugging), which get linked into the inittasks array.

It's probably a simple task for sinit.go to recognize that the init function is empty and then skip processing it further.

/cc @cuonglm

@mdempsky mdempsky added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Oct 13, 2019
@mdempsky mdempsky added this to the Unplanned milestone Oct 13, 2019
@mvdan
Copy link
Member

mvdan commented Oct 13, 2019

Also /cc @rasky; I believe his ongoing work on removing unused "pure" init functions would already catch this by definition. See #19533.

Though that's in the linker. I assume if the compiler takes care of the trivial ones, both sides can avoid some work.

@gopherbot
Copy link

Change https://golang.org/cl/200958 mentions this issue: cmd/compile: skip empty init function in fninit

@gopherbot
Copy link

Change https://golang.org/cl/204217 mentions this issue: cmd/compile: add test for skipping empty init functions

gopherbot pushed a commit that referenced this issue Nov 4, 2019
CL 200958 adds skipping empty init function feature without any tests
for it. A codegen test sounds ideal, but it's unlikely that we can make
one for now, so use a program to manipulate runtime/proc.go:initTask
directly.

Updates #34869

Change-Id: I2683b9a1ace36af6861af02a3a9fb18b3110b282
Reviewed-on: https://go-review.googlesource.com/c/go/+/204217
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Oct 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants