Skip to content

Commit e2f70f6

Browse files
committed
provide an error if an autodiff user does not set in their Cargo.toml
1 parent 4da69df commit e2f70f6

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
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: 5 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};
2929
use crate::type_::Type;
3030
use crate::type_of::LayoutLlvmExt;
@@ -1147,6 +1147,10 @@ fn codegen_autodiff<'ll, 'tcx>(
11471147
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
11481148
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
11491149
}
1150+
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
1151+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1152+
}
1153+
11501154

11511155
let fn_args = instance.args;
11521156
let callee_ty = instance.ty(tcx, bx.typing_env());

compiler/rustc_session/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ session_expr_parentheses_needed = parentheses are required to parse this as an e
2424
2525
session_failed_to_create_profiler = failed to create profiler: {$err}
2626
27+
session_feature_autodiff_without_lto =
28+
set `lto="fat"` in your Cargo.toml for debug and release mode
29+
2730
session_feature_diagnostic_for_issue =
2831
see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
2932

compiler/rustc_session/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ use rustc_target::spec::{SplitDebuginfo, StackProtector, TargetTuple};
1414
use crate::config::CrateType;
1515
use crate::parse::ParseSess;
1616

17+
#[derive(Diagnostic)]
18+
#[diag(session_feature_autodiff_without_lto)]
19+
pub struct AutodiffWithoutLto;
20+
1721
#[derive(Diagnostic)]
1822
pub(crate) enum AppleDeploymentTarget {
1923
#[diag(session_apple_deployment_target_invalid)]

compiler/rustc_session/src/session.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -600,13 +600,6 @@ impl Session {
600600

601601
/// Calculates the flavor of LTO to use for this compilation.
602602
pub fn lto(&self) -> config::Lto {
603-
// Autodiff currently requires fat-lto to have access to the llvm-ir of all (indirectly) used functions and types.
604-
// fat-lto is the easiest solution to this requirement, but quite expensive.
605-
// FIXME(autodiff): Make autodiff also work with embed-bc instead of fat-lto.
606-
if self.opts.autodiff_enabled() {
607-
return config::Lto::Fat;
608-
}
609-
610603
// If our target has codegen requirements ignore the command line
611604
if self.target.requires_lto {
612605
return config::Lto::Fat;

0 commit comments

Comments
 (0)