Skip to content

Conversation

Stevengre and others added 4 commits November 14, 2025 06:02
Co-authored-by: Daniel Cumming <124537596+dkcumming@users.noreply.github.com>
Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Julian Kuners <julian.kuners@gmail.com>
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:

1. Transmute is only possible between the same width bits (e.g. `u8 ->
i8` fine, `u8 -> u16` not fine);
2. Discriminants are stored as `u128` in the type data even if they are
unsigned at the source level;
3. An integer transmuted into an enum is wellformed as long as the bit
pattern matches a discriminant;

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.
Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Daniel Cumming <124537596+dkcumming@users.noreply.github.com>
@jberthold jberthold merged commit 370164c into feature/p-token Nov 16, 2025
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants