Thanks to visit codestin.com
Credit goes to github.com

Skip to content

x/tools/gopls: modernizer for Go 1.19 atomic types (atomic.Int32, ...) #77352

@aktau

Description

@aktau

Go 1.19 introduced new atomic types (wrappers). Allowing one to replace:

var x int32
for range 100 {
  go atomic.AddInt32(&x, 1)
}

With:

var x atomic.Int32
for range 100 {
  go x.Add(1)
}

On the whole, this is safer, as the atomic types don't allow non-atomic access, which is a source of bugs. Note the +checkatomic annotation of checklocks.

These new-style atomics also don't suffer from misalignment problems, see dominikh/go-tools#171.

Not all usages are (easily) migratable, a non-exhaustive list of the top of my head:

  • Initialized values (e.g.: x := int32(42) ), though this could be done with an ugly closure, it may not be worth it.
  • Multi-package usages (exposed atomics, if they exist for some reason)
  • ...(probably a lot more)

cc @adonovan

Metadata

Metadata

Assignees

Labels

FeatureRequestIssues asking for a new feature that does not need a proposal.RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions