Skip to content

Split autodiff into autodiff_forward and autodiff_reverse #140697

New issue

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

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

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Sa4dUs
Copy link
Contributor

@Sa4dUs Sa4dUs commented May 6, 2025

This PR splits #[autodiff] macro so #[autodiff(df, Reverse, args)] would become #[autodiff_reverse(df, args)] and #[autodiff(df, Forward, args)] would become #[autodiff_forwad(df, args)].

Pending tasks:

  • Fix cannot find a built-in macro with name error.
  • Update the tests to reflect the new macro structure.
  • Review the implementation for better code.

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 6, 2025
@rust-log-analyzer

This comment has been minimized.

@ZuseZ4 ZuseZ4 self-assigned this May 6, 2025
@ZuseZ4 ZuseZ4 added the F-autodiff `#![feature(autodiff)]` label May 6, 2025
@ZuseZ4
Copy link
Member

ZuseZ4 commented May 6, 2025

I'd almost bet it has to do with bootstrapping, see e.g. https://github.com/rust-lang/rust/pull/129458/files#diff-ea30f57e78f3b861b784ae315b3ac31358b7cea2aa14a668084ad412de12e586
It will be removed by other people later after landing, that's probably why you didn't see it anymore when just looking at the current code for it. Ping me if that doesn't solve the issue, then I can try to play around with it locally.

@jieyouxu
Copy link
Member

jieyouxu commented May 7, 2025

I don't remember exactly, can built-in attributes be namespaced now? E.g. #[autodiff::forward()] and #[autodiff::reverse()]. That way, only one "top-level" name would cause macro ambiguities from the built-in attribute (autodiff), instead of two.

@ZuseZ4
Copy link
Member

ZuseZ4 commented May 7, 2025

I think :: looks much prettier than _. Our attribute is called rustc_autodiff and not autodiff, so I don't think there will be ambiguities either way.
@jdonszelmann is probably the right person to ask about parsing. (see the question above)

@jieyouxu
Copy link
Member

jieyouxu commented May 7, 2025

Right sorry, I keep forgetting there's two

Pending fix.
```
error: cannot find a built-in macro with name `autodiff_forward`
    --> library\core\src\macros\mod.rs:1542:5
     |
1542 | /     pub macro autodiff_forward($item:item) {
1543 | |         /* compiler built-in */
1544 | |     }
     | |_____^

error: cannot find a built-in macro with name `autodiff_reverse`
    --> library\core\src\macros\mod.rs:1549:5
     |
1549 | /     pub macro autodiff_reverse($item:item) {
1550 | |         /* compiler built-in */
1551 | |     }
     | |_____^

error: could not compile `core` (lib) due to 2 previous errors
```
@Sa4dUs Sa4dUs force-pushed the split-autodiff branch from 34f259b to c47f0e3 Compare May 8, 2025 20:04
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Sa4dUs added 3 commits May 10, 2025 00:58
UI tests are pending, will depend on error messages change.
…des (`Forward`, `Reverse`)

Since the mode is no longer part of `meta_item`, we must insert it manually (otherwise macro expansion with `#[rustc_autodiff]` won't work).

This can be revised later if a more structured representation becomes necessary (using enums, annotated structs, etc).

Some tests are currently failing. I'll address them next.
@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Member

ZuseZ4 commented May 10, 2025

Try build/x86_64-unknown-linux-gnu/llvm/bin/clang-format compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp -i (Adjusted for all the cpp files you touched).

@Sa4dUs
Copy link
Contributor Author

Sa4dUs commented May 10, 2025

I'd say the tidy error it's because compiler/rustc_builtin_macros/messages.ftl has the message builtin_macros_autodiff_mode, but it's not being used. I still need to fix a bug when parsing the arguments (I'm assuming it's a silly mistake with an index or array boundary), and once everything works properly, I'll take care of errors and such, which I assume will need to be adjusted somehow for the new macros.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 13, 2025

☔ The latest upstream changes (presumably #140887) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) F-autodiff `#![feature(autodiff)]` 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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants