@@ -192,7 +192,6 @@ mod llvm_enzyme {
192192 /// which becomes expanded to:
193193 /// ```
194194 /// #[rustc_autodiff]
195- /// #[inline(never)]
196195 /// fn sin(x: &Box<f32>) -> f32 {
197196 /// f32::sin(**x)
198197 /// }
@@ -368,7 +367,7 @@ mod llvm_enzyme {
368367 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
369368 let inline_never = outer_normal_attr ( & inline_never_attr, new_id, span) ;
370369
371- // We're avoid duplicating the attributes `#[rustc_autodiff]` and `#[inline(never) ]`.
370+ // We're avoid duplicating the attribute `#[rustc_autodiff]`.
372371 fn same_attribute ( attr : & ast:: AttrKind , item : & ast:: AttrKind ) -> bool {
373372 match ( attr, item) {
374373 ( ast:: AttrKind :: Normal ( a) , ast:: AttrKind :: Normal ( b) ) => {
@@ -381,23 +380,25 @@ mod llvm_enzyme {
381380 }
382381 }
383382
383+ let mut has_inline_never = false ;
384+
384385 // Don't add it multiple times:
385386 let orig_annotatable: Annotatable = match item {
386387 Annotatable :: Item ( ref mut iitem) => {
387388 if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & attr. kind ) ) {
388389 iitem. attrs . push ( attr) ;
389390 }
390- if ! iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
391- iitem . attrs . push ( inline_never . clone ( ) ) ;
391+ if iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
392+ has_inline_never = true ;
392393 }
393394 Annotatable :: Item ( iitem. clone ( ) )
394395 }
395396 Annotatable :: AssocItem ( ref mut assoc_item, i @ Impl { .. } ) => {
396397 if !assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & attr. kind ) ) {
397398 assoc_item. attrs . push ( attr) ;
398399 }
399- if ! assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
400- assoc_item . attrs . push ( inline_never . clone ( ) ) ;
400+ if assoc_item. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
401+ has_inline_never = true ;
401402 }
402403 Annotatable :: AssocItem ( assoc_item. clone ( ) , i)
403404 }
@@ -407,9 +408,8 @@ mod llvm_enzyme {
407408 if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & attr. kind ) ) {
408409 iitem. attrs . push ( attr) ;
409410 }
410- if !iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) )
411- {
412- iitem. attrs . push ( inline_never. clone ( ) ) ;
411+ if iitem. attrs . iter ( ) . any ( |a| same_attribute ( & a. kind , & inline_never. kind ) ) {
412+ has_inline_never = true ;
413413 }
414414 }
415415 _ => unreachable ! ( "stmt kind checked previously" ) ,
@@ -430,11 +430,19 @@ mod llvm_enzyme {
430430
431431 let new_id = ecx. sess . psess . attr_id_generator . mk_attr_id ( ) ;
432432 let d_attr = outer_normal_attr ( & rustc_ad_attr, new_id, span) ;
433+
434+ // If the source function has the `#[inline(never)]` attribute, we'll also add it to the diff function
435+ let mut d_attrs = thin_vec ! [ d_attr] ;
436+
437+ if has_inline_never {
438+ d_attrs. push ( inline_never) ;
439+ }
440+
433441 let d_annotatable = match & item {
434442 Annotatable :: AssocItem ( _, _) => {
435- let assoc_item: AssocItemKind = ast:: AssocItemKind :: Fn ( asdf ) ;
443+ let assoc_item: AssocItemKind = ast:: AssocItemKind :: Fn ( d_fn ) ;
436444 let d_fn = Box :: new ( ast:: AssocItem {
437- attrs : thin_vec ! [ d_attr ] ,
445+ attrs : d_attrs ,
438446 id : ast:: DUMMY_NODE_ID ,
439447 span,
440448 vis,
@@ -444,13 +452,13 @@ mod llvm_enzyme {
444452 Annotatable :: AssocItem ( d_fn, Impl { of_trait : false } )
445453 }
446454 Annotatable :: Item ( _) => {
447- let mut d_fn = ecx. item ( span, thin_vec ! [ d_attr ] , ItemKind :: Fn ( d_fn) ) ;
455+ let mut d_fn = ecx. item ( span, d_attrs , ItemKind :: Fn ( d_fn) ) ;
448456 d_fn. vis = vis;
449457
450458 Annotatable :: Item ( d_fn)
451459 }
452460 Annotatable :: Stmt ( _) => {
453- let mut d_fn = ecx. item ( span, thin_vec ! [ d_attr ] , ItemKind :: Fn ( d_fn) ) ;
461+ let mut d_fn = ecx. item ( span, d_attrs , ItemKind :: Fn ( d_fn) ) ;
454462 d_fn. vis = vis;
455463
456464 Annotatable :: Stmt ( Box :: new ( ast:: Stmt {
0 commit comments