Skip to content

fix(lean-exporter): allocate OpaqueUint IDs from opaque_ids - #1881

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
hs1167:fix/lean-exporter-opaque-ids
Nov 27, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
hs1167:fix/lean-exporter-opaque-ids

Conversation

@hs1167

@hs1167 hs1167 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1880.

What This PR Does

Fixes an oracle-ID aliasing bug in lean-exporter (translate/program.rs) where fallback_rhs_for accepted an explicit ID map parameter and two call sites (mir.extract_array_element and nvvm.clc_query_*) passed the recycled register map &val_ids instead of the monotonic &opaque_ids map:

BEFORE (`main`):
  Block 1:  `ld0 = mir.load(...)`                  ──► `opaque_ids` #7  ──► `OpaqueUint(7, 32)`
  Block 2:  `elem = mir.extract_array_element(..)` ──► `val_ids`    #7  ──► `OpaqueUint(7, 32)`  (COLLISION!)
            Lean treated two unrelated runtime values as equal (`env.opaqueUint t 7`)!

AFTER (This PR):
  `fallback_rhs_for` captures `opaque_ids` directly (and `CtaUint1` on `clc_query_*` also reads
  `opaque_ids`), so every opaque/CTA integer definition receives a strictly increasing ID.

Changes

  • crates/lean-exporter/src/translate/program.rs:
    • Capture opaque_ids directly inside fallback_rhs_for and allocate clc_query_* (CtaUint1 / OpaqueUint) IDs from opaque_ids.
    • Remove the shadowed duplicate "mir.array_element_addr" match arm.
  • crates/lean-exporter/tests/export.rs:
    • Add clc_query_and_array_element_use_distinct_opaque_ids checking global uniqueness and RPO monotonicity across a multi-block collision reproducer and all shipped MIR fixtures.

Verification

  • Lean 4 & Exporter Suite: CUDA_OXIDE_REQUIRE_LEAN=1 cargo test -p lean-exporter --all-targets: PASS
  • Lints & Guards: cargo clippy -p lean-exporter --all-targets -- -D warnings, rustdoc -D warnings, cargo oxide fmt --check, and check-*.sh guards: PASS

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@nihalpasham nihalpasham added cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book formal-verification Compile-time Lean 4 kernel verification (#[verify], oxide-proofs-preview, lean-exporter) bug Something isn't working safety Memory safety, soundness, or undefined behavior codegen Device code-generation pipeline (Rust MIR to IR to PTX) tests Adds or improves test coverage soundness-audit Correctness case under active maintainer audit; not cleared for merge yet labels Nov 27, 2026
@nihalpasham
nihalpasham force-pushed the fix/lean-exporter-opaque-ids branch from 4724cf4 to 2064f25 Compare November 27, 2026 12:16
@nihalpasham nihalpasham removed the soundness-audit Correctness case under active maintainer audit; not cleared for merge yet label Nov 27, 2026
nihalpasham
nihalpasham previously approved these changes Nov 27, 2026

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Rebased onto main and extended opaque_ids allocation + test assertions to MirRhs::CtaUint1 on nvvm.clc_query_* as well.

@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test 2064f25

Capture the per-definition oracle map in the fallback helper. Keep oracle identity separate from the block-local register allocator, and remove a shadowed pointer match arm. Check uniqueness and definition order on the typed exporter output.

Signed-off-by: hs1167 <[email protected]>
Co-authored-by: OpenBot <335604065+openbotgit[bot]@users.noreply.github.com>
Signed-off-by: nihalpasham <[email protected]>
nihalpasham
nihalpasham previously approved these changes Nov 27, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test ddb744f

@nihalpasham
nihalpasham merged commit 8b91bb7 into NVIDIA:main Nov 27, 2026
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book formal-verification Compile-time Lean 4 kernel verification (#[verify], oxide-proofs-preview, lean-exporter) safety Memory safety, soundness, or undefined behavior tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: lean-exporter can reuse an opaque integer ID for distinct definitions

2 participants