Skip to content

Commit e26366a

Browse files
committed
[WIP] UPDATE - migrate intrinsic.rs to new diagnostic infrastructure
WIP - replacing span_invalid_monomorphization_error function. Still in progress due to its use in codegen_llvm inside macros
1 parent d41112a commit e26366a

File tree

4 files changed

+74
-60
lines changed

4 files changed

+74
-60
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::value::Value;
1010
use rustc_codegen_ssa::base::{compare_simd_types, wants_msvc_seh};
1111
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
1212
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
13+
use rustc_codegen_ssa::errors::InvalidMonomorphization;
1314
use rustc_codegen_ssa::mir::operand::OperandRef;
1415
use rustc_codegen_ssa::mir::place::PlaceRef;
1516
use rustc_codegen_ssa::traits::*;
@@ -284,15 +285,11 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
284285
_ => bug!(),
285286
},
286287
None => {
287-
span_invalid_monomorphization_error(
288-
tcx.sess,
288+
tcx.sess.emit_err(InvalidMonomorphization::BasicIntegerType {
289289
span,
290-
&format!(
291-
"invalid monomorphization of `{}` intrinsic: \
292-
expected basic integer type, found `{}`",
293-
name, ty
294-
),
295-
);
290+
name,
291+
ty,
292+
});
296293
return;
297294
}
298295
}

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_errors::{
66
IntoDiagnosticArg,
77
};
88
use rustc_macros::Diagnostic;
9+
use rustc_middle::ty::Ty;
910
use rustc_span::{Span, Symbol};
1011
use std::borrow::Cow;
1112
use std::io::Error;
@@ -589,3 +590,45 @@ pub struct ShuffleIndicesEvaluation {
589590
#[primary_span]
590591
pub span: Span,
591592
}
593+
594+
#[derive(Diagnostic)]
595+
#[diag(codegen_ssa_missing_memory_ordering)]
596+
pub struct MissingMemoryOrdering;
597+
598+
#[derive(Diagnostic)]
599+
#[diag(codegen_ssa_unknown_atomic_ordering)]
600+
pub struct UnknownAtomicOrdering;
601+
602+
#[derive(Diagnostic)]
603+
#[diag(codegen_ssa_atomic_compare_exchange)]
604+
pub struct AtomicCompareExchange;
605+
606+
#[derive(Diagnostic)]
607+
#[diag(codegen_ssa_unknown_atomic_operation)]
608+
pub struct UnknownAtomicOperation;
609+
610+
#[derive(Diagnostic)]
611+
pub enum InvalidMonomorphization<'tcx> {
612+
#[diag(codegen_ssa_invalid_monomorphization_basic_integer_type, code = "E0511")]
613+
BasicIntegerType {
614+
#[primary_span]
615+
span: Span,
616+
name: Symbol,
617+
ty: Ty<'tcx>,
618+
},
619+
620+
#[diag(codegen_ssa_invalid_monomorphization_basic_float_type, code = "E0511")]
621+
BasicFloatType {
622+
#[primary_span]
623+
span: Span,
624+
name: Symbol,
625+
ty: Ty<'tcx>,
626+
},
627+
628+
#[diag(codegen_ssa_invalid_monomorphization_float_to_int_unchecked, code = "E0511")]
629+
FloatToIntUnchecked {
630+
#[primary_span]
631+
span: Span,
632+
ty: Ty<'tcx>,
633+
},
634+
}

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use super::operand::{OperandRef, OperandValue};
22
use super::place::PlaceRef;
33
use super::FunctionCx;
4-
use crate::common::{span_invalid_monomorphization_error, IntPredicate};
4+
use crate::common::IntPredicate;
5+
use crate::errors;
6+
use crate::errors::InvalidMonomorphization;
57
use crate::glue;
68
use crate::meth;
79
use crate::traits::*;
@@ -305,15 +307,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
305307
_ => bug!(),
306308
},
307309
None => {
308-
span_invalid_monomorphization_error(
309-
bx.tcx().sess,
310-
span,
311-
&format!(
312-
"invalid monomorphization of `{}` intrinsic: \
313-
expected basic integer type, found `{}`",
314-
name, ty
315-
),
316-
);
310+
bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty });
317311
return;
318312
}
319313
}
@@ -329,45 +323,19 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
329323
_ => bug!(),
330324
},
331325
None => {
332-
span_invalid_monomorphization_error(
333-
bx.tcx().sess,
334-
span,
335-
&format!(
336-
"invalid monomorphization of `{}` intrinsic: \
337-
expected basic float type, found `{}`",
338-
name, arg_tys[0]
339-
),
340-
);
326+
bx.tcx().sess.emit_err(InvalidMonomorphization::BasicFloatType { span, name, ty: arg_tys[0] });
341327
return;
342328
}
343329
}
344330
}
345331

