Skip to content

Commit 18a6d12

Browse files
committed
fix compiler
1 parent ee3b63c commit 18a6d12

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -607,23 +607,30 @@ mod llvm_enzyme {
607607
exprs = ecx.expr_call(new_decl_span, bb_call_expr, thin_vec![default_call_expr]);
608608
}
609609
} else if x.mode.is_rev() {
610-
//if x.width == 1 {
611-
// if primal_ret {
612-
// // We have extra handling above for the primal ret
613-
// d_ret_ty = d_ret_ty[1..].to_vec().into();
614-
// }
615-
616-
// for arg in d_ret_ty.iter() {
617-
// let arg = arg.kind.is_simple_path().unwrap();
618-
// let sl: Vec<Symbol> = vec![arg, kw::Default];
619-
// let tmp = ecx.def_site_path(&sl);
620-
// let default_call_expr = ecx.expr_path(ecx.path(span, tmp));
621-
// let default_call_expr =
622-
// ecx.expr_call(new_decl_span, default_call_expr, thin_vec![]);
623-
// exprs = default_call_expr;
624-
// //exprs.push(default_call_expr);
625-
// }
626-
//}
610+
if x.width == 1 {
611+
// We either have `-> ArbitraryType` or `-> (ArbitraryType, repeated_float_scalars)`.
612+
match d_ret_ty.kind {
613+
TyKind::Tup(ref args) => {
614+
// We have a tuple return type. We need to create a tuple of the same size
615+
// and fill it with default values.
616+
let mut exprs2 = thin_vec![exprs];
617+
for arg in args.iter().skip(1) {
618+
let arg = arg.kind.is_simple_path().unwrap();
619+
let sl: Vec<Symbol> = vec![arg, kw::Default];
620+
let tmp = ecx.def_site_path(&sl);
621+
let default_call_expr = ecx.expr_path(ecx.path(span, tmp));
622+
let default_call_expr =
623+
ecx.expr_call(new_decl_span, default_call_expr, thin_vec![]);
624+
exprs2.push(default_call_expr);
625+
}
626+
exprs = ecx.expr_tuple(new_decl_span, exprs2);
627+
}
628+
_ => {
629+
panic!("Unsupported return type: {:?}", d_ret_ty);
630+
}
631+
}
632+
}
633+
exprs = ecx.expr_call(new_decl_span, bb_call_expr, thin_vec![exprs]);
627634
} else {
628635
// The return type of our dummy function is the same as the return type of our primal.
629636
// In that case, we can just use the primal call as last instruction.

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::ptr;
33
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, AutoDiffItem, DiffActivity, DiffMode};
44
use rustc_codegen_ssa::ModuleCodegen;
55
use rustc_codegen_ssa::back::write::ModuleConfig;
6-
use rustc_errors::{DiagCtxt, FatalError};
6+
use rustc_errors::FatalError;
77
use rustc_middle::bug;
88
use tracing::{debug, trace};
99

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::str::FromStr;
22

33
use rustc_abi::ExternAbi;
4-
use rustc_ast::expand::autodiff_attrs::{
5-
AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity,
6-
};
4+
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
75
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
86
use rustc_attr_parsing::ReprAttr::ReprAlign;
97
use rustc_attr_parsing::{AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr};
@@ -887,15 +885,6 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
887885
}
888886
}
889887

890-
for &input in &arg_activities {
891-
if !valid_input_activity(mode, input) {
892-
span_bug!(attr.span(), "Invalid input activity {} for {} mode", input, mode);
893-
}
894-
}
895-
if !valid_ret_activity(mode, ret_activity) {
896-
span_bug!(attr.span(), "Invalid return activity {} for {} mode", ret_activity, mode);
897-
}
898-
899888
Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities })
900889
}
901890

0 commit comments

Comments
 (0)