Cleanup of various lint issues across the code base

Fixing a variety of issues discovered by running staticcheck locally,
along with other linting issues found via golangci-lint in my IDE.

This does NOT eliminate all of the findings that staticcheck has in
its default configuration, just significantly reduces them. Some
issues require more extensive changes/investigation than I was willing
to put into this CL, or probably should just be suppressed since it is
unlikely we will fix them.

Types of issues identified by staticcheck and fixed:
- should use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) (S1028)
- var <name> is unused (U1000)
- func <name> is unused (U1000)
- type <name> is unused (U1000)
- this value of err is never used (SA4006)
- package <name> is being imported more than once (ST1019)
- unnecessary assignment to the blank identifier (S1005)
- Various "io/ioutil" has been deprecated since Go 1.19
- reflect.PtrTo has been deprecated since Go 1.22
- should use time.Since instead of time.Now().Sub (S1012)
- should use copy(to, from) instead of a loop (S1001)

Other types of issues fixed:
- Various pkg/var name collisions ('auth', 'git', 'gerrit', etc)
- Various direct comparison against errors instead of using errors.Is()
- Redundant conversions, e.g. string("literal")
- Struct <name> has methods on both value and pointer receivers,
  i.e. mixing (c Cmd) and (c *Cmd), there seemed to be lots of false
  positives for this, not clear why
- Ineffectual assignments, e.g. val := "", then immediately assigning
  to val, sometimes these assignments hid unused variables
- Instances where types could be omitted
- Snake case naming

I intentionally did not fix the following findings:
- error strings should not be capitalized (ST1005), since a lot of the
  existing tests are doing string comparison for error checking, so
  would need to be updated also
- strings.Title being deprecated, since it requires a new library call
  to fix, which has different semantics
- Fixing slices being initialized with empty literal instead of nil,
  e.g. var := []int{}. Technically nil for a slice can be appended to
  like an empty slice and some other usages and potentially save an
  allocation if not used, but in other cases, like working with JSON
  marshaling/unmarshaling nil vs an empty slice have semantic
  differences. I think the nil-behaviour of slices was a mistake,
  since it is a bit of a gotcha and really only exists for a niche
  optimization.
- Unused params, which could be fixed via '_'. There are hundreds of
  these in the code base and it is debatable if they should be fixed.
- Warnings about documentation, broadly ignored, since often they were
  related to having a '// TODO...' with no other documentation. Fixed
  examples that just needed moving text around instead of adding
  documentation
- Unhand-led errors, since these are often just being used in defer or
  from a printing statement, and wrapping them to be explicitly
  ignored is verbose
- Some examples of unused vars in tests, because they smelt of
  incomplete tests, i.e. there should have cases that used
  them.
- Some name collisions, especially with 'len' and 'delete', because
  they smelt of overly smart meta-programming going on, and I didn't
  feel like sussing out what was going on

Bug: 439814281

Change-Id: Ib828330bfcffb1290fc15909218fb1eb432c45b5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/258134
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Brian Sheedy <bsheedy@google.com>
Commit-Queue: Brian Sheedy <bsheedy@google.com>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
33 files changed
tree: 74a7ab0a9abe398ef7d8b9bd4ef751f427fb56a6
  1. .github/
  2. .vscode/
  3. build_overrides/
  4. docs/
  5. generator/
  6. include/
  7. infra/
  8. scripts/
  9. src/
  10. test/
  11. third_party/
  12. tools/
  13. webgpu-cts/
  14. .bazelrc
  15. .clang-format
  16. .clang-format-ignore
  17. .clang-tidy
  18. .git-blame-ignore-revs
  19. .gitattributes
  20. .gitignore
  21. .gitmodules
  22. .gn
  23. .style.yapf
  24. .vpython3
  25. AUTHORS
  26. BUILD.bazel
  27. BUILD.gn
  28. CMakeLists.txt
  29. CMakeSettings.json
  30. CODE_OF_CONDUCT.md
  31. codereview.settings
  32. CONTRIBUTING.md
  33. CPPLINT.cfg
  34. DEPS
  35. DIR_METADATA
  36. go.mod
  37. go.sum
  38. go_presubmit_support.py
  39. LICENSE
  40. OWNERS
  41. PRESUBMIT.py
  42. README.chromium
  43. README.md
  44. WATCHLISTS
  45. WORKSPACE.bazel
README.md

Build Status Matrix Space

Dawn, a WebGPU implementation

Dawn is an open-source and cross-platform implementation of the WebGPU standard. More precisely it implements webgpu.h that is a one-to-one mapping with the WebGPU IDL. Dawn is meant to be integrated as part of a larger system and is the underlying implementation of WebGPU in Chromium.

Dawn provides several WebGPU building blocks:

  • WebGPU C/C++ headers that applications and other building blocks use.
    • The webgpu.h version that Dawn implements.
    • A C++ wrapper for the webgpu.h.
  • A “native” implementation of WebGPU using platforms' GPU APIs: D3D12, Metal, Vulkan and OpenGL. See per API support for more details.
  • A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers
  • Tint is a compiler for the WebGPU Shader Language (WGSL) that can be used in standalone to convert shaders from and to WGSL.

Helpful links:

Documentation table of content

Developer documentation:

User documentation: (TODO, figure out what overlaps with the webgpu.h docs)

License

BSD 3-Clause License, please see LICENSE.

Disclaimer

This is not an officially supported Google product.