resolve repeated attribute fixme
This commit is contained in:
parent
f5c37c3732
commit
f9d0a14639
3 changed files with 17 additions and 14 deletions
|
@ -282,22 +282,35 @@ mod llvm_enzyme {
|
||||||
span,
|
span,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never)]`.
|
||||||
|
fn same_attribute(attr: &ast::AttrKind, item: &ast::AttrKind) -> bool {
|
||||||
|
match (attr, item) {
|
||||||
|
(ast::AttrKind::Normal(a), ast::AttrKind::Normal(b)) => {
|
||||||
|
let a = &a.item.path;
|
||||||
|
let b = &b.item.path;
|
||||||
|
a.segments.len() == b.segments.len()
|
||||||
|
&& a.segments.iter().zip(b.segments.iter()).all(|(a, b)| a.ident == b.ident)
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't add it multiple times:
|
// Don't add it multiple times:
|
||||||
let orig_annotatable: Annotatable = match item {
|
let orig_annotatable: Annotatable = match item {
|
||||||
Annotatable::Item(ref mut iitem) => {
|
Annotatable::Item(ref mut iitem) => {
|
||||||
if !iitem.attrs.iter().any(|a| a.id == attr.id) {
|
if !iitem.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
|
||||||
iitem.attrs.push(attr);
|
iitem.attrs.push(attr);
|
||||||
}
|
}
|
||||||
if !iitem.attrs.iter().any(|a| a.id == inline_never.id) {
|
if !iitem.attrs.iter().any(|a| same_attribute(&a.kind, &inline_never.kind)) {
|
||||||
iitem.attrs.push(inline_never.clone());
|
iitem.attrs.push(inline_never.clone());
|
||||||
}
|
}
|
||||||
Annotatable::Item(iitem.clone())
|
Annotatable::Item(iitem.clone())
|
||||||
}
|
}
|
||||||
Annotatable::AssocItem(ref mut assoc_item, i @ Impl) => {
|
Annotatable::AssocItem(ref mut assoc_item, i @ Impl) => {
|
||||||
if !assoc_item.attrs.iter().any(|a| a.id == attr.id) {
|
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
|
||||||
assoc_item.attrs.push(attr);
|
assoc_item.attrs.push(attr);
|
||||||
}
|
}
|
||||||
if !assoc_item.attrs.iter().any(|a| a.id == inline_never.id) {
|
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &inline_never.kind)) {
|
||||||
assoc_item.attrs.push(inline_never.clone());
|
assoc_item.attrs.push(inline_never.clone());
|
||||||
}
|
}
|
||||||
Annotatable::AssocItem(assoc_item.clone(), i)
|
Annotatable::AssocItem(assoc_item.clone(), i)
|
||||||
|
|
|
@ -798,16 +798,10 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
|
||||||
|
|
||||||
// check for exactly one autodiff attribute on placeholder functions.
|
// check for exactly one autodiff attribute on placeholder functions.
|
||||||
// There should only be one, since we generate a new placeholder per ad macro.
|
// There should only be one, since we generate a new placeholder per ad macro.
|
||||||
// FIXME(ZuseZ4): re-enable this check. Currently we add multiple, which doesn't cause harm but
|
|
||||||
// looks strange e.g. under cargo-expand.
|
|
||||||
let attr = match &attrs[..] {
|
let attr = match &attrs[..] {
|
||||||
[] => return None,
|
[] => return None,
|
||||||
[attr] => attr,
|
[attr] => attr,
|
||||||
// These two attributes are the same and unfortunately duplicated due to a previous bug.
|
|
||||||
[attr, _attr2] => attr,
|
|
||||||
_ => {
|
_ => {
|
||||||
//FIXME(ZuseZ4): Once we fixed our parser, we should also prohibit the two-attribute
|
|
||||||
//branch above.
|
|
||||||
span_bug!(attrs[1].span(), "cg_ssa: rustc_autodiff should only exist once per source");
|
span_bug!(attrs[1].span(), "cg_ssa: rustc_autodiff should only exist once per source");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -73,10 +73,6 @@ pub fn df4() {
|
||||||
}
|
}
|
||||||
#[rustc_autodiff]
|
#[rustc_autodiff]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[rustc_autodiff]
|
|
||||||
#[inline(never)]
|
|
||||||
#[rustc_autodiff]
|
|
||||||
#[inline(never)]
|
|
||||||
pub fn f5(x: &[f64], y: f64) -> f64 {
|
pub fn f5(x: &[f64], y: f64) -> f64 {
|
||||||
::core::panicking::panic("not implemented")
|
::core::panicking::panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue