-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: add new command #63501
Comments
Cf @bep's https://github.com/bep/punused, which I have used to check for dead code before. That one can have false positive though. |
I'd particularly interested in feedback on how we could improve the user interface to make it clearer. For example, the first command I ran to produce the example above used just Please try it out and let us know what you find. |
-generated=false is awkward. -exclude-generated would be less awkward. |
One thing I noticed is that it needs some logic around |
Logic to do what? The help message says:
Are you suggesting that it should treat non-executed Example functions as somehow reachable? I think its current behavior is more sensible. It's also unlikely that anyone would casually delete an Example based on the report produced by this tool. |
Why does the output print |
This proposal has been added to the active column of the proposals project |
I can see the logic in that, but having the tool not recognize functions that are meaningful to the standard go tooling feels like friction for most users. The invocation is going to become |
Change https://go.dev/cl/539661 mentions this issue: |
I think this depends on the default behavior. If generated files are excluded by default, then And based on my experience with this command, I think generated files should be excluded by default. I almost always want to exclude generated code, and commands should err on the side of less noise. |
This change adds support for JSON output and text/template formatting of output records, in the manner of 'go list (-f|-json)'. Plus test. Also, the -generated flag is now enabled by default, and it affects all output modes. Plus test. Updates golang/go#63501 Change-Id: I1374abad78d800f92739de5c75b28e6e5189caa1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/539661 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
Change https://go.dev/cl/540218 mentions this issue: |
...and don't quote the package path. Updates golang/go#63501 Change-Id: Ic4f52bf74d7ddd185f2179deed55118971bfa7ed Reviewed-on: https://go-review.googlesource.com/c/tools/+/540218 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
One small note about the output: the parens in (*Parsed).WriteNode are both pedantic and harmful. |
In the JSON, the fields "RelName" and "Posn" seem to be new spellings for Go. Are they necessary? |
Based on the discussion above, this proposal seems like a likely accept. See the top comment. |
Fair enough. (These names from go/ssa, which must be able to distinguish (T).f from (*T).f.)
Perhaps not: once we've simplified (*T).f to T.f then package-qualifying it is as simple as pkg.T.f. Nice. |
Change https://go.dev/cl/541238 mentions this issue: |
This change: - uses the simpler notation pkg.T.f instead of (*pkg.T).f in all output, by using a simplified fork of ssa.Function.String that only works on source functions (and package inits). - uses callgraph.Graph.DeleteSyntheticNodes to elide wrappers that aren't interesting to the user. - simplifies the JSON schema now that it's trivial to package-qualify any function by prepending "pkg.". - uses better spellings for JSON fields. Also, tests of new behavior. Updates golang/go#63501 Change-Id: Ie57399c4e05a882e294437b53317eb0c1b322e9f Reviewed-on: https://go-review.googlesource.com/c/tools/+/541238 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Commit-Queue: Alan Donovan <[email protected]>
Sounds like RelName can be deleted. Posn should be kept but changed to Pos or Position. |
I'm still not sure about the semi-structured default output. It is easy to fall back on "well it doesn't matter, programs will use json", but really the default output should be as usable for people as we can make it, including people typing at a Unix prompt. The current output is not greppable, for example. Also, I think it would make sense to think of deadcode as like vet in that it flags code that the user should take a look at. That strongly suggests the position belongs in the default output, so that it is easy to navigate to that code. So the output should probably be individual lines, not stateful sections, and each line should begin with the position:
And the file:line should default to relative to the current directory, like go vet and go build do. With the file:line, the full package path is probably unnecessary:
The "unused func:" is important because deadcode might also be printing ordinary build errors. |
Change https://go.dev/cl/542375 mentions this issue: |
Yep, that was done in CL 541238.
OK, done in 542375. I chose "unreachable" over "unused" because it's a property of the call graph, not the defs/uses graph.
The old format is now just an example -f template in the documentation. |
The previous format is now relegated to an example -f template in the documentation. Updates golang/go#63501 Change-Id: I29548121431282edbda07e3a75c131ac33104a6f Reviewed-on: https://go-review.googlesource.com/c/tools/+/542375 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
No change in consensus, so accepted. 🎉 See the top comment. |
Change https://go.dev/cl/547035 mentions this issue: |
The golang.org/x/tools/internal/cmd/deadcode command reports dead code, that is, functions not reachable by a sequence of calls from main, even through reflection, based on an RTA-based call graph. We have found it useful for identifying orphaned bits of code in x/tools and we imagine others might find it useful too. We propose to publish it at cmd/deadcode in the same repo.
This is an example of the tool in action, showing functions in x/tools not reachable from gopls' main or any of its tests, and suppressing functions in generated source files.
The text was updated successfully, but these errors were encountered: