Skip to content

Commit 5967598

Browse files
committed
make autodiff checks more helpful
1 parent ea34650 commit 5967598

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ codegen_ssa_aix_strip_not_used = using host's `strip` binary to cross-compile to
88
99
codegen_ssa_archive_build_failure = failed to build archive at `{$path}`: {$error}
1010
11-
codegen_ssa_autodiff_without_lto = using the autodiff feature requires using fat-lto
11+
codegen_ssa_autodiff_lib_unsupported = using the autodiff feature with library builds is not yet supported
12+
13+
codegen_ssa_autodiff_without_lto = using the autodiff feature requires using fat-lto.
1214
1315
codegen_ssa_bare_instruction_set = `#[instruction_set]` requires an argument
1416

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use tracing::debug;
4141
use super::link::{self, ensure_removed};
4242
use super::lto::{self, SerializedModule};
4343
use super::symbol_export::symbol_name_for_instance_in_crate;
44-
use crate::errors::{AutodiffWithoutLto, ErrorCreatingRemarkDir};
44+
use crate::errors::{AutodiffLibraryBuild, AutodiffWithoutLto, ErrorCreatingRemarkDir};
4545
use crate::traits::*;
4646
use crate::{
4747
CachedModuleCodegen, CodegenResults, CompiledModule, CrateInfo, ModuleCodegen, ModuleKind,
@@ -419,7 +419,12 @@ fn generate_lto_work<B: ExtraBackendMethods>(
419419
} else {
420420
if !autodiff.is_empty() {
421421
let dcx = cgcx.create_dcx();
422-
dcx.handle().emit_fatal(AutodiffWithoutLto {});
422+
if cgcx.crate_types.contains(&CrateType::Rlib) {
423+
dcx.handle().emit_fatal(AutodiffLibraryBuild {});
424+
}
425+
if cgcx.lto != Lto::Fat {
426+
dcx.handle().emit_fatal(AutodiffWithoutLto {});
427+
}
423428
}
424429
assert!(needs_fat_lto.is_empty());
425430
let (lto_modules, copy_jobs) = B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules)
@@ -1456,6 +1461,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
14561461
if needs_fat_lto.is_empty()
14571462
&& needs_thin_lto.is_empty()
14581463
&& lto_import_only_modules.is_empty()
1464+
&& autodiff_items.is_empty()
14591465
{
14601466
// Nothing more to do!
14611467
break;
@@ -1469,13 +1475,14 @@ fn start_executing_work<B: ExtraBackendMethods>(
14691475
assert!(!started_lto);
14701476
started_lto = true;
14711477

1478+
let autodiff_items = mem::take(&mut autodiff_items);
14721479
let needs_fat_lto = mem::take(&mut needs_fat_lto);
14731480
let needs_thin_lto = mem::take(&mut needs_thin_lto);
14741481
let import_only_modules = mem::take(&mut lto_import_only_modules);
14751482

14761483
for (work, cost) in generate_lto_work(
14771484
&cgcx,
1478-
autodiff_items.clone(),
1485+
autodiff_items,
14791486
needs_fat_lto,
14801487
needs_thin_lto,
14811488
import_only_modules,

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub(crate) struct CguNotRecorded<'a> {
4141
#[diag(codegen_ssa_autodiff_without_lto)]
4242
pub struct AutodiffWithoutLto;
4343

44+
#[derive(Diagnostic)]
45+
#[diag(codegen_ssa_autodiff_lib_unsupported)]
46+
pub struct AutodiffLibraryBuild;
47+
4448
#[derive(Diagnostic)]
4549
#[diag(codegen_ssa_unknown_reuse_kind)]
4650
pub(crate) struct UnknownReuseKind {

0 commit comments

Comments
 (0)