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

josharian opened this issue Aug 28, 2020 · 5 comments

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

josharian opened this issue Aug 28, 2020 · 5 comments
help wanted NeedsInvestigation ToolSpeed


Copy link

@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 this to the Unplanned milestone Aug 28, 2020
Copy link

@networkimprov networkimprov commented Aug 29, 2020

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

Copy link
Contributor Author

@josharian josharian commented Aug 29, 2020

We’d still have to typecheck it.

@cagedmantis cagedmantis added the NeedsInvestigation label Aug 31, 2020
Copy link

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

Copy link

@gopherbot gopherbot commented Oct 22, 2020

Change mentions this issue: cmd/compile: skip compiling some unexported, inlined functions

Copy link

@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
help wanted NeedsInvestigation ToolSpeed
None yet

No branches or pull requests

6 participants