Skip to content

Commit c5775a7

Browse files
committed
Auto merge of rust-lang#115602 - oli-obk:lower_intrinsics, r=petrochenkov
Don't report any errors in `lower_intrinsics`. Intrinsics should have been type checked earlier. This is part of moving all mir-opt diagnostics early enough so that they are reliably emitted even in check builds: rust-lang#49292 (comment)
2 parents 7f0fa48 + 65f25fe commit c5775a7

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

compiler/rustc_borrowck/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ borrowck_returned_lifetime_wrong =
166166
borrowck_returned_ref_escaped =
167167
returns a reference to a captured variable which escapes the closure body
168168
169+
borrowck_simd_shuffle_last_const = last argument of `simd_shuffle` is required to be a `const` item
170+
169171
borrowck_suggest_create_freash_reborrow =
170172
consider reborrowing the `Pin` instead of moving it
171173

compiler/rustc_borrowck/src/session_diagnostics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,10 @@ pub(crate) enum TypeNoCopy<'a, 'tcx> {
452452
#[note(borrowck_ty_no_impl_copy)]
453453
Note { is_partial_move: bool, ty: Ty<'tcx>, place: &'a str },
454454
}
455+
456+
#[derive(Diagnostic)]
457+
#[diag(borrowck_simd_shuffle_last_const)]
458+
pub(crate) struct SimdShuffleLastConst {
459+
#[primary_span]
460+
pub span: Span,
461+
}

compiler/rustc_borrowck/src/type_check/mod.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
5050
use rustc_mir_dataflow::move_paths::MoveData;
5151
use rustc_mir_dataflow::ResultsCursor;
5252

53-
use crate::session_diagnostics::MoveUnsized;
53+
use crate::session_diagnostics::{MoveUnsized, SimdShuffleLastConst};
5454
use crate::{
5555
borrow_set::BorrowSet,
5656
constraints::{OutlivesConstraint, OutlivesConstraintSet},
@@ -1426,7 +1426,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14261426
.add_element(region_vid, term_location);
14271427
}
14281428

1429-
self.check_call_inputs(body, term, &sig, args, term_location, *call_source);
1429+
self.check_call_inputs(body, term, func, &sig, args, term_location, *call_source);
14301430
}
14311431
TerminatorKind::Assert { cond, msg, .. } => {
14321432
self.check_operand(cond, term_location);
@@ -1546,33 +1546,44 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
15461546
}
15471547
}
15481548

1549+
#[instrument(level = "debug", skip(self, body, term, func, term_location, call_source))]
15491550
fn check_call_inputs(
15501551
&mut self,
15511552
body: &Body<'tcx>,
15521553
term: &Terminator<'tcx>,
1554+
func: &Operand<'tcx>,
15531555
sig: &ty::FnSig<'tcx>,
15541556
args: &[Operand<'tcx>],
15551557
term_location: Location,
15561558
call_source: CallSource,
15571559
) {
1558-
debug!("check_call_inputs({:?}, {:?})", sig, args);
15591560
if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.c_variadic) {
15601561
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
15611562
}
15621563

1563-
let func_ty = if let TerminatorKind::Call { func, .. } = &term.kind {
1564-
Some(func.ty(body, self.infcx.tcx))
1565-
} else {
1566-
None
1567-
};
1564+
let func_ty = func.ty(body, self.infcx.tcx);
1565+
if let ty::FnDef(def_id, _) = *func_ty.kind() {
1566+
if self.tcx().is_intrinsic(def_id) {
1567+
match self.tcx().item_name(def_id) {
1568+
sym::simd_shuffle => {
1569+
if !matches!(args[2], Operand::Constant(_)) {
1570+
self.tcx()
1571+
.sess
1572+
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
1573+
}
1574+
}
1575+
_ => {}
1576+
}
1577+
}
1578+
}
15681579
debug!(?func_ty);
15691580

15701581
for (n, (fn_arg, op_arg)) in iter::zip(sig.inputs(), args).enumerate() {
15711582
let op_arg_ty = op_arg.ty(body, self.tcx());
15721583

15731584
let op_arg_ty = self.normalize(op_arg_ty, term_location);
15741585
let category = if call_source.from_hir_call() {
1575-
ConstraintCategory::CallArgument(self.infcx.tcx.erase_regions(func_ty))
1586+
ConstraintCategory::CallArgument(Some(self.infcx.tcx.erase_regions(func_ty)))
15761587
} else {
15771588
ConstraintCategory::Boring
15781589
};

compiler/rustc_mir_transform/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ mir_transform_requires_unsafe = {$details} is unsafe and requires unsafe {$op_in
4242
}
4343
.not_inherited = items do not inherit unsafety from separate enclosing items
4444
45-
mir_transform_simd_shuffle_last_const = last argument of `simd_shuffle` is required to be a `const` item
46-
4745
mir_transform_target_feature_call_label = call to function with `#[target_feature]`
4846
mir_transform_target_feature_call_note = can only be called if the required target features are available
4947

compiler/rustc_mir_transform/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,3 @@ pub(crate) struct MustNotSuspendReason {
258258
pub span: Span,
259259
pub reason: String,
260260
}
261-
262-
#[derive(Diagnostic)]
263-
#[diag(mir_transform_simd_shuffle_last_const)]
264-
pub(crate) struct SimdShuffleLastConst {
265-
#[primary_span]
266-
pub span: Span,
267-
}

compiler/rustc_mir_transform/src/lower_intrinsics.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//! Lowers intrinsic calls
22
3-
use crate::{errors, MirPass};
3+
use crate::MirPass;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::GenericArgsRef;
66
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_span::symbol::{sym, Symbol};
8-
use rustc_span::Span;
98
use rustc_target::abi::{FieldIdx, VariantIdx};
109

1110
pub struct LowerIntrinsics;
@@ -304,9 +303,6 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics {
304303
terminator.kind = TerminatorKind::Unreachable;
305304
}
306305
}
307-
sym::simd_shuffle => {
308-
validate_simd_shuffle(tcx, args, terminator.source_info.span);
309-
}
310306
_ => {}
311307
}
312308
}
@@ -325,9 +321,3 @@ fn resolve_rust_intrinsic<'tcx>(
325321
}
326322
None
327323
}
328-
329-
fn validate_simd_shuffle<'tcx>(tcx: TyCtxt<'tcx>, args: &[Operand<'tcx>], span: Span) {
330-
if !matches!(args[2], Operand::Constant(_)) {
331-
tcx.sess.emit_err(errors::SimdShuffleLastConst { span });
332-
}
333-
}

0 commit comments

Comments
 (0)