1use std::str::FromStr;
2
3use rustc_abi::{Align, ExternAbi};
4use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
5use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
6use rustc_hir::attrs::{AttributeKind, InlineAttr, InstructionSetAttr, UsedBy};
7use rustc_hir::def::DefKind;
8use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
9use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS;
10use rustc_hir::{self as hir, Attribute, LangItem, find_attr, lang_items};
11use rustc_middle::middle::codegen_fn_attrs::{
12 CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
13};
14use rustc_middle::query::Providers;
15use rustc_middle::span_bug;
16use rustc_middle::ty::{self as ty, TyCtxt};
17use rustc_session::lint;
18use rustc_session::parse::feature_err;
19use rustc_span::{Ident, Span, sym};
20use rustc_target::spec::SanitizerSet;
21
22use crate::errors;
23use crate::errors::NoMangleNameless;
24use crate::target_features::{
25 check_target_feature_trait_unsafe, check_tied_features, from_target_feature_attr,
26};
27
28fn try_fn_sig<'tcx>(
34 tcx: TyCtxt<'tcx>,
35 did: LocalDefId,
36 attr_span: Span,
37) -> Option<ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>>> {
38 use DefKind::*;
39
40 let def_kind = tcx.def_kind(did);
41 if let Fn | AssocFn | Variant | Ctor(..) = def_kind {
42 Some(tcx.fn_sig(did))
43 } else {
44 tcx.dcx().span_delayed_bug(attr_span, "this attribute can only be applied to functions");
45 None
46 }
47}
48
49fn parse_instruction_set_attr(tcx: TyCtxt<'_>, attr: &Attribute) -> Option<InstructionSetAttr> {
51 let list = attr.meta_item_list()?;
52
53 match &list[..] {
54 [MetaItemInner::MetaItem(set)] => {
55 let segments = set.path.segments.iter().map(|x| x.ident.name).collect::<Vec<_>>();
56 match segments.as_slice() {
57 [sym::arm, sym::a32 | sym::t32] if !tcx.sess.target.has_thumb_interworking => {
58 tcx.dcx().emit_err(errors::UnsupportedInstructionSet { span: attr.span() });
59 None
60 }
61 [sym::arm, sym::a32] => Some(InstructionSetAttr::ArmA32),
62 [sym::arm, sym::t32] => Some(InstructionSetAttr::ArmT32),
63 _ => {
64 tcx.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span() });
65 None
66 }
67 }
68 }
69 [] => {
70 tcx.dcx().emit_err(errors::BareInstructionSet { span: attr.span() });
71 None
72 }
73 _ => {
74 tcx.dcx().emit_err(errors::MultipleInstructionSet { span: attr.span() });
75 None
76 }
77 }
78}
79
80fn parse_no_sanitize_attr(tcx: TyCtxt<'_>, attr: &Attribute) -> Option<SanitizerSet> {
82 let list = attr.meta_item_list()?;
83 let mut sanitizer_set = SanitizerSet::empty();
84
85 for item in list.iter() {
86 match item.name() {
87 Some(sym::address) => {
88 sanitizer_set |= SanitizerSet::ADDRESS | SanitizerSet::KERNELADDRESS
89 }
90 Some(sym::cfi) => sanitizer_set |= SanitizerSet::CFI,
91 Some(sym::kcfi) => sanitizer_set |= SanitizerSet::KCFI,
92 Some(sym::memory) => sanitizer_set |= SanitizerSet::MEMORY,
93 Some(sym::memtag) => sanitizer_set |= SanitizerSet::MEMTAG,
94 Some(sym::shadow_call_stack) => sanitizer_set |= SanitizerSet::SHADOWCALLSTACK,
95 Some(sym::thread) => sanitizer_set |= SanitizerSet::THREAD,
96 Some(sym::hwaddress) => sanitizer_set |= SanitizerSet::HWADDRESS,
97 _ => {
98 tcx.dcx().emit_err(errors::InvalidNoSanitize { span: item.span() });
99 }
100 }
101 }
102
103 Some(sanitizer_set)
104}
105
106fn parse_patchable_function_entry(
108 tcx: TyCtxt<'_>,
109 attr: &Attribute,
110) -> Option<PatchableFunctionEntry> {
111 attr.meta_item_list().and_then(|l| {
112 let mut prefix = None;
113 let mut entry = None;
114 for item in l {
115 let Some(meta_item) = item.meta_item() else {
116 tcx.dcx().emit_err(errors::ExpectedNameValuePair { span: item.span() });
117 continue;
118 };
119
120 let Some(name_value_lit) = meta_item.name_value_literal() else {
121 tcx.dcx().emit_err(errors::ExpectedNameValuePair { span: item.span() });
122 continue;
123 };
124
125 let attrib_to_write = match meta_item.name() {
126 Some(sym::prefix_nops) => &mut prefix,
127 Some(sym::entry_nops) => &mut entry,
128 _ => {
129 tcx.dcx().emit_err(errors::UnexpectedParameterName {
130 span: item.span(),
131 prefix_nops: sym::prefix_nops,
132 entry_nops: sym::entry_nops,
133 });
134 continue;
135 }
136 };
137
138 let rustc_ast::LitKind::Int(val, _) = name_value_lit.kind else {
139 tcx.dcx().emit_err(errors::InvalidLiteralValue { span: name_value_lit.span });
140 continue;
141 };
142
143 let Ok(val) = val.get().try_into() else {
144 tcx.dcx().emit_err(errors::OutOfRangeInteger { span: name_value_lit.span });
145 continue;
146 };
147
148 *attrib_to_write = Some(val);
149 }
150
151 if let (None, None) = (prefix, entry) {
152 tcx.dcx().span_err(attr.span(), "must specify at least one parameter");
153 }
154
155 Some(PatchableFunctionEntry::from_prefix_and_entry(prefix.unwrap_or(0), entry.unwrap_or(0)))
156 })
157}
158
159#[derive(Default)]
162struct InterestingAttributeDiagnosticSpans {
163 link_ordinal: Option<Span>,
164 no_sanitize: Option<Span>,
165 inline: Option<Span>,
166 no_mangle: Option<Span>,
167}
168
169fn process_builtin_attrs(
172 tcx: TyCtxt<'_>,
173 did: LocalDefId,
174 attrs: &[Attribute],
175 codegen_fn_attrs: &mut CodegenFnAttrs,
176) -> InterestingAttributeDiagnosticSpans {
177 let mut interesting_spans = InterestingAttributeDiagnosticSpans::default();
178 let rust_target_features = tcx.rust_target_features(LOCAL_CRATE);
179
180 if cfg!(llvm_enzyme) {
184 let ad = autodiff_attrs(tcx, did.into());
185 codegen_fn_attrs.autodiff_item = ad;
186 }
187
188 for attr in attrs.iter() {
189 if let hir::Attribute::Parsed(p) = attr {
190 match p {
191 AttributeKind::Cold(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD,
192 AttributeKind::ExportName { name, .. } => {
193 codegen_fn_attrs.export_name = Some(*name)
194 }
195 AttributeKind::Inline(inline, span) => {
196 codegen_fn_attrs.inline = *inline;
197 interesting_spans.inline = Some(*span);
198 }
199 AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
200 AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
201 AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
202 AttributeKind::LinkOrdinal { ordinal, span } => {
203 codegen_fn_attrs.link_ordinal = Some(*ordinal);
204 interesting_spans.link_ordinal = Some(*span);
205 }
206 AttributeKind::LinkSection { name, .. } => {
207 codegen_fn_attrs.link_section = Some(*name)
208 }
209 AttributeKind::NoMangle(attr_span) => {
210 interesting_spans.no_mangle = Some(*attr_span);
211 if tcx.opt_item_name(did.to_def_id()).is_some() {
212 codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
213 } else {
214 tcx.dcx().emit_err(NoMangleNameless {
215 span: *attr_span,
216 definition: format!(
217 "{} {}",
218 tcx.def_descr_article(did.to_def_id()),
219 tcx.def_descr(did.to_def_id())
220 ),
221 });
222 }
223 }
224 AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,
225 AttributeKind::TargetFeature(features, attr_span) => {
226 let Some(sig) = tcx.hir_node_by_def_id(did).fn_sig() else {
227 tcx.dcx().span_delayed_bug(*attr_span, "target_feature applied to non-fn");
228 continue;
229 };
230 let safe_target_features =
231 matches!(sig.header.safety, hir::HeaderSafety::SafeTargetFeatures);
232 codegen_fn_attrs.safe_target_features = safe_target_features;
233 if safe_target_features {
234 if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
235 } else {
257 check_target_feature_trait_unsafe(tcx, did, *attr_span);
258 }
259 }
260 from_target_feature_attr(
261 tcx,
262 did,
263 features,
264 rust_target_features,
265 &mut codegen_fn_attrs.target_features,
266 );
267 }
268 AttributeKind::TrackCaller(attr_span) => {
269 let is_closure = tcx.is_closure_like(did.to_def_id());
270
271 if !is_closure
272 && let Some(fn_sig) = try_fn_sig(tcx, did, *attr_span)
273 && fn_sig.skip_binder().abi() != ExternAbi::Rust
274 {
275 tcx.dcx().emit_err(errors::RequiresRustAbi { span: *attr_span });
276 }
277 if is_closure
278 && !tcx.features().closure_track_caller()
279 && !attr_span.allows_unstable(sym::closure_track_caller)
280 {
281 feature_err(
282 &tcx.sess,
283 sym::closure_track_caller,
284 *attr_span,
285 "`#[track_caller]` on closures is currently unstable",
286 )
287 .emit();
288 }
289 codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER
290 }
291 AttributeKind::Used { used_by, .. } => match used_by {
292 UsedBy::Compiler => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_COMPILER,
293 UsedBy::Linker => codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED_LINKER,
294 },
295 AttributeKind::FfiConst(_) => {
296 codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST
297 }
298 AttributeKind::FfiPure(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_PURE,
299 AttributeKind::StdInternalSymbol(_) => {
300 codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
301 }
302 AttributeKind::Linkage(linkage, _) => {
303 let linkage = Some(*linkage);
304
305 if tcx.is_foreign_item(did) {
306 codegen_fn_attrs.import_linkage = linkage;
307
308 if tcx.is_mutable_static(did.into()) {
309 let mut diag = tcx.dcx().struct_span_err(
310 attr.span(),
311 "extern mutable statics are not allowed with `#[linkage]`",
312 );
313 diag.note(
314 "marking the extern static mutable would allow changing which \
315 symbol the static references rather than make the target of the \
316 symbol mutable",
317 );
318 diag.emit();
319 }
320 } else {
321 codegen_fn_attrs.linkage = linkage;
322 }
323 }
324 _ => {}
325 }
326 }
327
328 let Some(Ident { name, .. }) = attr.ident() else {
329 continue;
330 };
331
332 match name {
333 sym::rustc_allocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR,
334 sym::rustc_nounwind => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND,
335 sym::rustc_reallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::REALLOCATOR,
336 sym::rustc_deallocator => codegen_fn_attrs.flags |= CodegenFnAttrFlags::DEALLOCATOR,
337 sym::rustc_allocator_zeroed => {
338 codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
339 }
340 sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
341 sym::no_sanitize => {
342 interesting_spans.no_sanitize = Some(attr.span());
343 codegen_fn_attrs.no_sanitize |=
344 parse_no_sanitize_attr(tcx, attr).unwrap_or_default();
345 }
346 sym::instruction_set => {
347 codegen_fn_attrs.instruction_set = parse_instruction_set_attr(tcx, attr)
348 }
349 sym::patchable_function_entry => {
350 codegen_fn_attrs.patchable_function_entry =
351 parse_patchable_function_entry(tcx, attr);
352 }
353 _ => {}
354 }
355 }
356
357 interesting_spans
358}
359
360fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut CodegenFnAttrs) {
363 codegen_fn_attrs.alignment =
367 Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment);
368
369 codegen_fn_attrs.alignment = Ord::max(codegen_fn_attrs.alignment, tcx.inherited_align(did));
371
372 if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
376 codegen_fn_attrs.inline = InlineAttr::Never;
377 }
378
379 if tcx.is_closure_like(did.to_def_id()) && codegen_fn_attrs.inline != InlineAttr::Always {
393 let owner_id = tcx.parent(did.to_def_id());
394 if tcx.def_kind(owner_id).has_codegen_attrs() {
395 codegen_fn_attrs
396 .target_features
397 .extend(tcx.codegen_fn_attrs(owner_id).target_features.iter().copied());
398 }
399 }
400
401 let crate_attrs = tcx.hir_attrs(rustc_hir::CRATE_HIR_ID);
404 let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
405 if no_builtins {
406 codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS;
407 }
408
409 if tcx.should_inherit_track_caller(did) {
411 codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
412 }
413
414 if tcx.is_foreign_item(did) {
416 if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) {
418 } else if codegen_fn_attrs.link_name.is_some() {
422 } else {
424 codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
432 }
433 }
434}
435
436fn check_result(
437 tcx: TyCtxt<'_>,
438 did: LocalDefId,
439 interesting_spans: InterestingAttributeDiagnosticSpans,
440 codegen_fn_attrs: &CodegenFnAttrs,
441) {
442 if !codegen_fn_attrs.target_features.is_empty()
456 && matches!(codegen_fn_attrs.inline, InlineAttr::Always)
457 && let Some(span) = interesting_spans.inline
458 {
459 tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
460 }
461
462 if !codegen_fn_attrs.no_sanitize.is_empty()
464 && codegen_fn_attrs.inline.always()
465 && let (Some(no_sanitize_span), Some(inline_span)) =
466 (interesting_spans.no_sanitize, interesting_spans.inline)
467 {
468 let hir_id = tcx.local_def_id_to_hir_id(did);
469 tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, no_sanitize_span, |lint| {
470 lint.primary_message("`no_sanitize` will have no effect after inlining");
471 lint.span_note(inline_span, "inlining requested here");
472 })
473 }
474
475 if let Some(_) = codegen_fn_attrs.link_name
477 && let Some(_) = codegen_fn_attrs.link_ordinal
478 {
479 let msg = "cannot use `#[link_name]` with `#[link_ordinal]`";
480 if let Some(span) = interesting_spans.link_ordinal {
481 tcx.dcx().span_err(span, msg);
482 } else {
483 tcx.dcx().err(msg);
484 }
485 }
486
487 if let Some(features) = check_tied_features(
488 tcx.sess,
489 &codegen_fn_attrs
490 .target_features
491 .iter()
492 .map(|features| (features.name.as_str(), true))
493 .collect(),
494 ) {
495 let span =
496 find_attr!(tcx.get_all_attrs(did), AttributeKind::TargetFeature(_, span) => *span)
497 .unwrap_or_else(|| tcx.def_span(did));
498
499 tcx.dcx()
500 .create_err(errors::TargetFeatureDisableOrEnable {
501 features,
502 span: Some(span),
503 missing_features: Some(errors::MissingFeatures),
504 })
505 .emit();
506 }
507}
508
509fn handle_lang_items(
510 tcx: TyCtxt<'_>,
511 did: LocalDefId,
512 interesting_spans: &InterestingAttributeDiagnosticSpans,
513 attrs: &[Attribute],
514 codegen_fn_attrs: &mut CodegenFnAttrs,
515) {
516 let lang_item = lang_items::extract(attrs).and_then(|(name, _)| LangItem::from_name(name));
517
518 if let Some(lang_item) = lang_item {
524 if WEAK_LANG_ITEMS.contains(&lang_item) {
525 codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
526 }
527 if let Some(link_name) = lang_item.link_name() {
528 codegen_fn_attrs.export_name = Some(link_name);
529 codegen_fn_attrs.link_name = Some(link_name);
530 }
531 }
532
533 if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
535 && codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
536 {
537 let mut err = tcx
538 .dcx()
539 .struct_span_err(
540 interesting_spans.no_mangle.unwrap_or_default(),
541 "`#[no_mangle]` cannot be used on internal language items",
542 )
543 .with_note("Rustc requires this item to have a specific mangled name.")
544 .with_span_label(tcx.def_span(did), "should be the internal language item");
545 if let Some(lang_item) = lang_item
546 && let Some(link_name) = lang_item.link_name()
547 {
548 err = err
549 .with_note("If you are trying to prevent mangling to ease debugging, many")
550 .with_note(format!("debuggers support a command such as `rbreak {link_name}` to"))
551 .with_note(format!(
552 "match `.*{link_name}.*` instead of `break {link_name}` on a specific name"
553 ))
554 }
555 err.emit();
556 }
557}
558
559fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
568 if cfg!(debug_assertions) {
569 let def_kind = tcx.def_kind(did);
570 assert!(
571 def_kind.has_codegen_attrs(),
572 "unexpected `def_kind` in `codegen_fn_attrs`: {def_kind:?}",
573 );
574 }
575
576 let mut codegen_fn_attrs = CodegenFnAttrs::new();
577 let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(did));
578
579 let interesting_spans = process_builtin_attrs(tcx, did, attrs, &mut codegen_fn_attrs);
580 handle_lang_items(tcx, did, &interesting_spans, attrs, &mut codegen_fn_attrs);
581 apply_overrides(tcx, did, &mut codegen_fn_attrs);
582 check_result(tcx, did, interesting_spans, &codegen_fn_attrs);
583
584 codegen_fn_attrs
585}
586
587fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
589 let impl_item = tcx.opt_associated_item(def_id)?;
590 match impl_item.container {
591 ty::AssocItemContainer::Impl => impl_item.trait_item_def_id,
592 _ => None,
593 }
594}
595
596fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
599 let Some(trait_item) = opt_trait_item(tcx, def_id) else { return false };
600 tcx.codegen_fn_attrs(trait_item).flags.intersects(CodegenFnAttrFlags::TRACK_CALLER)
601}
602
603fn inherited_align<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<Align> {
606 tcx.codegen_fn_attrs(opt_trait_item(tcx, def_id)?).alignment
607}
608
609fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
616 let attrs = tcx.get_attrs(id, sym::rustc_autodiff);
617
618 let attrs = attrs.filter(|attr| attr.has_name(sym::rustc_autodiff)).collect::<Vec<_>>();
619
620 let attr = match &attrs[..] {
623 [] => return None,
624 [attr] => attr,
625 _ => {
626 span_bug!(attrs[1].span(), "cg_ssa: rustc_autodiff should only exist once per source");
627 }
628 };
629
630 let list = attr.meta_item_list().unwrap_or_default();
631
632 if list.is_empty() {
634 return Some(AutoDiffAttrs::source());
635 }
636
637 let [mode, width_meta, input_activities @ .., ret_activity] = &list[..] else {
638 span_bug!(attr.span(), "rustc_autodiff attribute must contain mode, width and activities");
639 };
640 let mode = if let MetaItemInner::MetaItem(MetaItem { path: p1, .. }) = mode {
641 p1.segments.first().unwrap().ident
642 } else {
643 span_bug!(attr.span(), "rustc_autodiff attribute must contain mode");
644 };
645
646 let mode = match mode.as_str() {
648 "Forward" => DiffMode::Forward,
649 "Reverse" => DiffMode::Reverse,
650 _ => {
651 span_bug!(mode.span, "rustc_autodiff attribute contains invalid mode");
652 }
653 };
654
655 let width: u32 = match width_meta {
656 MetaItemInner::MetaItem(MetaItem { path: p1, .. }) => {
657 let w = p1.segments.first().unwrap().ident;
658 match w.as_str().parse() {
659 Ok(val) => val,
660 Err(_) => {
661 span_bug!(w.span, "rustc_autodiff width should fit u32");
662 }
663 }
664 }
665 MetaItemInner::Lit(lit) => {
666 if let LitKind::Int(val, _) = lit.kind {
667 match val.get().try_into() {
668 Ok(val) => val,
669 Err(_) => {
670 span_bug!(lit.span, "rustc_autodiff width should fit u32");
671 }
672 }
673 } else {
674 span_bug!(lit.span, "rustc_autodiff width should be an integer");
675 }
676 }
677 };
678
679 let ret_symbol = if let MetaItemInner::MetaItem(MetaItem { path: p1, .. }) = ret_activity {
681 p1.segments.first().unwrap().ident
682 } else {
683 span_bug!(attr.span(), "rustc_autodiff attribute must contain the return activity");
684 };
685
686 let Ok(ret_activity) = DiffActivity::from_str(ret_symbol.as_str()) else {
688 span_bug!(ret_symbol.span, "invalid return activity");
689 };
690
691 let mut arg_activities: Vec<DiffActivity> = vec![];
693 for arg in input_activities {
694 let arg_symbol = if let MetaItemInner::MetaItem(MetaItem { path: p2, .. }) = arg {
695 match p2.segments.first() {
696 Some(x) => x.ident,
697 None => {
698 span_bug!(
699 arg.span(),
700 "rustc_autodiff attribute must contain the input activity"
701 );
702 }
703 }
704 } else {
705 span_bug!(arg.span(), "rustc_autodiff attribute must contain the input activity");
706 };
707
708 match DiffActivity::from_str(arg_symbol.as_str()) {
709 Ok(arg_activity) => arg_activities.push(arg_activity),
710 Err(_) => {
711 span_bug!(arg_symbol.span, "invalid input activity");
712 }
713 }
714 }
715
716 Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities })
717}
718
719pub(crate) fn provide(providers: &mut Providers) {
720 *providers =
721 Providers { codegen_fn_attrs, should_inherit_track_caller, inherited_align, ..*providers };
722}