Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Now correctly catching not-fat-lto errors #144

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
codegen_llvm_prepare_autodiff = failed to prepare AutoDiff: src: {$src}, target: {$target}, {$error}
codegen_llvm_prepare_autodiff_with_llvm_err = failed to prepare AutoDiff: {$llvm_err}, src: {$src}, target: {$target}, {$error}

codegen_llvm_autodiff_without_lto = using the autodiff feature requires using fat-lto

codegen_llvm_sanitizer_memtag_requires_mte =
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_llvm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
#[note]
pub(crate) struct DynamicLinkingWithLTO;

#[derive(Diagnostic)]
#[diag(codegen_llvm_autodiff_without_lto)]
#[note]
pub(crate) struct AutoDiffWithoutLTO;

pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);

impl<G: EmissionGuarantee> IntoDiagnostic<'_, G> for ParseTargetMachineConfig<'_> {
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ extern crate rustc_macros;
#[macro_use]
extern crate tracing;

use rustc_session::config::Lto;
use back::owned_target_machine::OwnedTargetMachine;
use back::write::{create_informational_target_machine, create_target_machine};

use errors::ParseTargetMachineConfig;
use errors::{ParseTargetMachineConfig, AutoDiffWithoutLTO};

#[allow(unused_imports)]
use llvm::TypeTree;
Expand Down Expand Up @@ -268,6 +269,10 @@ impl WriteBackendMethods for LlvmCodegenBackend {
typetrees: FxHashMap<String, Self::TypeTree>,
config: &ModuleConfig,
) -> Result<(), FatalError> {
if cgcx.lto != Lto::Fat {
let dcx = cgcx.create_dcx();
return Err(dcx.emit_almost_fatal(AutoDiffWithoutLTO{}));
}
unsafe { back::write::differentiate(module, cgcx, diff_fncs, typetrees, config) }
}

Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,5 @@ codegen_ssa_use_cargo_directive = use the `cargo:rustc-link-lib` directive to sp
codegen_ssa_version_script_write_failure = failed to write version script: {$error}

codegen_ssa_visual_studio_not_installed = you may need to install Visual Studio build tools with the "C++ build tools" workload

codegen_ssa_autodiff_without_lto = using the autodiff feature requires using fat-lto
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
LtoModuleCodegen::Fat { ref module, .. } => {
B::autodiff(cgcx, &module, diff_fncs, typetrees, config)?;
}
_ => panic!("autodiff called with non-fat LTO module"),
_ => panic!("Unreachable? Autodiff called with non-fat LTO module"),
}

Ok(self)
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use rustc_span::symbol::sym;
use rustc_span::{BytePos, FileName, InnerSpan, Pos, Span};
use rustc_target::spec::{MergeFunctions, SanitizerSet};

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

if !needs_fat_lto.is_empty() {
assert!(needs_thin_lto.is_empty());
Expand All @@ -397,7 +394,10 @@ fn generate_lto_work<B: ExtraBackendMethods>(
// We are adding a single work item, so the cost doesn't matter.
vec![(WorkItem::LTO(module), 0)]
} else {
assert!(autodiff.is_empty());
if !autodiff.is_empty() {
let dcx = cgcx.create_dcx();
dcx.emit_fatal(AutodiffWithoutLto{});
}
assert!(needs_fat_lto.is_empty());
let (lto_modules, copy_jobs) = B::run_thin_lto(cgcx, needs_thin_lto, import_only_modules)
.unwrap_or_else(|e| e.raise());
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub struct CguNotRecorded<'a> {
pub cgu_name: &'a str,
}

#[derive(Diagnostic)]
#[diag(codegen_ssa_autodiff_without_lto)]
pub struct AutodiffWithoutLto;

#[derive(Diagnostic)]
#[diag(codegen_ssa_unknown_reuse_kind)]
pub struct UnknownReuseKind {
Expand Down
Loading