Skip to content

Commit fbd9b77

Browse files
committed
Lowering draft
1 parent 3ce4d9c commit fbd9b77

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ mod llvm_enzyme {
344344
ident: first_ident(&meta_item_vec[0]),
345345
generics,
346346
contract: None,
347-
body: None,
347+
body: None, // This leads to an error when the ad function is inside a traits
348348
define_opaque: None,
349349
});
350350
let mut rustc_ad_attr =

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,21 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
198198
)
199199
}
200200
_ if tcx.has_attr(def_id, sym::rustc_autodiff) => {
201+
// NOTE(Sa4dUs): This is a hacky way to get the autodiff items
202+
// so we can focus on the lowering of the intrinsic call
203+
204+
// `diff_items` is empty even when autodiff is enabled, and if we're here,
205+
// it's because some function was marked as intrinsic and had the `rustc_autodiff` attr
206+
let diff_items = tcx.collect_and_partition_mono_items(()).autodiff_items;
207+
208+
// this shouldn't happen?
209+
if diff_items.is_empty() {
210+
bug!("no autodiff items found for {def_id:?}");
211+
}
212+
213+
// TODO(Sa4dUs): generate the enzyme call itself, based on the logic in `builder.rs`
214+
215+
// Just gen the fallback body for now
201216
return Err(ty::Instance::new_raw(def_id, instance.args));
202217
}
203218
sym::is_val_statically_known => {

0 commit comments

Comments
 (0)