Repository navigation
fix(mir-importer): preserve emitted diverging device calls - #1364
Merged
nihalpasham merged 6 commits intoOct 19, 2026
Merged
Conversation
Signed-off-by: Yunus Mutlu <mutluyunus708@gmail.com>
YunusMutlu
force-pushed
the
fix/preserve-direct-diverging-calls
branch
from
October 13, 2026 12:09
7eaaf30 to
f2bdfa3
Compare
…ned traps Split is_emitted_function into a name-based is_emitted_name that it calls, so the per-run set can be tested without a rustc session, and add that test: the set installed for one pipeline run replaces the previous run's set instead of merging into it. A leftover name would keep a diverging call to a function the current run never emits. Make the translate_call comment at the diverging-call arm accurate. The arm fires for any visibly uninhabited destination type, because that is when rustc clears the call target, and two cases keep the trap: a call through a function pointer resolves no instance, and a callee whose path matches the panic-entry predicate is trapped by block translation before translate_call runs. Signed-off-by: nihalpasham <nihalp@nvidia.com>
The shape check asserted one of the three call sites the fix changes in diverging_callable, read only the pre-optimization IR, had no control for the trap fallback, and rejected the `!dbg` form of `unreachable` that a --device-debug build emits. It now asserts the two apply_never calls and the write_then_diverge call, each followed by `unreachable`, accepts the `!dbg` form, and, when the direct route wrote PTX, reads the kernel entry: the sentinel store or a call to the helper must survive opt and llc, with one trap for the control. The control is panic_only, a `-> !` function whose body is only a panic: the collector does not emit it, so its call site must still lower to the device trap. Built with the previous backend the check exits 1; with the fix it passes on the direct, NVVM and device-debug builds. The module doc now says the diverging calls are emitted, not executed, the README describes what the check covers, and the script carries the executable bit like most of its siblings. Signed-off-by: nihalpasham <nihalp@nvidia.com>
A device function declared `-> !` with a real body is called normally and the call is followed by `unreachable`, so its work before diverging is kept. Panic entry points, `-> !` bodies that are nothing but a panic, and calls through function pointers still lower to the device trap. State this in the panic-behavior section and in the Panic / Unwinding row of the supported-features table. Signed-off-by: nihalpasham <nihalp@nvidia.com>
A one-page figure for the book and the pull request, in the style of the tile-libraries direct-linkage figure. Signed-off-by: nihalpasham <nihalp@nvidia.com>
Collaborator
|
/ok to test 4f11e50 |
Collaborator
|
Thanks, this is the right fix and it matches what rustc's own backend does: emit the call, then
At |
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.
What this adds
A direct call to a
#[device] fn ... -> !was lowered totrap;by the importer, even when the callee's body had been compiled, so whatever the function did before diverging (an error store, say) was lost. The importer now does what rustc's own backend does: emit the call, thenunreachable. Only panic entry points,-> !bodies that are nothing but a panic, and calls through function pointers still lower to the trap.What we fixed
function_item_callcheck covers all three diverging call sites, reads the PTX entry when one exists, accepts--device-debugoutput, and has a retained-trap control (panic_only).facts.rshas a unit test for the emitted-function set (install, check, replace, gone).-> !calls still trap.Implementation
translate_call: for a MIRCallwith no return edge, resolve the callee and check the pipeline's emitted set. In the set meanscallthenunreachable; otherwisetrap;thenunreachable, as before.is_emitted_functiondelegates to a name-basedis_emitted_name.flag == 4arm calling a panic-only-> !helper, which the collector skips, so its call site must still trap.Verification
Checked at
4f11e505e(nightly-2026-10-11, RTX 5090):cargo test -p mir-importer --all-targets, clippy and rustdoc with warnings as errors, fmt, the example's fmt and clippy gates, the 18 guards and the lock check: clean.call+unreachablepairs, and the PTX stores the sentinel before its self-loop with notrap;on that path.cargo oxide run function_item_call: PASS with memcheck clean, through the llc route and the libNVVM route.device_panic_trapstill traps out of range.Caveats
-> !body that stores and then panics within one or two blocks is still skipped by the collector's placeholder heuristic, so that store is lost before the trap. Separate issue.Closes #1363.