Skip to content

Commit d2406fc

Browse files
committed
add span information to autodiff compile time errors
1 parent 3610d7c commit d2406fc

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

compiler/rustc_ast/src/expand/autodiff_attrs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use std::fmt::{self, Display, Formatter};
77
use std::str::FromStr;
88

9+
use rustc_span::Span;
10+
911
use crate::expand::{Decodable, Encodable, HashStable_Generic};
1012
use crate::ptr::P;
1113
use crate::{Ty, TyKind};
@@ -85,6 +87,7 @@ pub struct AutoDiffItem {
8587
/// The name of the function being generated
8688
pub target: String,
8789
pub attrs: AutoDiffAttrs,
90+
pub span: Span,
8891
}
8992

9093
#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
@@ -276,8 +279,8 @@ impl AutoDiffAttrs {
276279
!matches!(self.mode, DiffMode::Error | DiffMode::Source)
277280
}
278281

279-
pub fn into_item(self, source: String, target: String) -> AutoDiffItem {
280-
AutoDiffItem { source, target, attrs: self }
282+
pub fn into_item(self, source: String, target: String, span: Span) -> AutoDiffItem {
283+
AutoDiffItem { source, target, attrs: self, span }
281284
}
282285
}
283286

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,11 +419,12 @@ fn generate_lto_work<B: ExtraBackendMethods>(
419419
} else {
420420
if !autodiff.is_empty() {
421421
let dcx = cgcx.create_dcx();
422+
let span = autodiff[0].span;
422423
if cgcx.crate_types.contains(&CrateType::Rlib) {
423-
dcx.handle().emit_fatal(AutodiffLibraryBuild {});
424+
dcx.handle().span_fatal(AutodiffLibraryBuild { span });
424425
}
425426
if cgcx.lto != Lto::Fat {
426-
dcx.handle().emit_fatal(AutodiffWithoutLto {});
427+
dcx.handle().emit_fatal(AutodiffWithoutLto { span });
427428
}
428429
}
429430
assert!(needs_fat_lto.is_empty());

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ pub(crate) struct CguNotRecorded<'a> {
3939

4040
#[derive(Diagnostic)]
4141
#[diag(codegen_ssa_autodiff_without_lto)]
42-
pub struct AutodiffWithoutLto;
42+
pub struct AutodiffWithoutLto {
43+
#[primary_span]
44+
pub span: Span,
45+
}
4346

4447
#[derive(Diagnostic)]
4548
#[diag(codegen_ssa_autodiff_lib_unsupported)]
46-
pub struct AutodiffLibraryBuild;
49+
pub struct AutodiffLibraryBuild {
50+
#[primary_span]
51+
pub span: Span,
52+
}
4753

4854
#[derive(Diagnostic)]
4955
#[diag(codegen_ssa_unknown_reuse_kind)]

compiler/rustc_monomorphize/src/partitioning/autodiff.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,16 @@ pub(crate) fn find_autodiff_source_functions<'tcx>(
120120
None => continue,
121121
};
122122

123-
debug!("source_id: {:?}", inst.def_id());
123+
let source_def_id = inst.def_id();
124+
debug!("source_id: {:?}", source_def_id);
124125
let fn_ty = inst.ty(tcx, ty::TypingEnv::fully_monomorphized());
125126
assert!(fn_ty.is_fn());
126127
adjust_activity_to_abi(tcx, fn_ty, &mut input_activities);
127128
let symb = symbol_name_for_instance_in_crate(tcx, inst.clone(), LOCAL_CRATE);
128129

129130
let mut new_target_attrs = target_attrs.clone();
130131
new_target_attrs.input_activity = input_activities;
131-
let itm = new_target_attrs.into_item(symb, target_symbol);
132+
let itm = new_target_attrs.into_item(symb, target_symbol, tcx.def_span(source_def_id));
132133
autodiff_items.push(itm);
133134
}
134135

0 commit comments

Comments
 (0)