x/tools/cmd/deadcode: report uninstantiated types, and unreferenced fields #64945
Labels
FeatureRequest
Issues asking for a new feature that does not need a proposal.
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
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.
The text was updated successfully, but these errors were encountered: