Skip to content

fix(decode): accept signed enum tag scalars in _extract_tag#954

Draft
Stevengre wants to merge 2 commits intomasterfrom
jh/fix-signed-tag-decode
Draft

fix(decode): accept signed enum tag scalars in _extract_tag#954
Stevengre wants to merge 2 commits intomasterfrom
jh/fix-signed-tag-decode

Conversation

@Stevengre
Copy link
Contributor

@Stevengre Stevengre commented Feb 28, 2026

Summary

Change _extract_tag pattern match from signed=False to signed=_ so both signed and unsigned tag metadata are accepted. Add enum-3-variants-0-fields-signed-tag decode test fixture.

Context

Python's _extract_tag matched only signed=False in the PrimitiveInt pattern for enum discriminant scalars. However, some enums (e.g. 3-variant enums like Ordering) use signed: true tag metadata in SMIR — this comes from the Scalar representation where the compiler may choose a signed integer type for the discriminant.

Stable MIR enum discriminants represent raw tag bits. The signed flag describes the type metadata, not the encoding — unsigned decoding of the raw bytes is always correct regardless of the signed flag. Miri also reads discriminants as raw bytes without conditioning on signedness.

Without this fix, decoding a 3-variant enum raises:

ValueError: Unsupported tag: Initialized(value=PrimitiveInt(length=I8, signed=True), ...)

With this fix, the tag is correctly extracted as unsigned bytes regardless of the signed metadata flag.

Proof evidence

Without fix (RED): test_decode_value[enum-3-variants-0-fields-signed-tag] raises ValueError

With 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-integration regression

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.
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.

1 participant