Debian Codegraph @

website/content/changes/2020.2.md

raw
1 ---
2 title: Staticcheck 2020.2 release notes
3 linkTitle: "2020.2 (v0.1.0)"
4 weight: -5
5 ---
6
7 ## Performance improvements {#performance-improvements}
8
9 The primary focus of this release is a major improvement in performance, significantly reducing memory usage while also reducing runtimes.
10
11 <table class="table">
12 <caption>Uncached, GOMAXPROCS=1</caption>
13 <thead>
14 <tr>
15 <th>Package</th>
16 <th>2020.1.6</th>
17 <th>2020.2</th>
18 <th>Delta</th>
19 <th>Stats</th>
20 </tr>
21 </thead>
22 <tbody>
23 <tr>
24 <td>image/color </td>
25 <td>2.41s ±19% </td>
26 <td>2.00s ±14% </td>
27 <td>-17.08%</td>
28 <td>p=0.000, n=10+10</td>
29 </tr>
30 <tr>
31 <td>k8s.io/kubernetes/pkg/... </td>
32 <td>276s ± 1% </td>
33 <td>219s ± 1% </td>
34 <td>-20.62%</td>
35 <td>p=0.000, n=10+10</td>
36 </tr>
37 <tr>
38 <td>net/http </td>
39 <td>6.18s ± 1% </td>
40 <td>5.61s ± 5% </td>
41 <td>-9.21%</td>
42 <td>p=0.000, n=8+10</td>
43 </tr>
44 <tr>
45 <td>std </td>
46 <td>49.5s ± 1% </td>
47 <td>42.5s ± 1% </td>
48 <td>-14.04%</td>
49 <td>p=0.000, n=9+10</td>
50 </tr>
51 <tr>
52 <td>strconv </td>
53 <td>2.49s ± 9% </td>
54 <td>2.19s ±12% </td>
55 <td>-12.08%</td>
56 <td>p=0.001, n=10+10</td>
57 </tr>
58 </tbody>
59 <tbody>
60 <tr>
61 <td>image/color </td>
62 <td>167MB ±26% </td>
63 <td>146MB ±19% </td>
64 <td>-12.62%</td>
65 <td>p=0.043, n=10+10</td>
66 </tr>
67 <tr>
68 <td>k8s.io/kubernetes/pkg/... </td>
69 <td>2.14GB ± 1% </td>
70 <td>0.45GB ±13% </td>
71 <td>-79.09%</td>
72 <td>p=0.000, n=10+10</td>
73 </tr>
74 <tr>
75 <td>net/http </td>
76 <td>216MB ± 6% </td>
77 <td>166MB ±18% </td>
78 <td>-23.11%</td>
79 <td>p=0.000, n=10+10</td>
80 </tr>
81 <tr>
82 <td>std </td>
83 <td>972MB ± 3% </td>
84 <td>284MB ± 9% </td>
85 <td>-70.82%</td>
86 <td>p=0.000, n=8+10</td>
87 </tr>
88 <tr>
89 <td>strconv </td>
90 <td>155MB ±21% </td>
91 <td>139MB ±29% </td>
92 <td>~</td>
93 <td>p=0.063, n=10+10</td>
94 </tr>
95 </tbody>
96 </table>
97
98 <table class="table">
99 <caption>Cached, GOMAXPROCS=1</caption>
100 <thead>
101 <tr>
102 <th>Package</th>
103 <th>2020.1.6</th>
104 <th>2020.2</th>
105 <th>Delta</th>
106 <th>Stats</th>
107 </tr>
108 </thead>
109 <tbody>
110 <tr>
111 <td>image/color </td>
112 <td>160ms ± 0% </td>
113 <td>107ms ± 7% </td>
114 <td>-33.13%</td>
115 <td>p=0.000, n=8+10</td>
116 </tr>
117 <tr>
118 <td>k8s.io/kubernetes/pkg/... </td>
119 <td>12.7s ± 1% </td>
120 <td>6.9s ± 1% </td>
121 <td>-45.26%</td>
122 <td>p=0.000, n=9+10</td>
123 </tr>
124 <tr>
125 <td>net/http </td>
126 <td>370ms ± 0% </td>
127 <td>230ms ± 0% </td>
128 <td>-37.84%</td>
129 <td>p=0.000, n=8+8</td>
130 </tr>
131 <tr>
132 <td>std </td>
133 <td>2.52s ± 1% </td>
134 <td>1.31s ± 1% </td>
135 <td>-48.13%</td>
136 <td>p=0.000, n=10+9</td>
137 </tr>
138 <tr>
139 <td>strconv </td>
140 <td>164ms ± 4% </td>
141 <td>110ms ± 0% </td>
142 <td>-32.93%</td>
143 <td>p=0.000, n=10+10</td>
144 </tr>
145 </tbody>
146 <tbody>
147 <tr>
148 <td>image/color </td>
149 <td>38.6MB ± 4% </td>
150 <td>20.8MB ± 1% </td>
151 <td>-45.96%</td>
152 <td>p=0.000, n=9+10</td>
153 </tr>
154 <tr>
155 <td>k8s.io/kubernetes/pkg/... </td>
156 <td>863MB ± 4% </td>
157 <td>283MB ± 2% </td>
158 <td>-67.28%</td>
159 <td>p=0.000, n=10+10</td>
160 </tr>
161 <tr>
162 <td>net/http </td>
163 <td>70.5MB ± 5% </td>
164 <td>25.8MB ± 2% </td>
165 <td>-63.48%</td>
166 <td>p=0.000, n=10+9</td>
167 </tr>
168 <tr>
169 <td>std </td>
170 <td>243MB ±16% </td>
171 <td>73MB ± 8% </td>
172 <td>-70.00%</td>
173 <td>p=0.000, n=10+10</td>
174 </tr>
175 <tr>
176 <td>strconv </td>
177 <td>37.2MB ± 2% </td>
178 <td>21.3MB ± 1% </td>
179 <td>-42.76%</td>
180 <td>p=0.000, n=9+10</td>
181 </tr>
182 </tbody>
183 </table>
184
185 <table class="table">
186 <caption>Uncached, GOMAXPROCS=32</caption>
187 <thead>
188 <tr>
189 <th>Package</th>
190 <th>2020.1.6</th>
191 <th>2020.2</th>
192 <th>Delta</th>
193 <th>Stats</th>
194 </tr>
195 </thead>
196 <tbody>
197 <tr>
198 <td>image/color </td>
199 <td>1.19s ±21% </td>
200 <td>1.06s ±12% </td>
201 <td>~</td>
202 <td>p=0.115, n=10+8</td>
203 </tr>
204 <tr>
205 <td>k8s.io/kubernetes/pkg/... </td>
206 <td>27.0s ± 2% </td>
207 <td>22.4s ± 2% </td>
208 <td>-16.96%</td>
209 <td>p=0.000, n=10+10</td>
210 </tr>
211 <tr>
212 <td>net/http </td>
213 <td>2.24s ±11% </td>
214 <td>2.23s ±10% </td>
215 <td>~</td>
216 <td>p=0.870, n=10+10</td>
217 </tr>
218 <tr>
219 <td>std </td>
220 <td>7.14s ± 5% </td>
221 <td>5.10s ± 9% </td>
222 <td>-28.56%</td>
223 <td>p=0.000, n=10+9</td>
224 </tr>
225 <tr>
226 <td>strconv </td>
227 <td>1.24s ±26% </td>
228 <td>1.18s ±21% </td>
229 <td>~</td>
230 <td>p=0.753, n=10+10</td>
231 </tr>
232 </tbody>
233 <tbody>
234 <tr>
235 <td>image/color </td>
236 <td>143MB ± 7% </td>
237 <td>141MB ± 6% </td>
238 <td>~</td>
239 <td>p=0.515, n=8+10</td>
240 </tr>
241 <tr>
242 <td>k8s.io/kubernetes/pkg/... </td>
243 <td>5.77GB ± 6% </td>
244 <td>2.76GB ± 4% </td>
245 <td>-52.25%</td>
246 <td>p=0.000, n=10+10</td>
247 </tr>
248 <tr>
249 <td>net/http </td>
250 <td>284MB ±10% </td>
251 <td>226MB ±14% </td>
252 <td>-20.38%</td>
253 <td>p=0.000, n=10+10</td>
254 </tr>
255 <tr>
256 <td>std </td>
257 <td>1.74GB ±10% </td>
258 <td>1.15GB ±14% </td>
259 <td>-34.11%</td>
260 <td>p=0.000, n=10+10</td>
261 </tr>
262 <tr>
263 <td>strconv </td>
264 <td>148MB ±18% </td>
265 <td>144MB ±16% </td>
266 <td>~</td>
267 <td>p=0.579, n=10+10</td>
268 </tr>
269 </tbody>
270 </table>
271
272
273 <table class="table">
274 <caption>Cached, GOMAXPROCS=32</caption>
275 <thead>
276 <tr>
277 <th>Package</th>
278 <th>2020.1.6</th>
279 <th>2020.2</th>
280 <th>Delta</th>
281 <th>Stats</th>
282 </tr>
283 </thead>
284 <tbody>
285 <tr>
286 <td>image/color </td>
287 <td>96.0ms ± 6% </td>
288 <td>80.0ms ± 0% </td>
289 <td>-16.67%</td>
290 <td>p=0.000, n=10+9</td>
291 </tr>
292 <tr>
293 <td>k8s.io/kubernetes/pkg/... </td>
294 <td>4.64s ± 1% </td>
295 <td>3.88s ± 0% </td>
296 <td>-16.22%</td>
297 <td>p=0.000, n=9+8</td>
298 </tr>
299 <tr>
300 <td>net/http </td>
301 <td>216ms ± 3% </td>
302 <td>167ms ± 4% </td>
303 <td>-22.69%</td>
304 <td>p=0.000, n=10+10</td>
305 </tr>
306 <tr>
307 <td>std </td>
308 <td>1.09s ± 2% </td>
309 <td>0.96s ± 2% </td>
310 <td>-12.20%</td>
311 <td>p=0.000, n=10+10</td>
312 </tr>
313 <tr>
314 <td>strconv </td>
315 <td>100ms ± 0% </td>
316 <td>87ms ± 8% </td>
317 <td>-13.00%</td>
318 <td>p=0.000, n=9+10</td>
319 </tr>
320 </tbody>
321 <tbody>
322 <tr>
323 <td>image/color </td>
324 <td>46.4MB ± 3% </td>
325 <td>24.1MB ± 5% </td>
326 <td>-48.08%</td>
327 <td>p=0.000, n=8+10</td>
328 </tr>
329 <tr>
330 <td>k8s.io/kubernetes/pkg/... </td>
331 <td>1.38GB ± 9% </td>
332 <td>0.27GB ± 1% </td>
333 <td>-80.29%</td>
334 <td>p=0.000, n=10+10</td>
335 </tr>
336 <tr>
337 <td>net/http </td>
338 <td>80.7MB ±12% </td>
339 <td>31.4MB ± 2% </td>
340 <td>-61.16%</td>
341 <td>p=0.000, n=10+8</td>
342 </tr>
343 <tr>
344 <td>std </td>
345 <td>363MB ±12% </td>
346 <td>75MB ± 7% </td>
347 <td>-79.30%</td>
348 <td>p=0.000, n=10+10</td>
349 </tr>
350 <tr>
351 <td>strconv </td>
352 <td>48.5MB ± 6% </td>
353 <td>24.4MB ± 3% </td>
354 <td>-49.72%</td>
355 <td>p=0.000, n=10+10</td>
356 </tr>
357 </tbody>
358 </table>
359
360
361 See commit [5cfc85b70e7b778eb76fd7338e538d7c9af21e4e](https://github.com/dominikh/go-tools/commit/5cfc85b70e7b778eb76fd7338e538d7c9af21e4e)
362 for details on how these improvements have been achieved.
363
364 Furthermore, Staticcheck 2020.2 will skip very large packages (currently packages that are 50 MiB or larger),
365 under the assumption that these packages contain bundled assets and aren't worth analyzing.
366 This might further reduce Staticcheck's memory usage in your projects.
367
368 ## Changes to the detection of unused code {#unused}
369
370 ### Removal of whole-program mode and changes to the handling of exported identifiers {#unused-whole-program}
371
372 The [aforementioned performance improvements](#performance-improvements) necessitate some changes to the _U1000_ check (also known as _unused_).
373
374 The most visible change is the removal of the _whole program_ mode.
375 This mode, which analyzed an entire program and reported unused code even if it is exported,
376 did not work well with the kind of caching that we use in Staticcheck.
377 Even in previous versions, it didn't always work correctly and may have caused flaky results,
378 depending on the state of the cache and the order of `staticcheck` invocations.
379
380 The whole-program mode may be revived in the future as a standalone tool,
381 with the understanding that this mode of operation is inherently more expensive than `staticcheck`.
382 In the meantime, if you depend on this functionality and can tolerate its bugs, you should continue using Staticcheck 2020.1.
383
384 As part of improving the correctness of U1000, changes were made to the normal mode as well.
385 In particular, **all** exported package-level identifiers will be considered used from now on,
386 even if these identifiers are declared in `package main` or tests, even if they are otherwise unused.
387 Exported identifiers in `package main` can be used in ways invisible to us, for example via the `plugin` build mode.
388 For tests, we would run into the same kind of issues as we did with the whole program mode.
389
390 ### Improvements {#unused-improvements}
391
392 The `//lint:ignore` directive now works more intelligently with the U1000 check.
393 In previous versions, the directive would only suppress the output of a diagnostic. For example, for the following example
394
395 ```go
396 package pkg
397
398 //lint:ignore U1000 This is fine.
399 func fn1() { fn2() }
400
401 func fn2() {}
402 ```
403
404 Staticcheck would emit the following output:
405
406 ```text
407 foo.go:6:6: func fn2 is unused (U1000)
408 ```
409
410 as it would only suppress the diagnostic for `fn1`.
411
412 Beginning with this release, the directive instead actively marks the identifier as used,
413 which means that any transitively used code will also be considered used, and no diagnostic will be reported for `fn2`.
414 Similarly, the `//lint:file-ignore` directive will consider everything in a file used, which may transitively mark code in other files used, too.
415
416 ## UI improvements {#ui-improvements}
417
418 We've made some minor improvements to the output and behavior of the `staticcheck` command:
419
420 - the command now prints instructions on how to look up documentation for checks
421 - output of the `-explain` flag includes a link to the online documentation
422 - a warning is emitted when a package pattern matches no packages
423 - unmatched ignore directives cause `staticcheck` to exit with a non-zero status code
424
425 ## Changes to versioning scheme {#versioning-improvements}
426
427 Staticcheck releases have two version numbers: one meant for human consumption and one meant for consumption by machines, via Go modules.
428 For example, the previous release was both `2020.1.6` (for humans) and `v0.0.1-2020.1.6` (for machines).
429
430 In previous releases, we've tried to include the human version in the machine version, by using the `v0.0.1-<human version>` scheme.
431 However, this scheme had various drawbacks.
432 For this and future releases we've switched to a more standard scheme for machine versions: `v0.<minor>.<patch>`.
433 Minor will increase by one for every feature release of Staticcheck,
434 and patch will increase by one for every bugfix release of Staticcheck,
435 resetting to zero on feature releases.
436
437 For example, this release is both `2020.2` and `v0.1.0`.
438 A hypothetical `2020.2.1` would be `v0.1.1`, and `2021.1` will be `v0.2.0`.
439 This new versioning scheme fixes various issues when trying to use Staticcheck as a Go module.
440 It will also allow us to make true pre-releases in the future.
441
442 Documentation on the website, as well as the output of `staticcheck -version`, will include both version numbers, to make it easier to associate the two.
443
444 For detailed information on how we arrived at this decision, see the discussion on [issue 777]({{< issueref 777 >}}).
445
446 ## Checks {#checks}
447 ### New checks {#checks-new}
448
449 The following new checks have been added:
450
451 - {{< check "SA4023" >}} flags impossible comparisons of interface values with untyped nils
452 - {{< check "SA5012" >}} flags function calls with slice arguments that aren't the right length
453 - {{< check "SA9006" >}} flags dubious bit shifts of fixed size integers
454
455 ### Changed checks {#checks-changed}
456
457 Several checks have been improved:
458
459 - {{< check "S1030" >}} no longer recommends replacing `m[string(buf.Bytes())]` with `m[buf.String()]`, as the former gets optimized by the compiler
460 - {{< check "S1008" >}} no longer incorrectly suggests that the negation of `>=` is `<=`
461 - {{< check "S1029" >}} and {{ check "SA6003" }} now also check custom types with underlying type `string`
462 - {{< check "SA1019" >}} now recognizes deprecation notices that aren't in the last paragraph of a comment
463 - {{< check "SA1019" >}} now emits more precise diagnostics for deprecated code in the standard library
464 - {{< check "SA4006" >}} no longer flags assignments where the value is a typed nil
465 - {{< check "SA5011" >}} is now able to detect more functions that never return, thus reducing the number of false positives
466 - {{< check "SA9004" >}} no longer assumes that constants belong to the same group when they have different types
467 - Automatic fixes for {{< check "SA9004" >}} inside gopls no longer incorrectly duplicate comments
468 - {{< check "ST1003" >}} no longer complains about ALL_CAPS in variable names that don't contain any letters
469 - Incorrect position information in various checks have been fixed
470 - Crashes in various checks have been fixed
471
472 ## Staticcheck 2020.2.1 release notes {#2020.2.1}
473
474 This release eliminates some false negatives as well as false positives, makes the `staticcheck` command less noisy and fixes a potential security issue.
475
476 - {{< check "SA4020" >}} no longer claims that `case nil` is an unreachable case in a type switch.
477 - {{< check "S1025" >}} no longer marks uses of `Printf` as unnecessary when the printed types implement the `fmt.Formatter` interface.
478 - Various checks may now detect bugs in conditional code that were previously missed. This was a regression introduced in Staticcheck 2020.1.
479 - The `staticcheck` command no longer reminds the user of the `-explain` flag every time problems are found. This was deemed too noisy.
480 - We've updated our dependency on `golang.org/x/tools` to guard against arbitrary code execution on Windows.
481 Note that to be fully safe, you will also have to update your installation of Go.
482 See the [Command PATH security in Go](https://blog.golang.org/path-security) article by the Go authors for more information on this potential vulnerability.
483
484 ## Staticcheck 2020.2.2 release notes {#2020.2.2}
485
486 This release fixes a rare crash in Staticcheck, reduces the number of false positives, and adds support for Go 1.16's `io/fs.FileMode` type.
487
488 - {{< check "SA9002" >}} now supports the new `io/fs.FileMode` type in addition to `os.FileMode`.
489 - Various checks no longer crash when analyzing nested function calls involving multiple return values.
490 - {{< check "SA1006" >}} no longer flags `Printf` calls of the form `Printf(fn())` when `fn` has multiple return values.
491 - Staticcheck now understands the effects of `github.com/golang/glog` on a function's control flow.
492
493 ## Staticcheck 2020.2.3 release notes {#2020.2.3}
494
495 This release fixes a false positive in U1000. See [issue 942]({{< issueref 942 >}}) for an example.
496
497 ## Staticcheck 2020.2.4 release notes {#2020.2.4}
498
499 This release fixes the following issues:
500
501 - A false positive in {{< check "S1017" >}} when the `len` function has been shadowed
502 - A bug in Staticcheck's intermediate representation
503 that would lead to nonsensical reports claiming that a value isn't being used
504 when it is definitely being used
505 (see issues [949]({{< issueref 949 >}}) and [981]({{< issueref 981 >}}) for more information)
506 - A rare crash (see issue [972]({{< issueref 972 >}}) for more information)