Skip to content

Commit e3875bc

Browse files
authored
Now correctly catching not-fat-lto errors (#144)
1 parent f5ce829 commit e3875bc

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed

compiler/rustc_codegen_llvm/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
6363
codegen_llvm_prepare_autodiff = failed to prepare AutoDiff: src: {$src}, target: {$target}, {$error}
6464
codegen_llvm_prepare_autodiff_with_llvm_err = failed to prepare AutoDiff: {$llvm_err}, src: {$src}, target: {$target}, {$error}
6565
66+
codegen_llvm_autodiff_without_lto = using the autodiff feature requires using fat-lto
67+
6668
codegen_llvm_sanitizer_memtag_requires_mte =
6769
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`
6870

compiler/rustc_codegen_llvm/src/errors.rs

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
9797
#[note]
9898
pub(crate) struct DynamicLinkingWithLTO;
9999

100+
#[derive(Diagnostic)]
101+
#[diag(codegen_llvm_autodiff_without_lto)]
102+
#[note]
103+
pub(crate) struct AutoDiffWithoutLTO;
104+
100105
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
101106

102107
impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {

compiler/rustc_codegen_llvm/src/lib.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ extern crate rustc_macros;
2525
#[macro_use]
2626
extern crate tracing;
2727

28+
use rustc_session::config::Lto;
2829
use back::owned_target_machine::OwnedTargetMachine;
2930
use back::write::{create_informational_target_machine, create_target_machine};
3031

31-
use errors::ParseTargetMachineConfig;
32+
use errors::{ParseTargetMachineConfig, AutoDiffWithoutLTO};
3233

3334
#[allow(unused_imports)]
3435
use llvm::TypeTree;
@@ -268,6 +269,10 @@ impl WriteBackendMethods for LlvmCodegenBackend {
268269
typetrees: FxHashMap<String, Self::TypeTree>,
269270
config: &ModuleConfig,
270271
) -> Result<(), FatalError> {
272+
if cgcx.lto != Lto::Fat {
273+
let dcx = cgcx.create_dcx();
274+
return Err(dcx.emit_almost_fatal(AutoDiffWithoutLTO{}));
275+
}
271276
unsafe { back::write::differentiate(module, cgcx, diff_fncs, typetrees, config) }
272277
}
273278

compiler/rustc_codegen_ssa/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,5 @@ codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to sp
330330
codegen_ssa_version_script_write_failure = failed to write version script: {$error}
331331
332332
codegen_ssa_visual_studio_not_installed = you may need to install Visual Studio build tools with the "C++ build tools" workload
333+
334+
codegen_ssa_autodiff_without_lto = using the autodiff feature requires using fat-lto

compiler/rustc_codegen_ssa/src/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
9090
LtoModuleCodegen::Fat { ref module, .. } => {
9191
B::autodiff(cgcx, &module, diff_fncs, typetrees, config)?;
9292
}
93-
_ => panic!("autodiff called with non-fat LTO module"),
93+
_ => panic!("Unreachable? Autodiff called with non-fat LTO module"),
9494
}
9595

9696
Ok(self)

compiler/rustc_codegen_ssa/src/back/write.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_span::symbol::sym;
3535
use rustc_span::{BytePos, FileName, InnerSpan, Pos, Span};
3636
use rustc_target::spec::{MergeFunctions, SanitizerSet};
3737

38-
use crate::errors::ErrorCreatingRemarkDir;
38+
use crate::errors::{ErrorCreatingRemarkDir, AutodiffWithoutLto};
3939
use std::any::Any;
4040
use std::borrow::Cow;
4141
use std::fs;
@@ -382,9 +382,6 @@ fn generate_lto_work<B: ExtraBackendMethods>(
382382
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>,
383383
) -> Vec<(WorkItem<B>, u64)> {
384384
let _prof_timer = cgcx.prof.generic_activity("codegen_generate_lto_work");
385-
//let error_msg = format!("Found {} Functions, but {} TypeTrees", autodiff.len(), typetrees.len());
386-
// Don't assert yet, bc. apparently we add them later.
387-
//assert!(autodiff.len() == typetrees.len(), "{}", error_msg);
388385

389386
if !needs_fat_lto.is_empty() {
390387
assert!(needs_thin_lto.is_empty());
@@ -397,7 +394,10 @@ fn generate_lto_work<B: ExtraBackendMethods>(
397394
// We are adding a single work item, so the cost doesn't matter.
398395
vec![(WorkItem::LTO(module), 0)]
399396
} else {
400-
assert!(autodiff.is_empty());
397+
if !autodiff.is_empty() {
398+
let dcx = cgcx.create_dcx();
399+
dcx.emit_fatal(AutodiffWithoutLto{});
400+
}
401401
assert!(needs_fat_lto.is_empty());
402402
let (lto_modules, copy_jobs) = B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules)
403403
.unwrap_or_else(|e| e.raise());

compiler/rustc_codegen_ssa/src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub struct CguNotRecorded<'a> {
3535
pub cgu_name: &'a str,
3636
}
3737

38+
#[derive(Diagnostic)]
39+
#[diag(codegen_ssa_autodiff_without_lto)]
40+
pub struct AutodiffWithoutLto;
41+
3842
#[derive(Diagnostic)]
3943
#[diag(codegen_ssa_unknown_reuse_kind)]
4044
pub struct UnknownReuseKind {

0 commit comments

Comments
 (0)