-
Notifications
You must be signed in to change notification settings - Fork 4
Transmute integer to fieldless enum #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transmute integer to fieldless enum #840
Conversation
This test should fail the test suite as it thunks, but doesn't due to a hack rule that was introduced. This rule stops the thunk from occurring.
- Corrected rules to check discriminant is valid; - Aggregate returned uses the discriminant to look up the variant; - Added error condition to prevent thunk if discriminant is invalid; - Added fail and passing tests;
- `#cast` uses `truncate` similar to `SwitchInt`; - Added test cases with negative discriminant; - Added test cases with positive discriminant and negative value; - Signed discriminants test fails but for unrelated reason I believe.
jberthold
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-approving, but please change the description text
| │ (100 steps) | ||
| └─ 3 (stuck, leaf) | ||
| #traverseProjection ( toLocal ( 2 ) , thunk ( #decodeConstant ( constantKindAllo | ||
| span: 153 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should look into why this is failing. My guess is that the decoding code is not ready for signed discriminants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a bit of minimised testing and wrote issue #848
This PR implements semantics to cast (transmute) an integer into an enum if that enum is known to have no fields in it's variants. Some things to consider that influence this PR:
u8 -> i8fine,u8 -> u16not fine);u128in the type data even if they are unsigned at the source level;The combination of these points mean that the approach to soundly casting an integer into an enum is to treat the incoming integer as unsigned (converting if signed), and check if that value is in the discriminants. If yes, follow to the corresponding variant position; if not return
#UBErrorInvalidDisciminantsInEnumCast.The added code has meant a work around with retrieving the discriminant of a thunked cast can be removed.
All added tests that should pass do except for one which is failing, I have made an issue for this as it is related to decoding negative discriminant enum types from an allocation.