Skip to content

Commit 7b1d030

Browse files
committed
mono-time abi_check: unify error paths for call and definition sites
also move the existing tests to a more sensible location
1 parent aaa8614 commit 7b1d030

13 files changed

+74
-86
lines changed

compiler/rustc_monomorphize/messages.ftl

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
monomorphize_abi_error_disabled_vector_type_call =
2-
this function call uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled in the caller
3-
.label = function called here
4-
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
5-
monomorphize_abi_error_disabled_vector_type_def =
6-
this function definition uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled
7-
.label = function defined here
1+
monomorphize_abi_error_disabled_vector_type =
2+
this function {$is_call ->
3+
[true] call
4+
*[false] definition
5+
} uses SIMD vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call ->
6+
[true] {" "}in the caller
7+
*[false] {""}
8+
}
9+
.label = function {$is_call ->
10+
[true] called
11+
*[false] defined
12+
} here
813
.help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`)
914
10-
monomorphize_abi_error_unsupported_vector_type_call =
11-
this function call uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
12-
.label = function called here
13-
monomorphize_abi_error_unsupported_vector_type_def =
14-
this function definition uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
15-
.label = function defined here
15+
monomorphize_abi_error_unsupported_vector_type =
16+
this function {$is_call ->
17+
[true] call
18+
*[false] definition
19+
} uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI
20+
.label = function {$is_call ->
21+
[true] called
22+
*[false] defined
23+
} here
1624
1725
monomorphize_couldnt_dump_mono_stats =
1826
unexpected error occurred while dumping monomorphization stats: {$error}

compiler/rustc_monomorphize/src/errors.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -70,37 +70,23 @@ pub(crate) struct UnknownCguCollectionMode<'a> {
7070
}
7171

7272
#[derive(LintDiagnostic)]
73-
#[diag(monomorphize_abi_error_disabled_vector_type_def)]
73+
#[diag(monomorphize_abi_error_disabled_vector_type)]
7474
#[help]
75-
pub(crate) struct AbiErrorDisabledVectorTypeDef<'a> {
75+
pub(crate) struct AbiErrorDisabledVectorType<'a> {
7676
#[label]
7777
pub span: Span,
7878
pub required_feature: &'a str,
7979
pub ty: Ty<'a>,
80+
/// Whether this is a problem at a call site or at a declaration.
81+
pub is_call: bool,
8082
}
8183

8284
#[derive(LintDiagnostic)]
83-
#[diag(monomorphize_abi_error_disabled_vector_type_call)]
84-
#[help]
85-
pub(crate) struct AbiErrorDisabledVectorTypeCall<'a> {
86-
#[label]
87-
pub span: Span,
88-
pub required_feature: &'a str,
89-
pub ty: Ty<'a>,
90-
}
91-
92-
#[derive(LintDiagnostic)]
93-
#[diag(monomorphize_abi_error_unsupported_vector_type_def)]
94-
pub(crate) struct AbiErrorUnsupportedVectorTypeDef<'a> {
95-
#[label]
96-
pub span: Span,
97-
pub ty: Ty<'a>,
98-
}
99-
100-
#[derive(LintDiagnostic)]
101-
#[diag(monomorphize_abi_error_unsupported_vector_type_call)]
102-
pub(crate) struct AbiErrorUnsupportedVectorTypeCall<'a> {
85+
#[diag(monomorphize_abi_error_unsupported_vector_type)]
86+
pub(crate) struct AbiErrorUnsupportedVectorType<'a> {
10387
#[label]
10488
pub span: Span,
10589
pub ty: Ty<'a>,
90+
/// Whether this is a problem at a call site or at a declaration.
91+
pub is_call: bool,
10692
}

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

+44-50
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ use rustc_middle::ty::inherent::*;
77
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
88
use rustc_session::lint::builtin::ABI_UNSUPPORTED_VECTOR_TYPES;
99
use rustc_span::def_id::DefId;
10-
use rustc_span::{DUMMY_SP, Span, Symbol};
11-
use rustc_target::callconv::{FnAbi, PassMode};
10+
use rustc_span::{DUMMY_SP, Span, Symbol, sym};
11+
use rustc_target::callconv::{Conv, FnAbi, PassMode};
1212

13-
use crate::errors::{
14-
AbiErrorDisabledVectorTypeCall, AbiErrorDisabledVectorTypeDef,
15-
AbiErrorUnsupportedVectorTypeCall, AbiErrorUnsupportedVectorTypeDef,
16-
};
13+
use crate::errors;
1714

1815
fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
1916
match mode {
@@ -28,32 +25,56 @@ fn uses_vector_registers(mode: &PassMode, repr: &BackendRepr) -> bool {
2825

2926
/// Checks whether a certain function ABI is compatible with the target features currently enabled
3027
/// for a certain function.
31-
/// If not, `emit_err` is called, with `Some(feature)` if a certain feature should be enabled and
32-
/// with `None` if no feature is known that would make the ABI compatible.
28+
/// `is_call` indicates whether this is a call-site check or a definition-site check;
29+
/// this is only relevant for the wording in the emitted error.
3330
fn do_check_abi<'tcx>(
3431
tcx: TyCtxt<'tcx>,
3532
abi: &FnAbi<'tcx, Ty<'tcx>>,
3633
target_feature_def: DefId,
37-
mut emit_err: impl FnMut(Ty<'tcx>, Option<&'static str>),
34+
is_call: bool,
35+
span: impl Fn() -> Span,
3836
) {
3937
let feature_def = tcx.sess.target.features_for_correct_vector_abi();
4038
let codegen_attrs = tcx.codegen_fn_attrs(target_feature_def);
39+
let have_feature = |feat: Symbol| {
40+
tcx.sess.unstable_target_features.contains(&feat)
41+
|| codegen_attrs.target_features.iter().any(|x| x.name == feat)
42+
};
4143
for arg_abi in abi.args.iter().chain(std::iter::once(&abi.ret)) {
4244
let size = arg_abi.layout.size;
4345
if uses_vector_registers(&arg_abi.mode, &arg_abi.layout.backend_repr) {
4446
// Find the first feature that provides at least this vector size.
4547
let feature = match feature_def.iter().find(|(bits, _)| size.bits() <= *bits) {
4648
Some((_, feature)) => feature,
4749
None => {
48-
emit_err(arg_abi.layout.ty, None);
50+
let span = span();
51+
tcx.emit_node_span_lint(
52+
ABI_UNSUPPORTED_VECTOR_TYPES,
53+
CRATE_HIR_ID,
54+
span,
55+
errors::AbiErrorUnsupportedVectorType {
56+
span,
57+
ty: arg_abi.layout.ty,
58+
is_call,
59+
},
60+
);
4961
continue;
5062
}
5163
};
52-
let feature_sym = Symbol::intern(feature);
53-
if !tcx.sess.unstable_target_features.contains(&feature_sym)
54-
&& !codegen_attrs.target_features.iter().any(|x| x.name == feature_sym)
55-
{
56-
emit_err(arg_abi.layout.ty, Some(&feature));
64+
if !have_feature(Symbol::intern(feature)) {
65+
// Emit error.
66+
let span = span();
67+
tcx.emit_node_span_lint(
68+
ABI_UNSUPPORTED_VECTOR_TYPES,
69+
CRATE_HIR_ID,
70+
span,
71+
errors::AbiErrorDisabledVectorType {
72+
span,
73+
required_feature: feature,
74+
ty: arg_abi.layout.ty,
75+
is_call,
76+
},
77+
);
5778
}
5879
}
5980
}
@@ -69,24 +90,13 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
6990
// function.
7091
return;
7192
};
72-
do_check_abi(tcx, abi, instance.def_id(), |ty, required_feature| {
73-
let span = tcx.def_span(instance.def_id());
74-
if let Some(required_feature) = required_feature {
75-
tcx.emit_node_span_lint(
76-
ABI_UNSUPPORTED_VECTOR_TYPES,
77-
CRATE_HIR_ID,
78-
span,
79-
AbiErrorDisabledVectorTypeDef { span, required_feature, ty },
80-
);
81-
} else {
82-
tcx.emit_node_span_lint(
83-
ABI_UNSUPPORTED_VECTOR_TYPES,
84-
CRATE_HIR_ID,
85-
span,
86-
AbiErrorUnsupportedVectorTypeDef { span, ty },
87-
);
88-
}
89-
})
93+
do_check_abi(
94+
tcx,
95+
abi,
96+
instance.def_id(),
97+
/*is_call*/ false,
98+
|| tcx.def_span(instance.def_id()),
99+
)
90100
}
91101

92102
/// Checks that a call expression does not try to pass a vector-passed argument which requires a
@@ -123,23 +133,7 @@ fn check_call_site_abi<'tcx>(
123133
// ABI failed to compute; this will not get through codegen.
124134
return;
125135
};
126-
do_check_abi(tcx, callee_abi, caller.def_id(), |ty, required_feature| {
127-
if let Some(required_feature) = required_feature {
128-
tcx.emit_node_span_lint(
129-
ABI_UNSUPPORTED_VECTOR_TYPES,
130-
CRATE_HIR_ID,
131-
span,
132-
AbiErrorDisabledVectorTypeCall { span, required_feature, ty },
133-
);
134-
} else {
135-
tcx.emit_node_span_lint(
136-
ABI_UNSUPPORTED_VECTOR_TYPES,
137-
CRATE_HIR_ID,
138-
span,
139-
AbiErrorUnsupportedVectorTypeCall { span, ty },
140-
);
141-
}
142-
});
136+
do_check_abi(tcx, callee_abi, caller.def_id(), /*is_call*/ true, || span);
143137
}
144138

145139
fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &mir::Body<'tcx>) {
File renamed without changes.
File renamed without changes.

tests/ui/sse-abi-checks.rs renamed to tests/ui/abi/sse-abi-checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//@ build-pass
66
//@ ignore-pass (test emits codegen-time warnings)
77
//@ needs-llvm-components: x86
8-
#![feature(no_core, lang_items, repr_simd)]
8+
#![feature(no_core, repr_simd)]
99
#![no_core]
1010
#![allow(improper_ctypes_definitions)]
1111

File renamed without changes.

0 commit comments

Comments
 (0)