1
Fork 0

Single commit implementing the enzyme/autodiff frontend

Co-authored-by: Lorenz Schmidt <bytesnake@mailbox.org>
This commit is contained in:
Manuel Drehwald 2024-10-11 19:13:31 +02:00
parent 52fd998399
commit 624c071b99
17 changed files with 1384 additions and 1 deletions

View file

@ -243,6 +243,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_generic_attr(hir_id, attr, target, Target::Fn);
self.check_proc_macro(hir_id, target, ProcMacroKind::Derive)
}
[sym::autodiff, ..] => {
self.check_autodiff(hir_id, attr, span, target)
}
[sym::coroutine, ..] => {
self.check_coroutine(attr, target);
}
@ -2345,6 +2348,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.dcx().emit_err(errors::RustcPubTransparent { span, attr_span });
}
}
/// Checks if `#[autodiff]` is applied to an item other than a function item.
fn check_autodiff(&self, _hir_id: HirId, _attr: &Attribute, span: Span, target: Target) {
debug!("check_autodiff");
match target {
Target::Fn => {}
_ => {
self.dcx().emit_err(errors::AutoDiffAttr { attr_span: span });
self.abort.set(true);
}
}
}
}
impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {

View file

@ -20,6 +20,14 @@ use crate::lang_items::Duplicate;
#[diag(passes_incorrect_do_not_recommend_location)]
pub(crate) struct IncorrectDoNotRecommendLocation;
#[derive(Diagnostic)]
#[diag(passes_autodiff_attr)]
pub(crate) struct AutoDiffAttr {
#[primary_span]
#[label]
pub attr_span: Span,
}
#[derive(LintDiagnostic)]
#[diag(passes_outer_crate_level_attr)]
pub(crate) struct OuterCrateLevelAttr;