The LayoutKind enum provides a simple encoding of the layout used for the flat representation of a value, but code often needs to know the properties of a particular layout.
For instance, here's how some code tests if a flat field has some atomicity requirement:
bool is_atomic = layout != LayoutKind::NON_ATOMIC_FLAT;
This code is brittle because it might need to be updated each time a new layout is added to the LayoutKind enum.
To prevent this situation, a LayoutKindHelper class should be created to unify the way layout properties are tested. This class should provide methods like LayoutKindHelper::is_atomic(LayoutKind lk), LayoutKindHelper::is_nullable(LayoutKind lk), etc.
This helper class could also provide a method to perform the LayoutKind -> ArrayProperties mapping, which is currently implemented in three different places in the VM.
For instance, here's how some code tests if a flat field has some atomicity requirement:
bool is_atomic = layout != LayoutKind::NON_ATOMIC_FLAT;
This code is brittle because it might need to be updated each time a new layout is added to the LayoutKind enum.
To prevent this situation, a LayoutKindHelper class should be created to unify the way layout properties are tested. This class should provide methods like LayoutKindHelper::is_atomic(LayoutKind lk), LayoutKindHelper::is_nullable(LayoutKind lk), etc.
This helper class could also provide a method to perform the LayoutKind -> ArrayProperties mapping, which is currently implemented in three different places in the VM.