Skip to content

Commit 63f4b36

Browse files
committed
provide an error if an autodiff user does not set in their Cargo.toml
1 parent 11339a0 commit 63f4b36

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
codegen_llvm_autodiff_without_enable = using the autodiff feature requires -Z autodiff=Enable
2+
codegen_llvm_autodiff_without_lto = using the autodiff feature requires setting `lto="fat"` in your Cargo.toml
23
34
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
45

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
3232
}
3333
}
3434

35+
#[derive(Diagnostic)]
36+
#[diag(codegen_llvm_autodiff_without_lto)]
37+
pub(crate) struct AutoDiffWithoutLto;
38+
3539
#[derive(Diagnostic)]
3640
#[diag(codegen_llvm_autodiff_without_enable)]
3741
pub(crate) struct AutoDiffWithoutEnable;

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::abi::FnAbiLlvmExt;
2424
use crate::builder::Builder;
2525
use crate::builder::autodiff::{adjust_activity_to_abi, generate_enzyme_call};
2626
use crate::context::CodegenCx;
27-
use crate::errors::AutoDiffWithoutEnable;
27+
use crate::errors::{AutoDiffWithoutEnable, AutoDiffWithoutLto};
2828
use crate::llvm::{self, Metadata, Type, Value};
2929
use crate::type_of::LayoutLlvmExt;
3030
use crate::va_arg::emit_va_arg;
@@ -1145,6 +1145,9 @@ fn codegen_autodiff<'ll, 'tcx>(
11451145
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
11461146
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
11471147
}
1148+
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
1149+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1150+
}
11481151

11491152
let fn_args = instance.args;
11501153
let callee_ty = instance.ty(tcx, bx.typing_env());

compiler/rustc_session/src/session.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,6 @@ impl Session {
594594

595595
/// Calculates the flavor of LTO to use for this compilation.
596596
pub fn lto(&self) -> config::Lto {
597-
// Autodiff currently requires fat-lto to have access to the llvm-ir of all (indirectly) used functions and types.
598-
// fat-lto is the easiest solution to this requirement, but quite expensive.
599-
// FIXME(autodiff): Make autodiff also work with embed-bc instead of fat-lto.
600-
// Don't apply fat-lto to proc-macro crates as they cannot use fat-lto without -Zdylib-lto
601-
if self.opts.autodiff_enabled() && !self.opts.crate_types.contains(&CrateType::ProcMacro) {
602-
return config::Lto::Fat;
603-
}
604-
605597
// If our target has codegen requirements ignore the command line
606598
if self.target.requires_lto {
607599
return config::Lto::Fat;

0 commit comments

Comments
 (0)