You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Device-side SetDiscriminant is unsupported for both direct-tag and niche-encoded enums #306
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)TBDNot yet triaged; scope or disposition undecidedbugSomething isn't workingcodegenDevice code-generation pipeline (Rust MIR to IR to PTX)cuda-oxideSIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, bookenhancementNew feature or request
MIR StatementKind::SetDiscriminant is currently rejected on the device with:
SetDiscriminant statements are not yet supported on the device; until they are lowered, enum discriminant writes would be silently dropped
This means any kernel code that writes an enum discriminant cannot compile. Common triggers include:
Mutating an enum variant inside a kernel:
enumDeviceState{Empty,Full(u32)}letmut state = DeviceState::Full(42);
state = DeviceState::Empty;
Option::take(&mut opt) or similar standard library operations that update an Option's discriminant.
The diagnostic was added to replace an earlier silent miscompile where the discriminant write was dropped entirely, but the underlying lowering is still missing.
Scope
This issue tracks implementing SetDiscriminant lowering for all enum kinds:
Direct-tag enums — enums with a separate discriminant tag in memory (e.g. enum DeviceState { Empty, Full(u32) }). Lowering should write the declared discriminant value to the tag slot.
Niche-encoded enums — enums whose discriminant is encoded in the payload scalar itself (e.g. Option<&T>, Option<NonZeroU32>). Lowering must rewrite the payload scalar rather than storing a separate tag.
This looks resolved. Both halves named in the title are implemented and covered by executing examples.
The diagnostic is gone.grep for "SetDiscriminant statements are not yet supported on the device" finds nothing on 15fa9d9d. The importer lowers it: crates/mir-importer/src/translator/statement.rs builds a MirSetDiscriminantOp (around lines 936-1025), rejecting only the cases that genuinely cannot be encoded — an unsupported enum type, a variant index out of bounds, an uninhabited variant, an unsupported layout kind, and a place with no addressable slot.
Three examples cover it, and the two positive ones pass on an A10G (sm_86, driver 595.71.05):
example
covers
result
set_discriminant
direct-tag, incl. #[repr(i8)] with explicit discriminants (Empty = -5, Full(u32) = 7) and a Single layout
PASS: all 64 threads observed the SetDiscriminant write.
set_discriminant_niche
niche encoding, including a later-field niche (MaybeWrapper's niche is at byte 4, not byte 0) and a device-constructed Option<bool>
set_discriminant_niche: PASS (64 host->device decodes and device->host enum writes)
error_set_discriminant_uninhabited
the negative case, pinned in STATUS.md and smoketest's ERROR_EXAMPLES
compile-must-fail
Both positive examples run through #[custom_mir(dialect = "runtime", phase = "optimized")] helpers that emit StatementKind::SetDiscriminant directly, so they exercise the statement rather than something that happens to lower nearby.
The issue's own trigger list is worth re-checking if you want it kept open for a narrower reason — the Option::take case in particular goes through libcore rather than a hand-written discriminant write, and I did not test that specific path. But the two mechanisms the title names both work.
Landing this as a comment rather than closing it, since you may be tracking something more specific here.
Agree with the read above: both halves the title names landed (#307 direct tag, #349 niche) and the lowering is intact on current main after the #1186 fact-oracle and #1201 toolchain changes.
On the triggers in the issue body. A "whole-value store" here writes the entire enum, tag and payload together, as opposed to a SetDiscriminant statement that rewrites only the tag.
trigger
MIR it produces
covered by
state = DeviceState::Empty
whole-value store (aggregate, or a folded constant at opt-level 3), not SetDiscriminant
test(codegen): cover Option and Result enum state transitions #826 landed a few hours before the comment above, so Option::take is no longer the untested case. Confirmed today on an RTX 5090: enum_state_transitions prints PASS: Option::take (and its other seven checks), and CUDA_OXIDE_DUMP_MIR=1 shows zero mir.set_discriminant ops in that example. A scratch kernel doing Option::take plus mem::replace on a two-variant payload enum was correct on all 64 threads as well.
No, nothing narrower — Option::take was the only loose end I had, and you have settled it.
That was the one caveat in my comment above: the trigger list goes through libcore rather than a hand-written discriminant write, and I had not tested that path. Your table answers it exactly, and #826 plus the enum_state_transitions run on the 5090 (PASS: Option::take, zero mir.set_discriminant ops under CUDA_OXIDE_DUMP_MIR=1) covers it better than I could have — the point that ordinary enum writes are whole-value stores and never reach the statement at all is the part I had not worked out.
IR-loweringLowering between dialects (dialect-mir to LLVM dialect)TBDNot yet triaged; scope or disposition undecidedbugSomething isn't workingcodegenDevice code-generation pipeline (Rust MIR to IR to PTX)cuda-oxideSIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, bookenhancementNew feature or request
Activity
vyncint commentedon Aug 12, 2026
This looks resolved. Both halves named in the title are implemented and covered by executing examples.
The diagnostic is gone.
grepfor "SetDiscriminant statements are not yet supported on the device" finds nothing on15fa9d9d. The importer lowers it:crates/mir-importer/src/translator/statement.rsbuilds aMirSetDiscriminantOp(around lines 936-1025), rejecting only the cases that genuinely cannot be encoded — an unsupported enum type, a variant index out of bounds, an uninhabited variant, an unsupported layout kind, and a place with no addressable slot.Three examples cover it, and the two positive ones pass on an A10G (sm_86, driver 595.71.05):
set_discriminant#[repr(i8)]with explicit discriminants (Empty = -5,Full(u32) = 7) and a Single layoutPASS: all 64 threads observed the SetDiscriminant write.set_discriminant_nicheMaybeWrapper's niche is at byte 4, not byte 0) and a device-constructedOption<bool>set_discriminant_niche: PASS (64 host->device decodes and device->host enum writes)error_set_discriminant_uninhabitedSTATUS.mdand smoketest'sERROR_EXAMPLESBoth positive examples run through
#[custom_mir(dialect = "runtime", phase = "optimized")]helpers that emitStatementKind::SetDiscriminantdirectly, so they exercise the statement rather than something that happens to lower nearby.The issue's own trigger list is worth re-checking if you want it kept open for a narrower reason — the
Option::takecase in particular goes through libcore rather than a hand-written discriminant write, and I did not test that specific path. But the two mechanisms the title names both work.Landing this as a comment rather than closing it, since you may be tracking something more specific here.
nihalpasham commentedon Sep 3, 2026
Agree with the read above: both halves the title names landed (#307 direct tag, #349 niche) and the lowering is intact on current main after the #1186 fact-oracle and #1201 toolchain changes.
On the triggers in the issue body. A "whole-value store" here writes the entire enum, tag and payload together, as opposed to a
SetDiscriminantstatement that rewrites only the tag.state = DeviceState::EmptySetDiscriminantset_discriminant_niche(device-builtOption<bool>,DirectBoolean),enum_state_transitionsopt.take()mem::replace->*self = None, again a whole-value storeenum_state_transitions(#826, runstakefrom bothSomeandNoneon device)SetDiscriminant(custom MIR)set_discriminant,set_discriminant_niche,error_set_discriminant_uninhabitedSetDiscriminantfrom custom MIR and the coroutine transform. Ordinary enum writes never reach this statement, so the source-level triggers were fixed by the enum layout work (feat: field-faithful multi-payload enum layout; admit enums at the kernel ABI #160, feat(mir): support SetDiscriminant lowering for niche-encoded enums (incl. multi-field payloads) #349, Address an enum payload in memory, so a payload can be mutated in place #652, Write a canonical-storage enum payload by rebuilding the enum #673), not by this lowering.Option::takeis no longer the untested case. Confirmed today on an RTX 5090:enum_state_transitionsprintsPASS: Option::take(and its other seven checks), andCUDA_OXIDE_DUMP_MIR=1shows zeromir.set_discriminantops in that example. A scratch kernel doingOption::takeplusmem::replaceon a two-variant payload enum was correct on all 64 threads as well.error_enum_pointer_overlap,error_enum_shared_pointer_layout) fail closed with a diagnostic.I consider this covered. Was there anything narrower you were tracking under this issue?
vyncint commentedon Sep 6, 2026
No, nothing narrower —
Option::takewas the only loose end I had, and you have settled it.That was the one caveat in my comment above: the trigger list goes through libcore rather than a hand-written discriminant write, and I had not tested that path. Your table answers it exactly, and #826 plus the
enum_state_transitionsrun on the 5090 (PASS: Option::take, zeromir.set_discriminantops underCUDA_OXIDE_DUMP_MIR=1) covers it better than I could have — the point that ordinary enum writes are whole-value stores and never reach the statement at all is the part I had not worked out.Happy for this to close as covered.