-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
fix usage of autodiff
macro with inner functions
#138314
Conversation
Thank you for looking into this! Yes, adding a test to avoid regressions would be great. |
@bors delegate=ZuseZ4 |
@ZuseZ4 , thank you for providing more insights into this! The pretty printer tests do indeed sound like a good place for this. Also I've got to express how cool and insightful the docs are -- this is really not something to be taken as granted :D However, while looking into this I noticed that both It makes sense to open a separate PR fixing these issues before continuing with the inner function test, right? |
Yes I agree, I think one reason why I ended up being a rustc developer rather than working on other projects is the documentation. I don't have a pc this weekend, but my batching PR contains fixes for those. You can cherry pick them if you want, or I'll make a PR for that on Monday. I had hoped to get it done for the weekend, but unfortunately ran out of time. |
Okidoki! Don't stress, I'll just rebase when the changes are in master. |
Autodiff cleanups Splitting out some cleanups to reduce the size of my batching PR and simplify `@haenoe` 's [PR](rust-lang#138314). r? `@oli-obk` Tracking: - rust-lang#124509
Autodiff cleanups Splitting out some cleanups to reduce the size of my batching PR and simplify ``@haenoe`` 's [PR](rust-lang#138314). r? ``@oli-obk`` Tracking: - rust-lang#124509
Autodiff cleanups Splitting out some cleanups to reduce the size of my batching PR and simplify ```@haenoe``` 's [PR](rust-lang#138314). r? ```@oli-obk``` Tracking: - rust-lang#124509
Autodiff cleanups Splitting out some cleanups to reduce the size of my batching PR and simplify ````@haenoe```` 's [PR](rust-lang#138314). r? ````@oli-obk```` Tracking: - rust-lang#124509
Rollup merge of rust-lang#138627 - EnzymeAD:autodiff-cleanups, r=oli-obk Autodiff cleanups Splitting out some cleanups to reduce the size of my batching PR and simplify ``@haenoe`` 's [PR](rust-lang#138314). r? ``@oli-obk`` Tracking: - rust-lang#124509
☔ The latest upstream changes (presumably #138791) made this pull request unmergeable. Please resolve the merge conflicts. |
5024ae1
to
35812e2
Compare
Hey @ZuseZ4 |
looks good, but I will check again later when I'm on my computer. For the test I would just add a second autodiff macro with an in any way different config to the same function/test, to verify that even after future refactors we don't add inline or autodiff attributes multiple time to the source functions. |
☔ The latest upstream changes (presumably #138933) made this pull request unmergeable. Please resolve the merge conflicts. |
35812e2
to
013edbe
Compare
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
Hey @ZuseZ4! |
This comment has been minimized.
This comment has been minimized.
No worries, and the test looks good, thanks! |
013edbe
to
928f4e8
Compare
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
@bors r- |
Unfortunate, but as predicted. @haenoe the diff should hopefully be easy to fix, can you rebase one more time, so we can add it back to the CI? |
☔ The latest upstream changes (presumably #139396) made this pull request unmergeable. Please resolve the merge conflicts. |
Yess of course! Will look at it when I'm at my computer in ~2 hours. |
- fix errors caused by the move of `ast::Item::ident` (see rust-lang#138740) - move the logic of getting `sig`, `vis`, and `ident` from two seperate `match` statements into one (less repetition especially with the nested `match`)
Verify that the expanded `inline` and `rustc_autodiff` macros are not duplicated.
284672a
to
0108d40
Compare
This took longer than expected, because I ran into some very weird |
This comment has been minimized.
This comment has been minimized.
0108d40
to
bf69443
Compare
Yes, I also sometimes need to recompile llvm on updates, worst case I @bors r+ rollup |
…ZuseZ4 fix usage of `autodiff` macro with inner functions This PR adds additional handling into the expansion step of the `std::autodiff` macro (in `compiler/rustc_builtin_macros/src/autodiff.rs`), which allows the macro to be applied to inner functions. ```rust #![feature(autodiff)] use std::autodiff::autodiff; fn main() { #[autodiff(d_inner, Forward, Dual, DualOnly)] fn inner(x: f32) -> f32 { x * x } } ``` Previously, the compiler didn't allow this due to only handling `Annotatable::Item` and `Annotatable::AssocItem` and missing the handling of `Annotatable::Stmt`. This resulted in the rather generic error ``` error: autodiff must be applied to function --> src/main.rs:6:5 | 6 | / fn inner(x: f32) -> f32 { 7 | | x * x 8 | | } | |_____^ error: could not compile `enzyme-test` (bin "enzyme-test") due to 1 previous error ``` This issue was originally reported [here](EnzymeAD#184). Quick question: would it make sense to add a ui test to ensure there is no regression on this? This is my first contribution, so I'm extra grateful for any piece of feedback!! :D r? `@oli-obk` Tracking issue for autodiff: rust-lang#124509
Rollup of 4 pull requests Successful merges: - rust-lang#138314 (fix usage of `autodiff` macro with inner functions) - rust-lang#138766 (coverage: Deal with unused functions and their names in one place) - rust-lang#139298 (Allow for missing invisible close delim when reparsing an expression.) - rust-lang#139426 (Make the UnifyKey and UnifyValue imports non-nightly) r? `@ghost` `@rustbot` modify labels: rollup
Had a weird thing happen, where adding |
My experience is that if you rebase across an LLVM update, then the very first But I also have to say that this specific rebase was strange, when I updated my local rust builds, two of them ran into an LLVM issue that some option was already known, so I had to delete the whole build folder, this happens rarely. If you in the future run into an issue where x isn't rebuilding all of llvm, but everything starting from But after all, the vast majority of rustc devs don't build LLVM at all, so there are also fewer people to test, report, and fix bootstrap issues related to it. I hope to get rid of the requirement of building LLVM from source, but that requires fighting cmake, something I am not too keen about. |
Rollup of 5 pull requests Successful merges: - rust-lang#138314 (fix usage of `autodiff` macro with inner functions) - rust-lang#139426 (Make the UnifyKey and UnifyValue imports non-nightly) - rust-lang#139431 (Remove LLVM 18 inline ASM span fallback) - rust-lang#139456 (style guide: add let-chain rules) - rust-lang#139467 (More trivial tweaks) r? `@ghost` `@rustbot` modify labels: rollup
Yes the option thingy was the problem I ran into also! Do any of the other "experimental" features (thinking primarily of gpu offloading) that need some custom |
Rollup merge of rust-lang#138314 - haenoe:autodiff-inner-function, r=ZuseZ4 fix usage of `autodiff` macro with inner functions This PR adds additional handling into the expansion step of the `std::autodiff` macro (in `compiler/rustc_builtin_macros/src/autodiff.rs`), which allows the macro to be applied to inner functions. ```rust #![feature(autodiff)] use std::autodiff::autodiff; fn main() { #[autodiff(d_inner, Forward, Dual, DualOnly)] fn inner(x: f32) -> f32 { x * x } } ``` Previously, the compiler didn't allow this due to only handling `Annotatable::Item` and `Annotatable::AssocItem` and missing the handling of `Annotatable::Stmt`. This resulted in the rather generic error ``` error: autodiff must be applied to function --> src/main.rs:6:5 | 6 | / fn inner(x: f32) -> f32 { 7 | | x * x 8 | | } | |_____^ error: could not compile `enzyme-test` (bin "enzyme-test") due to 1 previous error ``` This issue was originally reported [here](EnzymeAD#184). Quick question: would it make sense to add a ui test to ensure there is no regression on this? This is my first contribution, so I'm extra grateful for any piece of feedback!! :D r? `@oli-obk` Tracking issue for autodiff: rust-lang#124509
This PR adds additional handling into the expansion step of the
std::autodiff
macro (incompiler/rustc_builtin_macros/src/autodiff.rs
), which allows the macro to be applied to inner functions.Previously, the compiler didn't allow this due to only handling
Annotatable::Item
andAnnotatable::AssocItem
and missing the handling ofAnnotatable::Stmt
. This resulted in the rather generic errorThis issue was originally reported here.
Quick question: would it make sense to add a ui test to ensure there is no regression on this?
This is my first contribution, so I'm extra grateful for any piece of feedback!! :D
r? @oli-obk
Tracking issue for autodiff: #124509