Update discriminant value encoding #16
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The original implementation, which used a
Discriminantenum with per-discriminant-type variants, relied on knowing the exact type that the discriminant resolves to. Extracting this type required the use of perma-unstable features and specialisation (or at least type name based runtime specialisation).Since we have moved away from these unstable features and now no longer extract the discriminant type but leave it as opaque, it is also no longer possible to know what type an enum discriminant should use.
Since the enum discriminant type is already encoded in the enum
#[repr]attribute, what we really only care about is the numerical value of the discriminant. We now store this numerical value in negabinary representation, which has unique representations for signed and unsigned values and is independent of the numerical type size.