Skip to content

Commit d1030fa

Browse files
committed
UPDATE - migrate fn simd_simple_float_intrinsic error messages
1 parent e26366a commit d1030fa

File tree

7 files changed

+55
-28
lines changed

7 files changed

+55
-28
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,7 @@ dependencies = [
36363636
"rustc_span",
36373637
"rustc_symbol_mangling",
36383638
"rustc_target",
3639+
"rustc_type_ir",
36393640
"serde_json",
36403641
"smallvec",
36413642
"snap",
@@ -3770,6 +3771,7 @@ dependencies = [
37703771
"rustc_serialize",
37713772
"rustc_span",
37723773
"rustc_target",
3774+
"rustc_type_ir",
37733775
"serde",
37743776
"serde_json",
37753777
"termcolor",

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,42 +1165,24 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11651165
span: Span,
11661166
args: &[OperandRef<'tcx, &'ll Value>],
11671167
) -> Result<&'ll Value, ()> {
1168-
#[allow(unused_macro_rules)]
1169-
macro_rules! emit_error {
1170-
($msg: tt) => {
1171-
emit_error!($msg, )
1172-
};
1173-
($msg: tt, $($fmt: tt)*) => {
1174-
span_invalid_monomorphization_error(
1175-
bx.sess(), span,
1176-
&format!(concat!("invalid monomorphization of `{}` intrinsic: ", $msg),
1177-
name, $($fmt)*));
1178-
}
1179-
}
1180-
macro_rules! return_error {
1181-
($($fmt: tt)*) => {
1182-
{
1183-
emit_error!($($fmt)*);
1184-
return Err(());
1185-
}
1186-
}
1187-
}
1188-
11891168
let (elem_ty_str, elem_ty) = if let ty::Float(f) = in_elem.kind() {
11901169
let elem_ty = bx.cx.type_float_from_ty(*f);
11911170
match f.bit_width() {
11921171
32 => ("f32", elem_ty),
11931172
64 => ("f64", elem_ty),
11941173
_ => {
1195-
return_error!(
1196-
"unsupported element type `{}` of floating-point vector `{}`",
1197-
f.name_str(),
1198-
in_ty
1199-
);
1174+
bx.sess().emit_err(InvalidMonomorphization::FloatingPointVector {
1175+
span,
1176+
name,
1177+
f_ty: *f,
1178+
in_ty,
1179+
});
1180+
return Err(());
12001181
}
12011182
}
12021183
} else {
1203-
return_error!("`{}` is not a floating-point type", in_ty);
1184+
bx.sess().emit_err(InvalidMonomorphization::FloatingPointType { span, name, in_ty });
1185+
return Err(());
12041186
};
12051187

12061188
let vec_ty = bx.type_vector(elem_ty, in_len);
@@ -1222,7 +1204,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
12221204
sym::simd_fsqrt => ("sqrt", bx.type_func(&[vec_ty], vec_ty)),
12231205
sym::simd_round => ("round", bx.type_func(&[vec_ty], vec_ty)),
12241206
sym::simd_trunc => ("trunc", bx.type_func(&[vec_ty], vec_ty)),
1225-
_ => return_error!("unrecognized intrinsic `{}`", name),
1207+
_ => {
1208+
bx.sess().emit_err(InvalidMonomorphization::UnrecognizedIntrinsic { span, name });
1209+
return Err(());
1210+
}
12261211
};
12271212
let llvm_name = &format!("llvm.{0}.v{1}{2}", intr_name, in_len, elem_ty_str);
12281213
let f = bx.declare_cfn(llvm_name, llvm::UnnamedAddr::No, fn_ty);

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ rustc_arena = { path = "../rustc_arena" }
2727
rustc_ast = { path = "../rustc_ast" }
2828
rustc_span = { path = "../rustc_span" }
2929
rustc_middle = { path = "../rustc_middle" }
30+
rustc_type_ir = { path = "../rustc_type_ir" }
3031
rustc_attr = { path = "../rustc_attr" }
3132
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
3233
rustc_data_structures = { path = "../rustc_data_structures" }

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 25 additions & 0 deletions
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};
@@ -631,4 +632,28 @@ pub enum InvalidMonomorphization<'tcx> {
631632
span: Span,
632633
ty: Ty<'tcx>,
633634
},
635+
636+
#[diag(codegen_ssa_invalid_monomorphization_floating_point_vector, code = "E0511")]
637+
FloatingPointVector {
638+
#[primary_span]
639+
span: Span,
640+
name: Symbol,
641+
f_ty: FloatTy,
642+
in_ty: Ty<'tcx>,
643+
},
644+
645+
#[diag(codegen_ssa_invalid_monomorphization_floating_point_type, code = "E0511")]
646+
FloatingPointType {
647+
#[primary_span]
648+
span: Span,
649+
name: Symbol,
650+
in_ty: Ty<'tcx>,
651+
},
652+
653+
#[diag(codegen_ssa_invalid_monomorphization_unrecognized_intrinsic, code = "E0511")]
654+
UnrecognizedIntrinsic {
655+
#[primary_span]
656+
span: Span,
657+
name: Symbol,
658+
},
634659
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,9 @@ codegen_ssa_invalid_monomorphization_basic_integer_type = invalid monomorphizati
219219
codegen_ssa_invalid_monomorphization_basic_float_type = invalid monomorphization of `{$name}` intrinsic: expected basic float type, found `{$ty}`
220220
221221
codegen_ssa_invalid_monomorphization_float_to_int_unchecked = invalid monomorphization of `float_to_int_unchecked` intrinsic: expected basic float type, found `{$ty}`
222+
223+
codegen_ssa_invalid_monomorphization_floating_point_vector = invalid monomorphization of `{$name}` intrinsic: unsupported element type `{$f_ty}` of floating-point vector `{$in_ty}`
224+
225+
codegen_ssa_invalid_monomorphization_floating_point_type = invalid monomorphization of `{$name}` intrinsic: `{$in_ty}` is not a floating-point type
226+
227+
codegen_ssa_invalid_monomorphization_unrecognized_intrinsic = invalid monomorphization of `{$name}` intrinsic: unrecognized intrinsic `{$name}`

compiler/rustc_errors/Cargo.toml

Lines changed: 1 addition & 0 deletions
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
termcolor = "1.0"
2223
annotate-snippets = "0.9"

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 7 additions & 0 deletions
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::num::ParseIntError;
@@ -170,6 +171,12 @@ impl IntoDiagnosticArg for ast::token::TokenKind {
170171
}
171172
}
172173

174+
impl IntoDiagnosticArg for type_ir::FloatTy {
175+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
176+
DiagnosticArgValue::Str(Cow::Borrowed(self.name_str()))
177+
}
178+
}
179+
173180
impl IntoDiagnosticArg for Level {
174181
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
175182
DiagnosticArgValue::Str(Cow::Borrowed(match self {

0 commit comments

Comments
 (0)