@@ -2,7 +2,7 @@ use std::str::FromStr;
2
2
3
3
use rustc_abi:: ExternAbi ;
4
4
use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , DiffActivity , DiffMode } ;
5
- use rustc_ast:: { MetaItem , MetaItemInner , attr} ;
5
+ use rustc_ast:: { LitKind , MetaItem , MetaItemInner , attr} ;
6
6
use rustc_attr_parsing:: ReprAttr :: ReprAlign ;
7
7
use rustc_attr_parsing:: { AttributeKind , InlineAttr , InstructionSetAttr , OptimizeAttr } ;
8
8
use rustc_data_structures:: fx:: FxHashMap ;
@@ -805,8 +805,8 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
805
805
return Some ( AutoDiffAttrs :: source ( ) ) ;
806
806
}
807
807
808
- let [ mode, input_activities @ .., ret_activity] = & list[ ..] else {
809
- span_bug ! ( attr. span( ) , "rustc_autodiff attribute must contain mode and activities" ) ;
808
+ let [ mode, width_meta , input_activities @ .., ret_activity] = & list[ ..] else {
809
+ span_bug ! ( attr. span( ) , "rustc_autodiff attribute must contain mode, width and activities" ) ;
810
810
} ;
811
811
let mode = if let MetaItemInner :: MetaItem ( MetaItem { path : p1, .. } ) = mode {
812
812
p1. segments . first ( ) . unwrap ( ) . ident
@@ -823,6 +823,31 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
823
823
}
824
824
} ;
825
825
826
+ let width: u32 ;
827
+ match width_meta {
828
+ MetaItemInner :: MetaItem ( MetaItem { path : p1, .. } ) => {
829
+ let w = p1. segments . first ( ) . unwrap ( ) . ident ;
830
+ width = match w. as_str ( ) . parse ( ) {
831
+ Ok ( val) => val,
832
+ Err ( _) => {
833
+ span_bug ! ( w. span, "rustc_autodiff width should fit u32" ) ;
834
+ }
835
+ } ;
836
+ }
837
+ MetaItemInner :: Lit ( lit) => {
838
+ if let LitKind :: Int ( val, _) = lit. kind {
839
+ width = match val. get ( ) . try_into ( ) {
840
+ Ok ( val) => val,
841
+ Err ( _) => {
842
+ span_bug ! ( lit. span, "rustc_autodiff width should fit u32" ) ;
843
+ }
844
+ } ;
845
+ } else {
846
+ span_bug ! ( lit. span, "rustc_autodiff width should be an integer" ) ;
847
+ }
848
+ }
849
+ }
850
+
826
851
// First read the ret symbol from the attribute
827
852
let ret_symbol = if let MetaItemInner :: MetaItem ( MetaItem { path : p1, .. } ) = ret_activity {
828
853
p1. segments . first ( ) . unwrap ( ) . ident
@@ -860,7 +885,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
860
885
}
861
886
}
862
887
863
- Some ( AutoDiffAttrs { mode, width : 1 , ret_activity, input_activity : arg_activities } )
888
+ Some ( AutoDiffAttrs { mode, width, ret_activity, input_activity : arg_activities } )
864
889
}
865
890
866
891
pub ( crate ) fn provide ( providers : & mut Providers ) {
0 commit comments