346332
sym::float_to_int_unchecked => {
347333
if float_type_width(arg_tys[0]).is_none() {
348-
span_invalid_monomorphization_error(
349-
bx.tcx().sess,
350-
span,
351-
&format!(
352-
"invalid monomorphization of `float_to_int_unchecked` \
353-
intrinsic: expected basic float type, \
354-
found `{}`",
355-
arg_tys[0]
356-
),
357-
);
334+
bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: arg_tys[0] });
358335
return;
359336
}
360337
let Some((_width, signed)) = int_type_width_signed(ret_ty, bx.tcx()) else {
361-
span_invalid_monomorphization_error(
362-
bx.tcx().sess,
363-
span,
364-
&format!(
365-
"invalid monomorphization of `float_to_int_unchecked` \
366-
intrinsic: expected basic integer type, \
367-
found `{}`",
368-
ret_ty
369-
),
370-
);
338+
bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: ret_ty });
371339
return;
372340
};
373341
if signed {
@@ -402,7 +370,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
402370
use crate::common::{AtomicRmwBinOp, SynchronizationScope};
403371

404372
let Some((instruction, ordering)) = atomic.split_once('_') else {
405-
bx.sess().fatal("Atomic intrinsic missing memory ordering");
373+
bx.sess().emit_fatal(errors::MissingMemoryOrdering);
406374
};
407375

408376
let parse_ordering = |bx: &Bx, s| match s {
@@ -412,25 +380,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
412380
"release" => Release,
413381
"acqrel" => AcquireRelease,
414382
"seqcst" => SequentiallyConsistent,
415-
_ => bx.sess().fatal("unknown ordering in atomic intrinsic"),
383+
_ => bx.sess().emit_fatal(errors::UnknownAtomicOrdering),
416384
};
417385

418386
let invalid_monomorphization = |ty| {
419-
span_invalid_monomorphization_error(
420-
bx.tcx().sess,
421-
span,
422-
&format!(
423-
"invalid monomorphization of `{}` intrinsic: \
424-
expected basic integer type, found `{}`",
425-
name, ty
426-
),
427-
);
387+
bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty });
428388
};
429389

430390
match instruction {
431391
"cxchg" | "cxchgweak" => {
432392
let Some((success, failure)) = ordering.split_once('_') else {
433-
bx.sess().fatal("Atomic compare-exchange intrinsic missing failure memory ordering");
393+
bx.sess().emit_fatal(errors::AtomicCompareExchange);
434394
};
435395
let ty = substs.type_at(0);
436396
if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() {
@@ -529,7 +489,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
529489
"min" => AtomicRmwBinOp::AtomicMin,
530490
"umax" => AtomicRmwBinOp::AtomicUMax,
531491
"umin" => AtomicRmwBinOp::AtomicUMin,
532-
_ => bx.sess().fatal("unknown atomic operation"),
492+
_ => bx.sess().emit_fatal(errors::UnknownAtomicOperation),
533493
};
534494

535495
let ty = substs.type_at(0);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,17 @@ codegen_ssa_invalid_windows_subsystem = invalid windows subsystem `{$subsystem}`
205205
codegen_ssa_erroneous_constant = erroneous constant encountered
206206
207207
codegen_ssa_shuffle_indices_evaluation = could not evaluate shuffle_indices at compile time
208+
209+
codegen_ssa_missing_memory_ordering = Atomic intrinsic missing memory ordering
210+
211+
codegen_ssa_unknown_atomic_ordering = unknown ordering in atomic intrinsic
212+
213+
codegen_ssa_atomic_compare_exchange = Atomic compare-exchange intrinsic missing failure memory ordering
214+
215+
codegen_ssa_unknown_atomic_operation = unknown atomic operation
216+
217+
codegen_ssa_invalid_monomorphization_basic_integer_type = invalid monomorphization of `{$name}` intrinsic: expected basic integer type, found `{$ty}`
218+
219+
codegen_ssa_invalid_monomorphization_basic_float_type = invalid monomorphization of `{$name}` intrinsic: expected basic float type, found `{$ty}`
220+
221+
codegen_ssa_invalid_monomorphization_float_to_int_unchecked = invalid monomorphization of `float_to_int_unchecked` intrinsic: expected basic float type, found `{$ty}`

0 commit comments

Comments
 (0)