I'm trying to add padding on a generic struct (the full code is here):
type slotOfPadded[I any] struct {
slotOf[I]
pad [64 - (unsafe.Sizeof(slotOf[I]{}) % 64)]byte
}
type slotOf[I any] struct {
turn uint64
item I
}
and getting a compiler error as a result:
array length 64 - (unsafe.Sizeof(slotOf[I]{}) % 64) (value of type uintptr) must be constant
The padding is required to both align atomic ops on the turn field (I need to deal with an array of slotOfPadded structs) and to prevent false sharing.
The language doesn't seem to support this use case, but maybe there are any workarounds I'm not aware of. If there are none, it would be great to support adding padding on a generic struct.