fix(decode): accept signed enum tag scalars in _extract_tag#954
Draft
fix(decode): accept signed enum tag scalars in _extract_tag#954
Conversation
Some enums (e.g. 3-variant enums) use signed tag metadata in SMIR. Stable MIR discriminants represent raw tag bits, so unsigned decoding is always correct regardless of the signed flag. Change the pattern match from signed=False to signed=_ to accept both. Test: enum-3-variants-0-fields-signed-tag decode fixture.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Change
_extract_tagpattern match fromsigned=Falsetosigned=_so both signed and unsigned tag metadata are accepted. Addenum-3-variants-0-fields-signed-tagdecode test fixture.Context
Python's
_extract_tagmatched onlysigned=Falsein thePrimitiveIntpattern for enum discriminant scalars. However, some enums (e.g. 3-variant enums likeOrdering) usesigned: truetag metadata in SMIR — this comes from theScalarrepresentation where the compiler may choose a signed integer type for the discriminant.Stable MIR enum discriminants represent raw tag bits. The
signedflag describes the type metadata, not the encoding — unsigned decoding of the raw bytes is always correct regardless of thesignedflag. Miri also reads discriminants as raw bytes without conditioning on signedness.Without this fix, decoding a 3-variant enum raises:
With this fix, the tag is correctly extracted as unsigned bytes regardless of the
signedmetadata flag.Proof evidence
Without fix (RED):
test_decode_value[enum-3-variants-0-fields-signed-tag]raisesValueErrorWith fix (GREEN): Test passes, decodes to
Aggregate(variantIdx(1), .List)as expected.Test plan
test_decode_value[enum-3-variants-0-fields-signed-tag]make test-integrationregression