@@ -1155,25 +1155,51 @@ fn codegen_enzyme_autodiff<'ll, 'tcx>(
1155
1155
// Get source, diff, and attrs
1156
1156
let ( source_id, source_args) = match fn_args. into_type_list ( tcx) [ 0 ] . kind ( ) {
1157
1157
ty:: FnDef ( def_id, source_params) => ( def_id, source_params) ,
1158
- _ => bug ! ( "invalid args" ) ,
1158
+ _ => bug ! ( "invalid autodiff intrinsic args" ) ,
1159
+ } ;
1160
+
1161
+ let fn_source = match Instance :: try_resolve ( tcx, bx. cx . typing_env ( ) , * source_id, source_args) {
1162
+ Ok ( Some ( instance) ) => instance,
1163
+ Ok ( None ) => bug ! (
1164
+ "could not resolve ({:?}, {:?}) to a specific autodiff instance" ,
1165
+ source_id,
1166
+ source_args
1167
+ ) ,
1168
+ Err ( _) => {
1169
+ // An error has already been emitted
1170
+ return ;
1171
+ }
1159
1172
} ;
1160
- let fn_source =
1161
- Instance :: try_resolve ( tcx, bx. cx . typing_env ( ) , * source_id, source_args) . unwrap ( ) . unwrap ( ) ;
1173
+
1162
1174
let source_symbol = symbol_name_for_instance_in_crate ( tcx, fn_source. clone ( ) , LOCAL_CRATE ) ;
1163
- let fn_to_diff: Option < & ' ll llvm:: Value > = bx. cx . get_function ( & source_symbol) ;
1164
- let Some ( fn_to_diff) = fn_to_diff else { bug ! ( "could not find source function" ) } ;
1175
+ let Some ( fn_to_diff) = bx. cx . get_function ( & source_symbol) else {
1176
+ bug ! ( "could not find source function" )
1177
+ } ;
1165
1178
1166
1179
let ( diff_id, diff_args) = match fn_args. into_type_list ( tcx) [ 1 ] . kind ( ) {
1167
1180
ty:: FnDef ( def_id, diff_args) => ( def_id, diff_args) ,
1168
1181
_ => bug ! ( "invalid args" ) ,
1169
1182
} ;
1170
- let fn_diff =
1171
- Instance :: try_resolve ( tcx, bx. cx . typing_env ( ) , * diff_id, diff_args) . unwrap ( ) . unwrap ( ) ;
1172
- let val_arr: Vec < & ' ll Value > = get_args_from_tuple ( bx, args[ 2 ] , fn_diff) ;
1183
+
1184
+ let fn_diff = match Instance :: try_resolve ( tcx, bx. cx . typing_env ( ) , * diff_id, diff_args) {
1185
+ Ok ( Some ( instance) ) => instance,
1186
+ Ok ( None ) => bug ! (
1187
+ "could not resolve ({:?}, {:?}) to a specific autodiff instance" ,
1188
+ diff_id,
1189
+ diff_args
1190
+ ) ,
1191
+ Err ( _) => {
1192
+ // An error has already been emitted
1193
+ return ;
1194
+ }
1195
+ } ;
1196
+
1197
+ let val_arr = get_args_from_tuple ( bx, args[ 2 ] , fn_diff) ;
1173
1198
let diff_symbol = symbol_name_for_instance_in_crate ( tcx, fn_diff. clone ( ) , LOCAL_CRATE ) ;
1174
1199
1175
- let diff_attrs = autodiff_attrs ( tcx, fn_diff. def_id ( ) ) ;
1176
- let Some ( mut diff_attrs) = diff_attrs else { bug ! ( "could not find autodiff attrs" ) } ;
1200
+ let Some ( mut diff_attrs) = autodiff_attrs ( tcx, fn_diff. def_id ( ) ) else {
1201
+ bug ! ( "could not find autodiff attrs" )
1202
+ } ;
1177
1203
1178
1204
adjust_activity_to_abi (
1179
1205
tcx,
0 commit comments