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: don't compile some unexported, inlined functions #41117

Open
josharian opened this issue Aug 28, 2020 · 5 comments
Open

cmd/compile: don't compile some unexported, inlined functions #41117

josharian opened this issue Aug 28, 2020 · 5 comments

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Aug 28, 2020

If a function is:

  • inlined at all call sites
  • not exported
  • not referred to by value (any uses of the function are as a static call)
  • not present in any interface types in its containing package

then we don't need to compile that function.

I suspect that these conditions are frequently met, cheap to check, and reasonably easy to implement.

I thought we had an issue for this, but I don't see one. I don't plan to work on this. I'm filing it in case someone else wants to. :)

@josharian josharian added the ToolSpeed label Aug 28, 2020
@josharian josharian added this to the Unplanned milestone Aug 28, 2020
@networkimprov
Copy link

@networkimprov networkimprov commented Aug 29, 2020

At what line would it report a compile error if not compiled?

@josharian
Copy link
Contributor Author

@josharian josharian commented Aug 29, 2020

We’d still have to typecheck it.

@zephyrtronium
Copy link
Contributor

@zephyrtronium zephyrtronium commented Oct 18, 2020

I've been working on this to introduce myself to the compiler code base, and I think I understand most of the changes to make. I'd like to take it.

Specifically, my plan so far:

  • Add a MustCompile flag for Func. (I considered calling this NoSkipCompile because a "MustCompile" function might still not be compiled, e.g. if there are errors.)
  • Possibly type checking (phase 1): set MustCompile on exported functions.
  • Probably type checking (phase 1): set MustCompile on functions used as values. I suspect there might be somewhere in the SSA passes where it would be better to do this, to exclude such uses in dead code and to more easily find uses as values, but it would require a different compilation check than I'm planning and would save less work.
  • In inlnode (phase 5): set MustCompile if it's an ODEFER or OGO node (not clear yet on whether OCLOSURE and OCALLMETH should also set it) or if it's NoInline at the end.
  • In genfun (between phases 7 and 8): set MustCompile for each concrete method that matches an interface method.
  • In funccompile (phase 8): return early if the function is not marked MustCompile and inlining is enabled.

I'll be working on this assuming that plan is fine, but I'll probably be slow about it.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 22, 2020

Change https://golang.org/cl/264277 mentions this issue: cmd/compile: skip compiling some unexported, inlined functions

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jan 18, 2021

One particular case of this has been addressed by CL 282892: if a function-scoped function literal is no longer needed as a function literal (e.g., all of its uses have been inlined or removed by dead-code removal) then we don't separately compile it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants