Skip to content

Add conformance coverage for Option and Result enum state transitions #825

Closed

Description

@uurl

Summary

Add focused device-side conformance coverage for enum state transitions exercised by:

  • Option::take
  • Option::replace
  • Option::get_or_insert
  • Result::map
  • Result::map_err
  • Result::and_then
  • Result::or_else

cuda-oxide already has the underlying enum machinery required by these operations. The missing piece is an end-to-end regression that exercises the corresponding core APIs directly and verifies their resulting discriminants and payloads on the GPU.

Motivation

These APIs stress more than simple enum construction.

Option::take and Option::replace are implemented in terms of mem::replace, while Option::get_or_insert conditionally constructs a Some value and returns a mutable reference to its payload.

The resulting device-side behavior combines:

enum construction
    -> discriminant read
    -> conditional control flow
    -> whole-enum replacement
    -> payload extraction/addressing
    -> payload mutation

The selected Result combinators similarly exercise both payload-preserving and variant-changing control flow:

Ok  -> Ok
Ok  -> Err
Err -> Err
Err -> Ok

Existing enum regressions cover the underlying compiler primitives, including enum layout, construction, discriminant handling, niche encoding, payload access, and payload mutation. There is currently no focused example that drives these standard Option and Result APIs through those paths together.

Proposed coverage

Add an enum_state_transitions example containing two independent kernels.

Option

Use a runtime-selected initial Option<u32> so both Some and None paths remain observable.

Cover:

Option::take

Verify:

Some(value) -> None, returns Some(value)
None        -> None, returns None

Option::replace

Verify:

Some(old) -> Some(new), returns Some(old)
None      -> Some(new), returns None

Option::get_or_insert

Verify both cases:

None
  -> insert Some(value)
  -> return &mut payload
  -> mutate payload

Some(existing)
  -> preserve existing payload
  -> return &mut existing payload
  -> mutate payload

This also exercises payload addressing through the mutable reference returned by get_or_insert.

Result

Use a runtime-selected Result<u32, u32> and cover:

  • Result::map
  • Result::map_err
  • Result::and_then
  • Result::or_else

The test should include both starting variants and explicitly verify variant-changing cases:

Ok  -> Err via and_then
Err -> Ok  via or_else

Every intermediate value should be matched and encoded into an integer returned to the host so that the resulting discriminant and payload are observed explicitly.

Scope

This issue is intended as conformance coverage for already-supported enum operations.

It does not require new enum representation or lowering machinery unless the regression exposes a previously unknown compiler defect.

It intentionally does not expand into:

  • niche-layout-specific coverage already handled by existing regressions
  • custom enum ABI coverage
  • panic or unwrap failure paths
  • allocator-backed types
  • Result combinators unrelated to enum construction or variant transitions

Acceptance criteria

The example should pass both optimized and low-MIR-optimization device execution:

cargo oxide run enum_state_transitions

CUDA_OXIDE_NO_OPT=1 \
cargo oxide run enum_state_transitions

It should also pass both scoped smoketest modes:

scripts/smoketest.sh -o '^enum_state_transitions$'

scripts/smoketest.sh \
  --compile-only \
  -o '^enum_state_transitions$'

The standalone example should pass:

cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings

Expected runtime output:

=== enum_state_transitions ===
PASS: Option::take
PASS: Option::replace
PASS: Option::get_or_insert
PASS: Result::map
PASS: Result::map_err
PASS: Result::and_then
PASS: Result::or_else
PASS: enum_state_transitions

Activity

  1. added
    enhancement
    codegen
    tests
    on Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenenhancementtests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions