Skip to content

Commit 0dfdb6c

Browse files
committed
rlib handling
1 parent 66bc5a4 commit 0dfdb6c

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_middle::mir::BinOp;
1515
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
1616
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
1717
use rustc_middle::{bug, span_bug};
18+
use rustc_session::config::CrateType;
1819
use rustc_span::{Span, Symbol, sym};
1920
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
2021
use rustc_target::callconv::PassMode;
@@ -1136,8 +1137,17 @@ fn codegen_autodiff<'ll, 'tcx>(
11361137
if !tcx.sess.opts.unstable_opts.autodiff.contains(&rustc_session::config::AutoDiff::Enable) {
11371138
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutEnable);
11381139
}
1139-
if tcx.sess.lto() != rustc_session::config::Lto::Fat {
1140-
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1140+
1141+
let ct = tcx.crate_types();
1142+
let lto = tcx.sess.lto();
1143+
if ct.len() == 1 && ct.contains(&CrateType::Executable) {
1144+
if lto != rustc_session::config::Lto::Fat {
1145+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1146+
}
1147+
} else {
1148+
if lto != rustc_session::config::Lto::Fat && !tcx.sess.opts.cg.linker_plugin_lto.enabled() {
1149+
let _ = tcx.dcx().emit_almost_fatal(AutoDiffWithoutLto);
1150+
}
11411151
}
11421152

11431153
let fn_args = instance.args;

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
3434
return true;
3535
}
3636

37+
// FIXME(autodiff): replace this as per discussion in https://github.com/rust-lang/rust/pull/149033#discussion_r2535465880
38+
if tcx.has_attr(def_id, sym::autodiff_forward)
39+
|| tcx.has_attr(def_id, sym::autodiff_reverse)
40+
|| tcx.has_attr(def_id, sym::rustc_autodiff)
41+
{
42+
return true;
43+
}
44+
3745
if tcx.has_attr(def_id, sym::rustc_intrinsic) {
3846
// Intrinsic fallback bodies are always cross-crate inlineable.
3947
// To ensure that the MIR inliner doesn't cluelessly try to inline fallback

compiler/rustc_monomorphize/src/collector/autodiff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::collector::{MonoItems, create_fn_mono_item};
77
// mono so this does not interfere in `autodiff` intrinsics
88
// codegen process. If they are unused, LLVM will remove them when
99
// compiling with O3.
10+
// FIXME(autodiff): Remove this whole file, as per discussion in
11+
// https://github.com/rust-lang/rust/pull/149033#discussion_r2535465880
1012
pub(crate) fn collect_autodiff_fn<'tcx>(
1113
tcx: TyCtxt<'tcx>,
1214
instance: ty::Instance<'tcx>,

0 commit comments

Comments
 (0)