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

Merged
merged 7 commits into from
May 28, 2025

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)].

@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

@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.

@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.

@Sa4dUs Sa4dUs marked this pull request as ready for review May 20, 2025 16:52
@rustbot
Copy link
Collaborator

rustbot commented May 20, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

Sa4dUs added 5 commits May 21, 2025 07:24
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.
@ZuseZ4
Copy link
Member

ZuseZ4 commented May 25, 2025

Now that we can't get the Forward/Reverse symbols from the input, using sym to create them seems like the right thing to do. We already have a few UI tests to make sure that our current autodiff symbol there doesn't colide with similar named user types, so adding Forward/Reverse to the list should also be fine.
lgtm, with the small doc improvement.

@ZuseZ4
Copy link
Member

ZuseZ4 commented May 26, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented May 26, 2025

📌 Commit c6c2fde 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 May 26, 2025
tgross35 added a commit to tgross35/rust that referenced this pull request May 28, 2025
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

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)]`.
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141407 (Refactor the two-phase check for impls and impl items)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request May 28, 2025
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

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)]`.
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141407 (Refactor the two-phase check for impls and impl items)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request May 28, 2025
Rollup of 7 pull requests

Successful merges:

 - #140369 (Add data_ptr method to Mutex and RwLock)
 - #140697 (Split `autodiff` into `autodiff_forward` and `autodiff_reverse`)
 - #141404 (Improve intrinsic handling in cg_ssa)
 - #141411 (rustdoc: linking to a local proc macro no longer warns)
 - #141548 (consider glob imports in cfg suggestion)
 - #141627 (Drop-build cleanups)
 - #141670 (Fix ICE in tokenstream with contracts from parser recovery)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7f5f29b into rust-lang:master May 28, 2025
7 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 28, 2025
rust-timer added a commit that referenced this pull request May 28, 2025
Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4

Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

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)]`.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request May 30, 2025
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

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)]`.
@jasalper jasalper mentioned this pull request May 31, 2025
7 tasks
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-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. 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