Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(878)

Issue 12507043: code review 12507043: cmd/vet: add an "unused" module (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 9 months ago by r
Modified:
9 years, 10 months ago
CC:
golang-dev
Visibility:
Public.

Description

cmd/vet: add an "unused" module The algorithm is straightforward although some corner cases are tricky. We use the go/types Object map to iterate over the identifiers. A used identifier will appear at least twice: once at the declaration, once at the use. An unused identifier will appear only once: at its declaration. Thus we reference count the identifiers and those with only one appearance are errors. Moreover, by luck, that one instance is the correct place to flag the error. Tricky cases: - implicit declarations such as in import clauses and type switches. - handled through the Implicits map. - methods used only through interfaces - done by cross-checking methods and interfaces - fields in nonce structs (these appear often in tests) - not handled yet The nonce struct case is unsolved yet because the right heuristic is not clear. This check is enabled by default. It's a little noisy, especially inside tests, but it's already found lots of cruft in the standard library so I think it's worth turning on. Heuristics will improve to reduce noise. Fixes issue 4827.

Patch Set 1 #

Total comments: 3

Patch Set 2 : diff -r 2d447f803f2f https://code.google.com/p/go.tools #

Total comments: 30

Patch Set 3 : diff -r 6698ca2900e2 https://code.google.com/p/go.tools #

Total comments: 4

Patch Set 4 : diff -r 400755f06d55 https://code.google.com/p/go.tools #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+380 lines, -22 lines) Patch
M cmd/vet/asmdecl.go View 1 chunk +1 line, -1 line 0 comments Download
M cmd/vet/main.go View 1 2 3 7 chunks +67 lines, -12 lines 1 comment Download
M cmd/vet/testdata/asm.go View 2 chunks +2 lines, -2 lines 0 comments Download
M cmd/vet/testdata/composite.go View 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/vet/testdata/deadcode.go View 1 chunk +2 lines, -0 lines 0 comments Download
M cmd/vet/testdata/print.go View 2 chunks +2 lines, -2 lines 0 comments Download
M cmd/vet/testdata/shadow.go View 1 chunk +1 line, -0 lines 0 comments Download
A cmd/vet/testdata/unused.go View 1 2 1 chunk +60 lines, -0 lines 0 comments Download
M cmd/vet/types.go View 1 2 1 chunk +10 lines, -5 lines 0 comments Download
A cmd/vet/unused.go View 1 2 1 chunk +233 lines, -0 lines 2 comments Download

Messages

Total messages: 15
r
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://code.google.com/p/go.tools
10 years, 9 months ago (2013-08-06 06:18:33 UTC) #1
Dominik Honnef
https://codereview.appspot.com/12507043/diff/1/cmd/vet/unused.go File cmd/vet/unused.go (right): https://codereview.appspot.com/12507043/diff/1/cmd/vet/unused.go#newcode20 cmd/vet/unused.go:20: // use increments the reference count for the identifier, ...
10 years, 9 months ago (2013-08-07 02:01:04 UTC) #2
r
Hello golang-dev@googlegroups.com, dominik.honnef@gmail.com (cc: golang-dev@googlegroups.com), Please take another look.
10 years, 9 months ago (2013-08-07 04:17:25 UTC) #3
gri
What's the reason for having a use _count_ as opposed to a _use_ bit? Is ...
10 years, 9 months ago (2013-08-07 22:40:42 UTC) #4
r
https://codereview.appspot.com/12507043/diff/6001/cmd/vet/main.go File cmd/vet/main.go (right): https://codereview.appspot.com/12507043/diff/6001/cmd/vet/main.go#newcode48 cmd/vet/main.go:48: "unused": flag.Bool("unused", false, "check for unused unexported package-level identifiers"), ...
10 years, 9 months ago (2013-08-08 06:38:36 UTC) #5
r
Hello golang-dev@googlegroups.com, dominik.honnef@gmail.com, gri@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
10 years, 9 months ago (2013-08-08 06:38:57 UTC) #6
r
For the record, the actual message was: ./unused.go:149: cannot use method.Recv.List[0].Type (type ast.Expr) as type ...
10 years, 9 months ago (2013-08-08 06:59:54 UTC) #7
gri
looking forward to the general useType function https://codereview.appspot.com/12507043/diff/14001/cmd/vet/main.go File cmd/vet/main.go (right): https://codereview.appspot.com/12507043/diff/14001/cmd/vet/main.go#newcode448 cmd/vet/main.go:448: if d.Body ...
10 years, 9 months ago (2013-08-08 23:16:59 UTC) #8
r
Please explain for the incompetent here how the useType function would work. What is its ...
10 years, 9 months ago (2013-08-09 00:37:08 UTC) #9
r
https://codereview.appspot.com/12507043/diff/14001/cmd/vet/main.go File cmd/vet/main.go (right): https://codereview.appspot.com/12507043/diff/14001/cmd/vet/main.go#newcode448 cmd/vet/main.go:448: if d.Body == nil { On 2013/08/08 23:16:59, gri ...
10 years, 9 months ago (2013-08-09 00:38:27 UTC) #10
r
Hello golang-dev@googlegroups.com, dominik.honnef@gmail.com, gri@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
10 years, 9 months ago (2013-08-13 05:30:02 UTC) #11
r
Anyone else want to look at this? Robert is out and it would be nice ...
10 years, 8 months ago (2013-08-22 23:14:36 UTC) #12
remyoudompheng
I've used the module and noticed that when the binary packages are not installed, the ...
10 years, 8 months ago (2013-08-23 05:57:26 UTC) #13
crawshaw1
https://codereview.appspot.com/12507043/diff/22001/cmd/vet/main.go File cmd/vet/main.go (right): https://codereview.appspot.com/12507043/diff/22001/cmd/vet/main.go#newcode448 cmd/vet/main.go:448: if d.Body == nil { This case is covered ...
10 years, 8 months ago (2013-08-23 19:54:54 UTC) #14
r
10 years, 8 months ago (2013-08-27 05:03:48 UTC) #15
*** Abandoned ***
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b