Repository navigation
codegen: tighten the standalone compiler's clone, liveness and diagnostic paths - #415
Merged
nihalpasham merged 1 commit intoJul 22, 2026
Merged
Conversation
…stic paths Follow-up to NVIDIA#314's cuda-oxide-codegen extraction, covering the review findings that stand on their own. Compiler::compile clones the caller's module and erases the clone once the destructive pipeline has run. The erase ran as a plain statement after the call, so a panic inside compile_clone unwound past it and leaked the clone in the shared Context arena for the process lifetime. An RAII guard now owns the erase. Operation::erase still runs from Drop, so a panic inside the erase during an unwind aborts; that is left alone and documented, since an erase fails only once the arena is already inconsistent and swallowing the second panic would trade a loud abort for a silent leak. Callers with no further use for a module paid for that clone regardless. Compiler::compile_owned consumes the module and runs the pipeline on the caller's IR directly. mark_kernel_entry and the compile entry points each re-checked that a stored Pliron pointer still names a live builtin.module, in duplicated form. The check is now one helper, validate_live_module_op. CompileOptions gains with_verbose/verbose. The pipeline has always produced progress and target-selection diagnostics behind BackendOptions::verbose, and the standalone API had no way to ask for them. Two paths dropped them even when asked: generate_ptx_with_toolchain discarded everything but the resolved target string, and compile_clone never copied the pipeline's diagnostics into the Compilation. generate_ptx_with_toolchain now returns GeneratedPtx, matching the discovery path, and compile_clone forwards what it receives. Toolchain::discover and Toolchain::from_paths both record which llc and opt they settled on. Reporting nothing left a caller unable to tell which of several installed LLVM versions produced an artifact. The double LLVM-IR render on the libdevice path is now documented in place. The preview renders pre-legalization and the export renders post- legalization through a different export config, so the two texts describe different module states and caching one for the other would be unsound. Removing the second render needs feature detection that works off the IR rather than off rendered text. Signed-off-by: Alejandro Soto Franco <[email protected]>
This was referenced Jul 20, 2026
Collaborator
|
Thanks for the PR. LGTM as submitted.
For example: Reviewer note: all 123 cuda-oxide-codegen tests pass with LLVM 21/22 on PATH (the discover-diagnostic test genuinely executed rather than skipping); crate clippy and fmt are clean. Merge-order caution: siblings #416/#417 touch the same files and will need rebasing after this lands — #416 also rewords the target-selection diagnostic this PR's test greps for. Land this before #410. All hosted CI checks passed on the final head. |
This was referenced Jul 22, 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.
One of three parts of #357, split so each can be reviewed on its own. #357 bundled eight unrelated fixes across 12 files, which put the small ones behind a dependency discussion. The three parts are independent: each applies cleanly to
mainalone, and they merge cleanly in any order. #357 will be closed once all three are open.Sibling parts: #416 (target selection provenance), #417 (scratch directory on tempfile).
Summary
Follow-up to #314's
cuda-oxide-codegenextraction, covering the review findings that stand on their own: a leak on the panic path, an unavoidable module clone, a duplicated liveness check, and diagnostics that the standalone API could neither request nor receive.Changes
EraseGuardowns the erase of the cloned module, so a panic insidecompile_cloneno longer leaks it into the sharedContextarena.Compiler::compile_ownedconsumes the module and runs the pipeline on the caller's IR, making the clone opt-in.validate_live_module_opreplaces the liveness check duplicated betweenmark_kernel_entryand the compile entry points.CompileOptions::with_verbose/verbose, so the standalone API can ask for the diagnostics the pipeline has always produced behindBackendOptions::verbose.generate_ptx_with_toolchainreturnsGeneratedPtx, matching the discovery path, andcompile_cloneforwards the diagnostics it receives.Toolchain::discoverandToolchain::from_pathsboth record whichllcandoptthey selected.Rationale
Two paths dropped diagnostics even when asked for them:
generate_ptx_with_toolchaindiscarded everything but the resolved target string, andcompile_clonenever copied the pipeline's diagnostics into theCompilation. Reporting nothing about toolchain selection left a caller unable to tell which of several installed LLVM versions produced an artifact.Operation::erasestill runs fromDrop, so a panic inside the erase during an unwind aborts. That is left alone and documented: an erase fails only once the arena is already inconsistent, and swallowing the second panic would trade a loud abort for a silent leak.The double render is documented rather than removed. The preview renders pre-legalisation and the export renders post-legalisation through a different export config, so the two texts describe different module states and caching one for the other would be unsound. Removing the second render needs feature detection that works off the IR rather than off rendered text.
Validation
cargo check --workspace --all-targetscargo test -p cuda-oxide-codegen(123 passed)cargo test -p mir-importer(801 passed)cargo clippy --workspace -- -D warningscargo fmt --all -- --check(cd crates/rustc-codegen-cuda && cargo fmt --all -- --check)RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace