Skip to content

Prevent ICE in autodiff validation by emitting user-friendly errors #138231

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

Sa4dUs
Copy link
Contributor

@Sa4dUs Sa4dUs commented Mar 8, 2025

This PR moves valid_ret_activity and valid_input_activity checks to the macro expansion phase in compiler/rustc_builtin_macros/src/autodiff.rs, replacing the following internal compiler error (ICE):

error: internal compiler error:  
compiler/rustc_codegen_ssa/src/codegen_attrs.rs:935:13:  
Invalid input activity Dual for Reverse mode  

with a more user-friendly message.

The issue specifically affected the test file tests/ui/autodiff/autodiff_illegal.rs, impacting the functions f5 and f6.

The ICE can be reproduced by following Enzyme's Rustbook installation guide.

Additionally, this PR adds tests for invalid return activity in autodiff_illegal.rs, which previously triggered an unnoticed ICE before these fixes.

r? @oli-obk

@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2025

r? @estebank

rustbot has assigned @estebank.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 8, 2025
@rust-log-analyzer

This comment has been minimized.

builtin_macros_autodiff_ty_activity = {$act} can not be used for this type


Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why I had builtin_macros_autodiff_unknown_activity not grouped together with the rest, but maybe combine them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've just grouped them so all autodiff-related errors are together.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Mar 10, 2025

@rustbot label +F-autodiff

@rustbot rustbot added the F-autodiff `#![feature(autodiff)]` label Mar 10, 2025
@rustbot rustbot assigned oli-obk and unassigned estebank Mar 10, 2025
@Sa4dUs Sa4dUs marked this pull request as ready for review March 10, 2025 09:36
@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2025

Some changes occurred in compiler/rustc_codegen_ssa/src/codegen_attrs.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@oli-obk
Copy link
Contributor

oli-obk commented Mar 10, 2025

@bors delegate=ZuseZ4

@bors
Copy link
Collaborator

bors commented Mar 10, 2025

✌️ @ZuseZ4, you can now approve this pull request!

If @oli-obk told you to "r=me" after making some further change, please make that change, then do @bors r=@oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Mar 10, 2025

Contrary to what the bot said, feel free to r+ yourself

@ZuseZ4
Copy link
Member

ZuseZ4 commented Mar 11, 2025

@Sa4dUs It's not strictly necessary, but if you have some time, could you please remove the Remove test_ad commit and just update the previous commit to not include the binary blob? When possible it's preferable to have a cleaner history and let every commit build on it's own, since bors will just apply all of your commits unchanged (and not squash them).

@Sa4dUs
Copy link
Contributor Author

Sa4dUs commented Mar 11, 2025

Done! Sorry for the oversight.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Mar 11, 2025

Thanks! @bors r+

@bors
Copy link
Collaborator

bors commented Mar 11, 2025

📌 Commit 8546e01 has been approved by ZuseZ4

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 11, 2025
@oli-obk
Copy link
Contributor

oli-obk commented Mar 11, 2025

@bors rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 11, 2025
Prevent ICE in autodiff validation by emitting user-friendly errors

This PR moves `valid_ret_activity` and `valid_input_activity` checks to the macro expansion phase in compiler/rustc_builtin_macros/src/autodiff.rs, replacing the following internal compiler error (ICE):
```
error: internal compiler error:
compiler/rustc_codegen_ssa/src/codegen_attrs.rs:935:13:
Invalid input activity Dual for Reverse mode
```
with a more user-friendly message.

The issue specifically affected the test file `tests/ui/autodiff/autodiff_illegal.rs`, impacting the functions `f5` and `f6`.

The ICE can be reproduced by following [Enzyme's Rustbook](https://enzymead.github.io/rustbook/installation.html) installation guide.

Additionally, this PR adds tests for invalid return activity in `autodiff_illegal.rs`, which previously triggered an unnoticed ICE before these fixes.

r? `@oli-obk`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 11, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#137715 (Allow int literals for pattern types with int base types)
 - rust-lang#138002 (Disable CFI for weakly linked syscalls)
 - rust-lang#138051 (Add support for downloading GCC from CI)
 - rust-lang#138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - rust-lang#138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - rust-lang#138256 (Do not feed anon const a type that references generics that it does not have)
 - rust-lang#138284 (Do not write user type annotation for const param value path)
 - rust-lang#138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - rust-lang#138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - rust-lang#138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit caa2d00 into rust-lang:master Mar 12, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 12, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Mar 14, 2025
…iaskrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#137715 (Allow int literals for pattern types with int base types)
 - rust-lang#138002 (Disable CFI for weakly linked syscalls)
 - rust-lang#138051 (Add support for downloading GCC from CI)
 - rust-lang#138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - rust-lang#138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - rust-lang#138256 (Do not feed anon const a type that references generics that it does not have)
 - rust-lang#138284 (Do not write user type annotation for const param value path)
 - rust-lang#138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - rust-lang#138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - rust-lang#138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants