-
Notifications
You must be signed in to change notification settings - Fork 5
fix(rt): generalize direct-tag enum decoding to any variant count and discriminant #955
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fd8be40
test(prove-rs): add direct-tag enum decode test showing stuck states
Stevengre 5ef51f4
fix(rt): generalize direct-tag enum decoding to any variant count and…
Stevengre 77713ea
test(prove-rs): remove enum-direct-tag-decode from show list
Stevengre eb8341c
Merge branch 'master' into jh/fix-two-variant-enum-decode
dkcumming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
kmir/src/tests/integration/data/prove-rs/enum-direct-tag-decode.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /// Comprehensive test for direct-tag enum decoding. | ||
| /// | ||
| /// Covers: | ||
| /// - `#[repr(u8)]` with discriminants 0/1 (baseline, like Option) | ||
| /// - `#[repr(u8)]` with discriminants 2/5 (non-zero start) | ||
| /// - `#[repr(u16)]` with discriminants 0/256 (wide tag exceeding u8 range) | ||
| /// - `#[repr(u8)]` with 3 variants (beyond two-variant restriction) | ||
|
|
||
| // --- Baseline: repr(u8), disc 0 / 1 ------------------------------------------- | ||
|
|
||
| #[repr(u8)] | ||
| enum TwoU8 { | ||
| A(bool) = 0, | ||
| B(bool) = 1, | ||
| } | ||
|
|
||
| const TWO_U8_A: TwoU8 = TwoU8::A(true); | ||
| const TWO_U8_B: TwoU8 = TwoU8::B(false); | ||
|
|
||
| // --- Non-zero discriminants: repr(u8), disc 2 / 5 ----------------------------- | ||
|
|
||
| #[repr(u8)] | ||
| enum NonZero { | ||
| X(bool) = 2, | ||
| Y(bool) = 5, | ||
| } | ||
|
|
||
| const NZ_X: NonZero = NonZero::X(false); | ||
| const NZ_Y: NonZero = NonZero::Y(true); | ||
|
|
||
| // --- Wide tag: repr(u16), disc 0 / 256 ---------------------------------------- | ||
|
|
||
| #[repr(u16)] | ||
| enum WideTag { | ||
| Lo(bool) = 0, | ||
| Hi(bool) = 256, | ||
| } | ||
|
|
||
| const WIDE_LO: WideTag = WideTag::Lo(true); | ||
| const WIDE_HI: WideTag = WideTag::Hi(false); | ||
|
|
||
| // --- Three variants: repr(u8), disc 0 / 1 / 2 --------------------------------- | ||
|
|
||
| #[repr(u8)] | ||
| enum Three { | ||
| First(bool) = 0, | ||
| Second(bool) = 1, | ||
| Third(bool) = 2, | ||
| } | ||
|
|
||
| const THREE_A: Three = Three::First(true); | ||
| const THREE_B: Three = Three::Second(false); | ||
| const THREE_C: Three = Three::Third(true); | ||
|
|
||
| fn main() { | ||
| // Baseline | ||
| assert!(matches!(TWO_U8_A, TwoU8::A(true))); | ||
| assert!(matches!(TWO_U8_B, TwoU8::B(false))); | ||
|
|
||
| // Non-zero discriminants | ||
| assert!(matches!(NZ_X, NonZero::X(false))); | ||
| assert!(matches!(NZ_Y, NonZero::Y(true))); | ||
|
|
||
| // Wide tag | ||
| assert!(matches!(WIDE_LO, WideTag::Lo(true))); | ||
| assert!(matches!(WIDE_HI, WideTag::Hi(false))); | ||
|
|
||
| // Three variants | ||
| assert!(matches!(THREE_A, Three::First(true))); | ||
| assert!(matches!(THREE_B, Three::Second(false))); | ||
| assert!(matches!(THREE_C, Three::Third(true))); | ||
| } |
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.
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.
This is unstable in the case that
#[repr(i8)]is provided right? It will interpret the magnitude as an unsigned? e.g.-1 -> 255?