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
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Milestone

Comments

@josharian
Copy link
Contributor

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
@networkimprov
Copy link

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

@josharian
Copy link
Contributor Author

We’d still have to typecheck it.

@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 31, 2020
@zephyrtronium
Copy link
Contributor

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
Contributor

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

@mdempsky
Copy link
Contributor

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.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Projects
None yet
Development

No branches or pull requests

6 participants