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

x/tools/cmd/deadcode: report uninstantiated types, and unreferenced fields #64945

Open
adonovan opened this issue Jan 3, 2024 · 0 comments
Open
Labels
FeatureRequest NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Jan 3, 2024

The deadcode command discovers functions that are unreachable from main, but a number of users (e.g. @rsc, @eliben) have suggested that it additionally report uninstantiated types.

The implementation strategy should be to visit every function that is found to be reachable, make a pass over its syntax, and enumerate all named types of which instances (any value, not just a variable) are created, including subelements of aggregate types (structs and arrays). This set cannot be soundly computed from the SSA representation as it folds constant expressions away, and they may contain the sole instantiation of a type (e.g. len(mystring(""))). The result is then the difference between the set of named types declared in all packages in the program, and the instantiated subset.

Also, @dominikh's staticcheck has a nice complementary feature which is the reporting of unused struct fields, and it is smart enough to report not only fields that are never mentioned, but also fields that are used only to compute a value for that field, such as x.f = x.f + 1. That feature would fit well in deadcode too.

Edit: let's also include unreferenced constants, as described in #66042.

@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Jan 3, 2024
@adonovan adonovan self-assigned this Jan 3, 2024
@gopherbot gopherbot added this to the Unreleased milestone Jan 3, 2024
@adonovan adonovan removed their assignment Jan 3, 2024
@adonovan adonovan changed the title x/tools/cmd/deadode: report uninstantiated types, and unreferenced fields x/tools/cmd/deadcode: report uninstantiated types, and unreferenced fields Jan 3, 2024
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants