types/dynamicpb: switch atomicExtFiles to atomic.Uint64 type

(Go Protobuf currently requires Go 1.21.)

This guarantees correct alignment on stack-allocated values, too.

Change-Id: If713532c20326a7ee3f1dd5c77f49c1d52f6eb9a
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/641017
Reviewed-by: Chressie Himpel <chressie@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/types/dynamicpb/types.go b/types/dynamicpb/types.go
index c432817..8e759fc 100644
--- a/types/dynamicpb/types.go
+++ b/types/dynamicpb/types.go
@@ -28,11 +28,7 @@
 type Types struct {
 	// atomicExtFiles is used with sync/atomic and hence must be the first word
 	// of the struct to guarantee 64-bit alignment.
-	//
-	// TODO(stapelberg): once we only support Go 1.19 and newer, switch this
-	// field to be of type atomic.Uint64 to guarantee alignment on
-	// stack-allocated values, too.
-	atomicExtFiles uint64
+	atomicExtFiles atomic.Uint64
 	extMu          sync.Mutex
 
 	files *protoregistry.Files
@@ -90,7 +86,7 @@
 func (t *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
 	// Construct the extension number map lazily, since not every user will need it.
 	// Update the map if new files are added to the registry.
-	if atomic.LoadUint64(&t.atomicExtFiles) != uint64(t.files.NumFiles()) {
+	if t.atomicExtFiles.Load() != uint64(t.files.NumFiles()) {
 		t.updateExtensions()
 	}
 	xd := t.extensionsByMessage[extField{message, field}]
@@ -133,10 +129,10 @@
 func (t *Types) updateExtensions() {
 	t.extMu.Lock()
 	defer t.extMu.Unlock()
-	if atomic.LoadUint64(&t.atomicExtFiles) == uint64(t.files.NumFiles()) {
+	if t.atomicExtFiles.Load() == uint64(t.files.NumFiles()) {
 		return
 	}
-	defer atomic.StoreUint64(&t.atomicExtFiles, uint64(t.files.NumFiles()))
+	defer t.atomicExtFiles.Store(uint64(t.files.NumFiles()))
 	t.files.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
 		t.registerExtensions(fd.Extensions())
 		t.registerExtensionsInMessages(fd.Messages())