4 ms·
Seems like you're conflating two separate things here. The Go compiler has a DCE pass which prevents unused code from ending up in the binary. The linked blog-p
by icholy 3y ago
Seems like you're conflating two separate things here. The Go compiler has a DCE pass which prevents unused code from ending up in the binary. The linked blog-post describes a tool for identifying unused code in your codebase. Two completely separate use-cases.
- BoppreH 3y agoI agree that "changes the generated binary" and "displays information to the user" are separate use cases, but the compiler already does both. There's even a compiler error for unused imports and variables. Doesn't seem far-fetched to ask for the compiler to warn on unused types/functions too.
- icholy 3y agoIt's not that simple. The Go compiler uses a main package as its entry point when compiling a binary. A module can have a many main packages each using different subsets of the library packages. So there are two choices here: 1. The Go compiler complains about code which is unused by the current main package. 2. The Go compiler tries to find/compile all main packages every-time. Both of these options suck.