Skip to content

Commit 9a31b3c

Browse files
committed
UPDATE - migrate fn simd_simple_float_intrinsic error messages
1 parent fdce670 commit 9a31b3c

File tree

7 files changed

+55
-28
lines changed

7 files changed

+55
-28
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,7 @@ dependencies = [
33183318
"rustc_span",
33193319
"rustc_symbol_mangling",
33203320
"rustc_target",
3321+
"rustc_type_ir",
33213322
"serde_json",
33223323
"smallvec",
33233324
"snap",
@@ -3447,6 +3448,7 @@ dependencies = [
34473448
"rustc_serialize",
34483449
"rustc_span",
34493450
"rustc_target",
3451+
"rustc_type_ir",
34503452
"serde",
34513453
"serde_json",
34523454
"termcolor",

compiler/rustc_codegen_llvm/src/intrinsic.rs

+13-28
Original file line numberDiff line numberDiff line change
@@ -1163,42 +1163,24 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11631163
span: Span,
11641164
args: &[OperandRef<'tcx, &'ll Value>],
11651165
) -> Result<&'ll Value, ()> {
1166-
#[allow(unused_macro_rules)]
1167-
macro_rules! emit_error {
1168-
($msg: tt) => {
1169-
emit_error!($msg, )
1170-
};
1171-
($msg: tt, $($fmt: tt)*) => {
1172-
span_invalid_monomorphization_error(
1173-
bx.sess(), span,
1174-
&format!(concat!("invalid monomorphization of `{}` intrinsic: ", $msg),
1175-
name, $($fmt)*));
1176-
}
1177-
}
1178-
macro_rules! return_error {
1179-
($($fmt: tt)*) => {
1180-
{
1181-
emit_error!($($fmt)*);
1182-
return Err(());
1183-
}
1184-
}
1185-
}
1186-
11871166
let (elem_ty_str, elem_ty) = if let ty::Float(f) = in_elem.kind() {
11881167
let elem_ty = bx.cx.type_float_from_ty(*f);
11891168
match f.bit_width() {
11901169
32 => ("f32", elem_ty),
11911170
64 => ("f64", elem_ty),
11921171
_ => {
1193-
return_error!(
1194-
"unsupported element type `{}` of floating-point vector `{}`",
1195-
f.name_str(),
1196-
in_ty
1197-
);
1172+
bx.sess().emit_err(InvalidMonomorphization::FloatingPointVector {
1173+
span,
1174+
name,
1175+
f_ty: *f,
1176+
in_ty,
1177+
});
1178+
return Err(());
11981179
}
11991180
}
12001181
} else {
1201-
return_error!("`{}` is not a floating-point type", in_ty);
1182+
bx.sess().emit_err(InvalidMonomorphization::FloatingPointType { span, name, in_ty });
1183+
return Err(());
12021184
};
12031185

12041186
let vec_ty = bx.type_vector(elem_ty, in_len);
@@ -1220,7 +1202,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
12201202
sym::simd_fsqrt => ("sqrt", bx.type_func(&[vec_ty], vec_ty)),
12211203
sym::simd_round => ("round", bx.type_func(&[vec_ty], vec_ty)),
12221204
sym::simd_trunc => ("trunc", bx.type_func(&[vec_ty], vec_ty)),
1223-
_ => return_error!("unrecognized intrinsic `{}`", name),
1205+
_ => {
1206+
bx.sess().emit_err(InvalidMonomorphization::UnrecognizedIntrinsic { span, name });
1207+
return Err(());
1208+
}
12241209
};
12251210
let llvm_name = &format!("llvm.{0}.v{1}{2}", intr_name, in_len, elem_ty_str);
12261211
let f = bx.declare_cfn(llvm_name, llvm::UnnamedAddr::No, fn_ty);

