-
Notifications
You must be signed in to change notification settings - Fork 62
Validity of unions #73
Copy link
Copy link
Closed
Labels
A-unionsTopic: Related to unionsTopic: Related to unionsA-validityTopic: Related to validity invariantsTopic: Related to validity invariantsS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions
Metadata
Metadata
Assignees
Labels
A-unionsTopic: Related to unionsTopic: Related to unionsA-validityTopic: Related to validity invariantsTopic: Related to validity invariantsS-pending-designStatus: Resolving this issue requires addressing some open design questionsStatus: Resolving this issue requires addressing some open design questions
Type
Fields
Give feedbackNo fields configured for issues without a type.
Discussing the validity invariant of unions.
One possible choice here is "none, any bit pattern is allowed no matter which types the fields have, and including uninitialized bits".
We could also decide that e.g. a
must start with the first byte being either the bit-pattern of
falseor the bit-pattern oftrue, because all fields agree on that invariant.Notice that we cannot require the union to be valid for some field: for a union like
we want to allow a bit pattern like
0x3 0x3, which can occur from code likeThere is no demonstrated benefit from disallowing such code, and this kind of code seems perfectly reasonable around unions.
Given that, any validity invariant that wants to restrict the set of allowed bit patterns will be rather complicated. However, such an invariant would enable us to e.g. layout-optimize
Option<Foo>, whereas the "anything goes"-invariant would prohibit any kind of layout optimization around unions.