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

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Oct 13, 2019

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

@mvdan

This comment has been minimized.

Copy link
Member

@mvdan 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

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 13, 2019

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

@gopherbot gopherbot closed this in 584ef45 Oct 18, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Oct 30, 2019

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.