Repository navigation
test(codegen): cover Option and Result enum state transitions - #826
Merged
nihalpasham merged 1 commit intoAug 12, 2026
Merged
Conversation
Signed-off-by: Raul Estrada <[email protected]>
Option and Result enum state transitions
Collaborator
|
Gist: device-side coverage for seven Option/Result state transitions (take, replace, get_or_insert, map, map_err, and_then, or_else), with runtime seeds keeping everything out of const-folding and collision-free packing making every slot host-checkable. Zero compiler changes needed: the SetDiscriminant path already lowers these, and now it's gated. Verified on an RTX 5090 (sm_120):
Landing once CI is green. Closes #825. |
nihalpasham
approved these changes
Aug 12, 2026
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.
Closes #825
Summary
Add an
enum_state_transitionscodegen example covering device-side execution of:Option::takeOption::replaceOption::get_or_insertResult::mapResult::map_errResult::and_thenResult::or_elseNo compiler changes are required.
The example confirms that the existing enum lowering machinery correctly handles the construction, discriminant reads, payload extraction, replacement, and payload mutation produced by these standard
coreAPIs.OptioncoverageThe
option_transitionskernel starts from a runtime-selectedSomeorNone, preventing the initial variant from being fixed at compile time.It verifies
Option::takein both directions:It verifies
Option::replacewith both initial variants:It also exercises
Option::get_or_insert.For an initial
None, the operation must construct a newSomepayload and return a mutable reference to it.For an existing
Some, the supplied replacement value must not overwrite the existing payload.In both cases the returned
&mutpayload is mutated and the finalOptionis observed afterward, covering payload addressing and mutation as well as the state transition itself.ResultcoverageThe
result_combinatorskernel starts from a runtime-selected:and exercises:
Both
OkandErrstarting states are tested.This gives explicit coverage of:
including the two cross-variant transitions:
Every intermediate
OptionorResultis matched and packed into a host-observable integer. This makes the resulting discriminant and payload part of the regression rather than merely checking that the methods compile.Why no compiler change is needed
The compiler already has the enum infrastructure required by these APIs:
Downcast -> Fieldpayload addressingThe standard-library APIs covered here lower onto those existing MIR paths.
This PR therefore adds focused conformance coverage rather than another enum representation or special-case intrinsic lowering.
Scope
This PR only adds:
No compiler, dialect, exporter, smoketest-script, or Rustlantis sources are changed.
Validation
Validated on an NVIDIA GeForce RTX 5060 Laptop GPU (
sm_120a).Optimized execution:
passes with:
Low-MIR-optimization execution also passes:
Scoped runtime smoketest:
Scoped compile-only smoketest:
The standalone example also passes:
Repository-level formatting and diff checks are clean.