Skip to content

Commit ffdbffb

Browse files
authored
add rust error for activity to arg count missmatch (#111)
1 parent 948848d commit ffdbffb

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ builtin_macros_autodiff_unknown_activity = did not recognize activity {$act}
55
builtin_macros_autodiff = autodiff must be applied to function
66
builtin_macros_autodiff_not_build = this rustc version does not support autodiff
77
builtin_macros_autodiff_mode_activity = {$act} can not be used in {$mode} Mode
8+
builtin_macros_autodiff_number_activities = expected {$expected} activities, but found {$found}
89
builtin_macros_autodiff_mode = unknown Mode: `{$mode}`. Use `Forward` or `Reverse`
910
builtin_macros_autodiff_ty_activity = {$act} can not be used for this type
1011

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,15 @@ fn gen_enzyme_decl(
493493
x: &AutoDiffAttrs,
494494
span: Span,
495495
) -> (ast::FnSig, Vec<String>, Vec<Ident>) {
496+
let sig_args = sig.decl.inputs.len() + if sig.decl.output.has_ret() { 1 } else { 0 };
497+
let num_activities = x.input_activity.len() + if x.has_ret_activity() { 1 } else { 0 };
498+
if sig_args != num_activities {
499+
ecx.sess.dcx().emit_fatal(errors::AutoDiffInvalidNumberActivities {
500+
span,
501+
expected: sig_args,
502+
found: num_activities,
503+
});
504+
}
496505
assert!(sig.decl.inputs.len() == x.input_activity.len());
497506
assert!(sig.decl.output.has_ret() == x.has_ret_activity());
498507
let mut d_decl = sig.decl.clone();

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ pub(crate) struct AutoDiffInvalidTypeForActivity {
177177
pub(crate) span: Span,
178178
pub(crate) act: String,
179179
}
180-
180+
#[derive(Diagnostic)]
181+
#[diag(builtin_macros_autodiff_number_activities)]
182+
pub(crate) struct AutoDiffInvalidNumberActivities {
183+
#[primary_span]
184+
pub(crate) span: Span,
185+
pub(crate) expected: usize,
186+
pub(crate) found: usize,
187+
}
181188
#[derive(Diagnostic)]
182189
#[diag(builtin_macros_autodiff_mode_activity)]
183190
pub(crate) struct AutoDiffInvalidApplicationModeAct {

0 commit comments

Comments
 (0)