Skip to content

Commit 08587a5

Browse files
committed
Auto merge of #118780 - GuillaumeGomez:rollup-nd0syaf, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #117953 (Add more SIMD platform-intrinsics) - #118057 (dedup for duplicate suggestions) - #118638 (More `rustc_mir_dataflow` cleanups) - #118702 (Strengthen well known check-cfg names and values test) - #118734 (Unescaping cleanups) - #118766 (Lower some forgotten spans) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1dfb228 + fd60c5a commit 08587a5

35 files changed

+1099
-283
lines changed

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
634634
// Resume argument type: `ResumeTy`
635635
let unstable_span = self.mark_span_with_reason(
636636
DesugaringKind::Async,
637-
span,
637+
self.lower_span(span),
638638
Some(self.allow_gen_future.clone()),
639639
);
640640
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
@@ -766,7 +766,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
766766
// Resume argument type: `ResumeTy`
767767
let unstable_span = self.mark_span_with_reason(
768768
DesugaringKind::Async,
769-
span,
769+
self.lower_span(span),
770770
Some(self.allow_gen_future.clone()),
771771
);
772772
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);

Diff for: compiler/rustc_ast_lowering/src/item.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1382,6 +1382,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13821382
let host_param_parts = if let Const::Yes(span) = constness
13831383
&& self.tcx.features().effects
13841384
{
1385+
let span = self.lower_span(span);
13851386
let param_node_id = self.next_node_id();
13861387
let hir_id = self.next_id();
13871388
let def_id = self.create_def(

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16791679
duplicated_lifetime_node_id,
16801680
lifetime.ident.name,
16811681
DefKind::LifetimeParam,
1682-
lifetime.ident.span,
1682+
self.lower_span(lifetime.ident.span),
16831683
);
16841684
captured_to_synthesized_mapping.insert(old_def_id, duplicated_lifetime_def_id);
16851685
// FIXME: Instead of doing this, we could move this whole loop
@@ -1688,7 +1688,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16881688
synthesized_lifetime_definitions.push((
16891689
duplicated_lifetime_node_id,
16901690
duplicated_lifetime_def_id,
1691-
lifetime.ident,
1691+
self.lower_ident(lifetime.ident),
16921692
));
16931693

16941694
// Now make an arg that we can use for the generic params of the opaque tykind.
@@ -2253,7 +2253,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22532253
match c.value.kind {
22542254
ExprKind::Underscore => {
22552255
if self.tcx.features().generic_arg_infer {
2256-
hir::ArrayLen::Infer(self.lower_node_id(c.id), c.value.span)
2256+
hir::ArrayLen::Infer(self.lower_node_id(c.id), self.lower_span(c.value.span))
22572257
} else {
22582258
feature_err(
22592259
&self.tcx.sess.parse_sess,

Diff for: compiler/rustc_borrowck/src/dataflow.rs

+70-83
Original file line numberDiff line numberDiff line change
@@ -11,101 +11,88 @@ use rustc_middle::ty::TyCtxt;
1111
use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces};
1212
use rustc_mir_dataflow::ResultsVisitable;
1313
use rustc_mir_dataflow::{self, fmt::DebugWithContext, GenKill};
14-
use rustc_mir_dataflow::{Analysis, Direction, Results};
14+
use rustc_mir_dataflow::{Analysis, AnalysisDomain, Results};
1515
use std::fmt;
1616

1717
use crate::{places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext};
1818

19-
/// A tuple with named fields that can hold either the results or the transient state of the
20-
/// dataflow analyses used by the borrow checker.
21-
#[derive(Debug)]
22-
pub struct BorrowckAnalyses<B, U, E> {
23-
pub borrows: B,
24-
pub uninits: U,
25-
pub ever_inits: E,
26-
}
27-
2819
/// The results of the dataflow analyses used by the borrow checker.
29-
pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses<
30-
Results<'tcx, Borrows<'mir, 'tcx>>,
31-
Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
32-
Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
33-
>;
20+
pub struct BorrowckResults<'mir, 'tcx> {
21+
pub(crate) borrows: Results<'tcx, Borrows<'mir, 'tcx>>,
22+
pub(crate) uninits: Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>,
23+
pub(crate) ever_inits: Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>,
24+
}
3425

3526
/// The transient state of the dataflow analyses used by the borrow checker.
36-
pub type BorrowckFlowState<'mir, 'tcx> =
37-
<BorrowckResults<'mir, 'tcx> as ResultsVisitable<'tcx>>::FlowState;
38-
39-
macro_rules! impl_visitable {
40-
( $(
41-
$T:ident { $( $field:ident : $A:ident ),* $(,)? }
42-
)* ) => { $(
43-
impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*>
44-
where
45-
$( $A: Analysis<'tcx, Direction = D>, )*
46-
{
47-
type Direction = D;
48-
type FlowState = $T<$( $A::Domain ),*>;
27+
#[derive(Debug)]
28+
pub struct BorrowckFlowState<'mir, 'tcx> {
29+
pub(crate) borrows: <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
30+
pub(crate) uninits: <MaybeUninitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
31+
pub(crate) ever_inits: <EverInitializedPlaces<'mir, 'tcx> as AnalysisDomain<'tcx>>::Domain,
32+
}
4933

50-
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
51-
$T {
52-
$( $field: self.$field.analysis.bottom_value(body) ),*
53-
}
54-
}
34+
impl<'mir, 'tcx> ResultsVisitable<'tcx> for BorrowckResults<'mir, 'tcx> {
35+
// All three analyses are forward, but we have to use just one here.
36+
type Direction = <Borrows<'mir, 'tcx> as AnalysisDomain<'tcx>>::Direction;
37+
type FlowState = BorrowckFlowState<'mir, 'tcx>;
5538

56-
fn reset_to_block_entry(
57-
&self,
58-
state: &mut Self::FlowState,
59-
block: BasicBlock,
60-
) {
61-
$( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )*
62-
}
39+
fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState {
40+
BorrowckFlowState {
41+
borrows: self.borrows.analysis.bottom_value(body),
42+
uninits: self.uninits.analysis.bottom_value(body),
43+
ever_inits: self.ever_inits.analysis.bottom_value(body),
44+
}
45+
}
6346

64-
fn reconstruct_before_statement_effect(
65-
&mut self,
66-
state: &mut Self::FlowState,
67-
stmt: &mir::Statement<'tcx>,
68-
loc: Location,
69-
) {
70-
$( self.$field.analysis
71-
.apply_before_statement_effect(&mut state.$field, stmt, loc); )*
72-
}
47+
fn reset_to_block_entry(&self, state: &mut Self::FlowState, block: BasicBlock) {
48+
state.borrows.clone_from(&self.borrows.entry_set_for_block(block));
49+
state.uninits.clone_from(&self.uninits.entry_set_for_block(block));
50+
state.ever_inits.clone_from(&self.ever_inits.entry_set_for_block(block));
51+
}
7352

74-
fn reconstruct_statement_effect(
75-
&mut self,
76-
state: &mut Self::FlowState,
77-
stmt: &mir::Statement<'tcx>,
78-
loc: Location,
79-
) {
80-
$( self.$field.analysis
81-
.apply_statement_effect(&mut state.$field, stmt, loc); )*
82-
}
53+
fn reconstruct_before_statement_effect(
54+
&mut self,
55+
state: &mut Self::FlowState,
56+
stmt: &mir::Statement<'tcx>,
57+
loc: Location,
58+
) {
59+
self.borrows.analysis.apply_before_statement_effect(&mut state.borrows, stmt, loc);
60+
self.uninits.analysis.apply_before_statement_effect(&mut state.uninits, stmt, loc);
61+
self.ever_inits.analysis.apply_before_statement_effect(&mut state.ever_inits, stmt, loc);
62+
}
8363

84-
fn reconstruct_before_terminator_effect(
85-
&mut self,
86-
state: &mut Self::FlowState,
87-
term: &mir::Terminator<'tcx>,
88-
loc: Location,
89-
) {
90-
$( self.$field.analysis
91-
.apply_before_terminator_effect(&mut state.$field, term, loc); )*
92-
}
64+
fn reconstruct_statement_effect(
65+
&mut self,
66+
state: &mut Self::FlowState,
67+
stmt: &mir::Statement<'tcx>,
68+
loc: Location,
69+
) {
70+
self.borrows.analysis.apply_statement_effect(&mut state.borrows, stmt, loc);
71+
self.uninits.analysis.apply_statement_effect(&mut state.uninits, stmt, loc);
72+
self.ever_inits.analysis.apply_statement_effect(&mut state.ever_inits, stmt, loc);
73+
}
9374

94-
fn reconstruct_terminator_effect(
95-
&mut self,
96-
state: &mut Self::FlowState,
97-
term: &mir::Terminator<'tcx>,
98-
loc: Location,
99-
) {
100-
$( self.$field.analysis
101-
.apply_terminator_effect(&mut state.$field, term, loc); )*
102-
}
103-
}
104-
)* }
105-
}
75+
fn reconstruct_before_terminator_effect(
76+
&mut self,
77+
state: &mut Self::FlowState,
78+
term: &mir::Terminator<'tcx>,
79+
loc: Location,
80+
) {
81+
self.borrows.analysis.apply_before_terminator_effect(&mut state.borrows, term, loc);
82+
self.uninits.analysis.apply_before_terminator_effect(&mut state.uninits, term, loc);
83+
self.ever_inits.analysis.apply_before_terminator_effect(&mut state.ever_inits, term, loc);
84+
}
10685

107-
impl_visitable! {
108-
BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E }
86+
fn reconstruct_terminator_effect(
87+
&mut self,
88+
state: &mut Self::FlowState,
89+
term: &mir::Terminator<'tcx>,
90+
loc: Location,
91+
) {
92+
self.borrows.analysis.apply_terminator_effect(&mut state.borrows, term, loc);
93+
self.uninits.analysis.apply_terminator_effect(&mut state.uninits, term, loc);
94+
self.ever_inits.analysis.apply_terminator_effect(&mut state.ever_inits, term, loc);
95+
}
10996
}
11097

11198
rustc_index::newtype_index! {
@@ -598,7 +585,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
598585

599586
fn before_terminator_effect(
600587
&mut self,
601-
trans: &mut impl GenKill<Self::Idx>,
588+
trans: &mut Self::Domain,
602589
_terminator: &mir::Terminator<'tcx>,
603590
location: Location,
604591
) {
@@ -625,7 +612,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> {
625612

626613
fn call_return_effect(
627614
&mut self,
628-
_trans: &mut impl GenKill<Self::Idx>,
615+
_trans: &mut Self::Domain,
629616
_block: mir::BasicBlock,
630617
_return_places: CallReturnPlaces<'_, 'tcx>,
631618
) {

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+51-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Codegen `extern "platform-intrinsic"` intrinsics.
22
3+
use cranelift_codegen::ir::immediates::Offset32;
34
use rustc_middle::ty::GenericArgsRef;
45
use rustc_span::Symbol;
56
use rustc_target::abi::Endian;
@@ -1008,8 +1009,57 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
10081009
}
10091010
}
10101011

1012+
sym::simd_masked_load => {
1013+
intrinsic_args!(fx, args => (mask, ptr, val); intrinsic);
1014+
1015+
let (val_lane_count, val_lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx);
1016+
let (mask_lane_count, _mask_lane_ty) = mask.layout().ty.simd_size_and_type(fx.tcx);
1017+
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
1018+
assert_eq!(val_lane_count, mask_lane_count);
1019+
assert_eq!(val_lane_count, ret_lane_count);
1020+
1021+
let lane_clif_ty = fx.clif_type(val_lane_ty).unwrap();
1022+
let ret_lane_layout = fx.layout_of(ret_lane_ty);
1023+
let ptr_val = ptr.load_scalar(fx);
1024+
1025+
for lane_idx in 0..ret_lane_count {
1026+
let val_lane = val.value_lane(fx, lane_idx).load_scalar(fx);
1027+
let mask_lane = mask.value_lane(fx, lane_idx).load_scalar(fx);
1028+
1029+
let if_enabled = fx.bcx.create_block();
1030+
let if_disabled = fx.bcx.create_block();
1031+
let next = fx.bcx.create_block();
1032+
let res_lane = fx.bcx.append_block_param(next, lane_clif_ty);
1033+
1034+
fx.bcx.ins().brif(mask_lane, if_enabled, &[], if_disabled, &[]);
1035+
fx.bcx.seal_block(if_enabled);
1036+
fx.bcx.seal_block(if_disabled);
1037+
1038+
fx.bcx.switch_to_block(if_enabled);
1039+
let offset = lane_idx as i32 * lane_clif_ty.bytes() as i32;
1040+
let res = fx.bcx.ins().load(
1041+
lane_clif_ty,
1042+
MemFlags::trusted(),
1043+
ptr_val,
1044+
Offset32::new(offset),
1045+
);
1046+
fx.bcx.ins().jump(next, &[res]);
1047+
1048+
fx.bcx.switch_to_block(if_disabled);
1049+
fx.bcx.ins().jump(next, &[val_lane]);
1050+
1051+
fx.bcx.seal_block(next);
1052+
fx.bcx.switch_to_block(next);
1053+
1054+
fx.bcx.ins().nop();
1055+
1056+
ret.place_lane(fx, lane_idx)
1057+
.write_cvalue(fx, CValue::by_val(res_lane, ret_lane_layout));
1058+
}
1059+
}
1060+
10111061
sym::simd_scatter => {
1012-
intrinsic_args!(fx, args => (val, ptr, mask); intrinsic);
1062+
intrinsic_args!(fx, args => (mask, ptr, val); intrinsic);
10131063

10141064
let (val_lane_count, _val_lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx);
10151065
let (ptr_lane_count, _ptr_lane_ty) = ptr.layout().ty.simd_size_and_type(fx.tcx);

0 commit comments

Comments
 (0)