Repository navigation
Conversation
15aeb9f to
b629e11
Compare
|
Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs cc @ZuseZ4 |
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
There was a problem hiding this comment.
This might fix the ICE, but the way this macro forwards attributes is fundamentally broken, it should be properly fixed.
The problem is that the macro generates smth like
#[other_attr]
#[rustc_autodif]
fn foo(){}and if other_attr is a macro, it gets to observe the implementation details of the autodiff macros. It also exposes errors such as the one encountered here, from when we tried putting #[rustc_test_entrypoint_marker] in the expansion of the test macro.
Instead, there should be an allowlist for attributes, and the original example should emit an error. See
rust/compiler/rustc_builtin_macros/src/eii.rs
Line 202 in 6a98084
eii macro does it.From a glance it looks like currently only the inline attribute is forwarded.
|
Reminder, once the PR becomes ready for a review, use |
| @@ -363,7 +360,7 @@ mod llvm_enzyme { | |||
| (ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => { | |||
| let a = &a.item.path; | |||
There was a problem hiding this comment.
I found another bug while changing the code😅, the current code of same_attribute only checks whether the paths are the same not including the argument. This means we're adding #[inline(never)] to the generated function if there's an inline attribute on the original function, even when it's #[inline(always)] or #[inline].
#![feature(prelude_import)]
#![no_std]
#![feature(macro_attr)]
#![feature(autodiff)]
extern crate std;
#[prelude_import]
use ::std::prelude::rust_2015::*;
macro_rules! forward_referenced_attr { attr() {} => {} }
use std::autodiff::autodiff_reverse;
#[inline(always)]
#[rustc_autodiff]
fn foo() {}
#[rustc_autodiff(Reverse, 1, None)]
#[inline(never)]
fn Active() { ::core::intrinsics::autodiff(foo as fn(), Active, ()) }
fn main() {}There was a problem hiding this comment.
I will also fix this in this PR.
b629e11 to
72f049d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
72f049d to
3ff6ff3
Compare
| if is_builtin_attr_name(name) | ||
| || name == sym::autodiff_forward | ||
| || name == sym::autodiff_reverse => | ||
| { |
There was a problem hiding this comment.
This checks that the macro is named autodiff_forward or autodiff_reverse, not that it is.
item.name() is also None if it used like #[std::autodiff::autodiff_reverse]
There was a problem hiding this comment.
Unfortunately there is no way to tell that it really is that macro.
There was a problem hiding this comment.
I vaguely remember that someone (@oli-obk ?) was working on adding name or type resolution to some macros. It sounds quite tricky to get such a prototype merged with all the obvious challenges. But if there's a chance, it might be worth adding a FIXME?
Other than that, a user written macro with name should be rejected, see the visibility.rs ui test.
There is one ui test using #[std::autodiff::autodiff_reverse], but I don't see too many users writing it.
|
@ZuseZ4 Can you explain the purpose of It's only retrieved once, like let Some(Some(mut diff_attrs)) =
find_attr!(tcx, fn_diff.def_id(), RustcAutodiff(attr) => attr.clone())
else {
bug!("could not find autodiff attrs")
};so it does appear like |
|
@mejrs thanks for helping with the review. The @Sa4dUs do you know if we still need rustc_autodiff (with no args)? |
3ff6ff3 to
80e3289
Compare
80e3289 to
84b41bf
Compare
|
☔ The latest upstream changes (presumably #166350) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Fixes #152889
outer_normal_attrdidn't add token stream to the attribute. This will cause an ICE when rustc tries to convert the ast node into token stream and send to a macro (e.g proc macro or attribute macro rules).LLM disclosure: I locate the cause of this issue by myself. I only ask the LLM what is the common/correct way to create an attribute in a builtin macro, and it suggest
attr_word.