Skip to content

Commit f9d0a14

Browse files
committed
resolve repeated attribute fixme
1 parent f5c37c3 commit f9d0a14

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

Diff for: compiler/rustc_builtin_macros/src/autodiff.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -282,22 +282,35 @@ mod llvm_enzyme {
282282
span,
283283
};
284284

285+
// We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
286+
fn same_attribute(attr: &ast::AttrKind, item: &ast::AttrKind) -> bool {
287+
match (attr, item) {
288+
(ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => {
289+
let a = &a.item.path;
290+
let b = &b.item.path;
291+
a.segments.len() == b.segments.len()
292+
&& a.segments.iter().zip(b.segments.iter()).all(|(a, b)| a.ident == b.ident)
293+
}
294+
_ => false,
295+
}
296+
}
297+
285298
// Don't add it multiple times:
286299
let orig_annotatable: Annotatable = match item {
287300
Annotatable::Item(ref mut iitem) => {
288-
if !iitem.attrs.iter().any(|a| a.id == attr.id) {
301+
if !iitem.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
289302
iitem.attrs.push(attr);
290303
}
291-
if !iitem.attrs.iter().any(|a| a.id == inline_never.id) {
304+
if !iitem.attrs.iter().any(|a| same_attribute(&a.kind, &inline_never.kind)) {
292305
iitem.attrs.push(inline_never.clone());
293306
}
294307
Annotatable::Item(iitem.clone())
295308
}
296309
Annotatable::AssocItem(ref mut assoc_item, i @ Impl) => {
297-
if !assoc_item.attrs.iter().any(|a| a.id == attr.id) {
310+
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
298311
assoc_item.attrs.push(attr);
299312
}
300-
if !assoc_item.attrs.iter().any(|a| a.id == inline_never.id) {
313+
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &inline_never.kind)) {
301314
assoc_item.attrs.push(inline_never.clone());
302315
}
303316
Annotatable::AssocItem(assoc_item.clone(), i)

Diff for: compiler/rustc_codegen_ssa/src/codegen_attrs.rs

-6
Original file line numberDiff line numberDiff line change
@@ -798,16 +798,10 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
798798

799799
// check for exactly one autodiff attribute on placeholder functions.
800800
// There should only be one, since we generate a new placeholder per ad macro.
801-
// FIXME(ZuseZ4): re-enable this check. Currently we add multiple, which doesn't cause harm but
802-
// looks strange e.g. under cargo-expand.
803801
let attr = match &attrs[..] {
804802
[] => return None,
805803
[attr] => attr,
806-
// These two attributes are the same and unfortunately duplicated due to a previous bug.
807-
[attr, _attr2] => attr,
808804
_ => {
809-
//FIXME(ZuseZ4): Once we fixed our parser, we should also prohibit the two-attribute
810-
//branch above.
811805
span_bug!(attrs[1].span(), "cg_ssa: rustc_autodiff should only exist once per source");
812806
}
813807
};

Diff for: tests/pretty/autodiff_forward.pp

-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
}
7474
#[rustc_autodiff]
7575
#[inline(never)]
76-
#[rustc_autodiff]
77-
#[inline(never)]
78-
#[rustc_autodiff]
79-
#[inline(never)]
8076
pub fn f5(x: &[f64], y: f64) -> f64 {
8177
::core::panicking::panic("not implemented")
8278
}

0 commit comments

Comments
 (0)