compiler/rustc_codegen_ssa/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ rustc_arena = { path = "../rustc_arena" }
2626
rustc_ast = { path = "../rustc_ast" }
2727
rustc_span = { path = "../rustc_span" }
2828
rustc_middle = { path = "../rustc_middle" }
29+
rustc_type_ir = { path = "../rustc_type_ir" }
2930
rustc_attr = { path = "../rustc_attr" }
3031
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
3132
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_codegen_ssa/src/errors.rs

+25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_errors::{
88
use rustc_macros::Diagnostic;
99
use rustc_middle::ty::Ty;
1010
use rustc_span::{Span, Symbol};
11+
use rustc_type_ir::FloatTy;
1112
use std::borrow::Cow;
1213
use std::io::Error;
1314
use std::path::{Path, PathBuf};
@@ -610,4 +611,28 @@ pub enum InvalidMonomorphization<'tcx> {
610611
span: Span,
611612
ty: Ty<'tcx>,
612613
},
614+
615+
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = "E0511")]
616+
FloatingPointVector {
617+
#[primary_span]
618+
span: Span,
619+
name: Symbol,
620+
f_ty: FloatTy,
621+
in_ty: Ty<'tcx>,
622+
},
623+
624+
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = "E0511")]
625+
FloatingPointType {
626+
#[primary_span]
627+
span: Span,
628+
name: Symbol,
629+
in_ty: Ty<'tcx>,
630+
},
631+
632+
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = "E0511")]
633+
UnrecognizedIntrinsic {
634+
#[primary_span]
635+
span: Span,
636+
name: Symbol,
637+
},
613638
}

compiler/rustc_error_messages/locales/en-US/codegen_ssa.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,9 @@ codegen_ssa_invalid_monomorphization_basic_integer_type = invalid monomorphizati
211211
codegen_ssa_invalid_monomorphization_basic_float_type = invalid monomorphization of `{$name}` intrinsic: expected basic float type, found `{$ty}`
212212
213213
codegen_ssa_invalid_monomorphization_float_to_int_unchecked = invalid monomorphization of `float_to_int_unchecked` intrinsic: expected basic float type, found `{$ty}`
214+
215+
codegen_ssa_invalid_monomorphization_floating_point_vector = invalid monomorphization of `{$name}` intrinsic: unsupported element type `{$f_ty}` of floating-point vector `{$in_ty}`
216+
217+
codegen_ssa_invalid_monomorphization_floating_point_type = invalid monomorphization of `{$name}` intrinsic: `{$in_ty}` is not a floating-point type
218+
219+
codegen_ssa_invalid_monomorphization_unrecognized_intrinsic = invalid monomorphization of `{$name}` intrinsic: unrecognized intrinsic `{$name}`

compiler/rustc_errors/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
1717
rustc_target = { path = "../rustc_target" }
1818
rustc_hir = { path = "../rustc_hir" }
1919
rustc_lint_defs = { path = "../rustc_lint_defs" }
20+
rustc_type_ir = { path = "../rustc_type_ir" }
2021
unicode-width = "0.1.4"
2122
atty = "0.2"
2223
termcolor = "1.0"

compiler/rustc_errors/src/diagnostic_impls.rs

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_span::edition::Edition;
99
use rustc_span::symbol::{Ident, MacroRulesNormalizedIdent, Symbol};
1010
use rustc_target::abi::TargetDataLayoutErrors;
1111
use rustc_target::spec::{PanicStrategy, SplitDebuginfo, StackProtector, TargetTriple};
12+
use rustc_type_ir as type_ir;
1213
use std::borrow::Cow;
1314
use std::fmt;
1415
use std::fmt::Write;
@@ -165,6 +166,12 @@ impl IntoDiagnosticArg for ast::token::TokenKind {
165166
}
166167
}
167168

169+
impl IntoDiagnosticArg for type_ir::FloatTy {
170+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
171+
DiagnosticArgValue::Str(Cow::Borrowed(self.name_str()))
172+
}
173+
}
174+
168175
impl IntoDiagnosticArg for Level {
169176
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
170177
DiagnosticArgValue::Str(Cow::Borrowed(match self {

0 commit comments

Comments
 (0)