Skip to content

Commit 47aee31

Browse files
committed
Auto merge of #97849 - matthiaskrgr:rollup-1yodhvw, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #97829 (Add regresion test for #95307) - #97831 (Remove `AlwaysLiveLocals` wrapper struct) - #97832 (Change `Direction::{is_forward,is_backward}` functions into constants) - #97840 (RustWrapper: adapt to APInt API changes in LLVM 15) - #97845 (Use more targeted suggestion when confusing i8 with std::i8) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b17e9d7 + c2d8485 commit 47aee31

File tree

16 files changed

+107
-86
lines changed

16 files changed

+107
-86
lines changed

compiler/rustc_const_eval/src/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::layout::{
1515
use rustc_middle::ty::{
1616
self, query::TyCtxtAt, subst::SubstsRef, ParamEnv, Ty, TyCtxt, TypeFoldable,
1717
};
18-
use rustc_mir_dataflow::storage::AlwaysLiveLocals;
18+
use rustc_mir_dataflow::storage::always_live_locals;
1919
use rustc_query_system::ich::StableHashingContext;
2020
use rustc_session::Limit;
2121
use rustc_span::{Pos, Span};
@@ -715,7 +715,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
715715

716716
// Now mark those locals as dead that we do not want to initialize
717717
// Mark locals that use `Storage*` annotations as dead on function entry.
718-
let always_live = AlwaysLiveLocals::new(self.body());
718+
let always_live = always_live_locals(self.body());
719719
for local in locals.indices() {
720720
if !always_live.contains(local) {
721721
locals[local].value = LocalValue::Dead;

compiler/rustc_const_eval/src/transform/validate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::{
1414
use rustc_middle::ty::fold::BottomUpFolder;
1515
use rustc_middle::ty::{self, InstanceDef, ParamEnv, Ty, TyCtxt, TypeFoldable};
1616
use rustc_mir_dataflow::impls::MaybeStorageLive;
17-
use rustc_mir_dataflow::storage::AlwaysLiveLocals;
17+
use rustc_mir_dataflow::storage::always_live_locals;
1818
use rustc_mir_dataflow::{Analysis, ResultsCursor};
1919
use rustc_target::abi::{Size, VariantIdx};
2020

@@ -48,7 +48,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
4848
let param_env = tcx.param_env(def_id);
4949
let mir_phase = self.mir_phase;
5050

51-
let always_live_locals = AlwaysLiveLocals::new(body);
51+
let always_live_locals = always_live_locals(body);
5252
let storage_liveness = MaybeStorageLive::new(always_live_locals)
5353
.into_engine(tcx, body)
5454
.iterate_to_fixpoint()

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1542,11 +1542,19 @@ extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *hig
15421542
auto C = unwrap<llvm::ConstantInt>(CV);
15431543
if (C->getBitWidth() > 128) { return false; }
15441544
APInt AP;
1545+
#if LLVM_VERSION_GE(15, 0)
1546+
if (sext) {
1547+
AP = C->getValue().sext(128);
1548+
} else {
1549+
AP = C->getValue().zext(128);
1550+
}
1551+
#else
15451552
if (sext) {
15461553
AP = C->getValue().sextOrSelf(128);
15471554
} else {
15481555
AP = C->getValue().zextOrSelf(128);
15491556
}
1557+
#endif
15501558
*low = AP.getLoBits(64).getZExtValue();
15511559
*high = AP.getHiBits(64).getZExtValue();
15521560
return true;

compiler/rustc_mir_dataflow/src/framework/cursor.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ where
109109
/// For backward analyses, this is the state that will be propagated to its
110110
/// predecessors (ignoring edge-specific effects).
111111
pub fn seek_to_block_start(&mut self, block: BasicBlock) {
112-
if A::Direction::is_forward() {
112+
if A::Direction::IS_FORWARD {
113113
self.seek_to_block_entry(block)
114114
} else {
115115
self.seek_after(Location { block, statement_index: 0 }, Effect::Primary)
@@ -123,7 +123,7 @@ where
123123
/// For forward analyses, this is the state that will be propagated to its
124124
/// successors (ignoring edge-specific effects).
125125
pub fn seek_to_block_end(&mut self, block: BasicBlock) {
126-
if A::Direction::is_backward() {
126+
if A::Direction::IS_BACKWARD {
127127
self.seek_to_block_entry(block)
128128
} else {
129129
self.seek_after(self.body.terminator_loc(block), Effect::Primary)
@@ -157,7 +157,7 @@ where
157157
self.seek_to_block_entry(target.block);
158158
} else if let Some(curr_effect) = self.pos.curr_effect_index {
159159
let mut ord = curr_effect.statement_index.cmp(&target.statement_index);
160-
if A::Direction::is_backward() {
160+
if A::Direction::IS_BACKWARD {
161161
ord = ord.reverse()
162162
}
163163

@@ -173,7 +173,7 @@ where
173173
debug_assert_eq!(target.block, self.pos.block);
174174

175175
let block_data = &self.body[target.block];
176-
let next_effect = if A::Direction::is_forward() {
176+
let next_effect = if A::Direction::IS_FORWARD {
177177
#[rustfmt::skip]
178178
self.pos.curr_effect_index.map_or_else(
179179
|| Effect::Before.at_index(0),

compiler/rustc_mir_dataflow/src/framework/direction.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use super::{
99
};
1010

1111
pub trait Direction {
12-
fn is_forward() -> bool;
12+
const IS_FORWARD: bool;
1313

14-
fn is_backward() -> bool {
15-
!Self::is_forward()
16-
}
14+
const IS_BACKWARD: bool = !Self::IS_FORWARD;
1715

1816
/// Applies all effects between the given `EffectIndex`s.
1917
///
@@ -68,9 +66,7 @@ pub trait Direction {
6866
pub struct Backward;
6967

7068
impl Direction for Backward {
71-
fn is_forward() -> bool {
72-
false
73-
}
69+
const IS_FORWARD: bool = false;
7470

7571
fn apply_effects_in_block<'tcx, A>(
7672
analysis: &A,
@@ -338,9 +334,7 @@ where
338334
pub struct Forward;
339335

340336
impl Direction for Forward {
341-
fn is_forward() -> bool {
342-
true
343-
}
337+
const IS_FORWARD: bool = true;
344338

345339
fn apply_effects_in_block<'tcx, A>(
346340
analysis: &A,

compiler/rustc_mir_dataflow/src/framework/engine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ where
147147
let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), body.basic_blocks());
148148
analysis.initialize_start_block(body, &mut entry_sets[mir::START_BLOCK]);
149149

150-
if A::Direction::is_backward() && entry_sets[mir::START_BLOCK] != bottom_value {
150+
if A::Direction::IS_BACKWARD && entry_sets[mir::START_BLOCK] != bottom_value {
151151
bug!("`initialize_start_block` is not yet supported for backward dataflow analyses");
152152
}
153153

@@ -200,7 +200,7 @@ where
200200
let mut dirty_queue: WorkQueue<BasicBlock> =
201201
WorkQueue::with_none(body.basic_blocks().len());
202202

203-
if A::Direction::is_forward() {
203+
if A::Direction::IS_FORWARD {
204204
for (bb, _) in traversal::reverse_postorder(body) {
205205
dirty_queue.insert(bb);
206206
}

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ where
216216
// Write the full dataflow state immediately after the terminator if it differs from the
217217
// state at block entry.
218218
self.results.seek_to_block_end(block);
219-
if self.results.get() != &block_start_state || A::Direction::is_backward() {
219+
if self.results.get() != &block_start_state || A::Direction::IS_BACKWARD {
220220
let after_terminator_name = match terminator.kind {
221221
mir::TerminatorKind::Call { target: Some(_), .. } => "(on unwind)",
222222
_ => "(on end)",
@@ -390,7 +390,7 @@ where
390390
let mut afters = diffs.after.into_iter();
391391

392392
let next_in_dataflow_order = |it: &mut std::vec::IntoIter<_>| {
393-
if A::Direction::is_forward() { it.next().unwrap() } else { it.next_back().unwrap() }
393+
if A::Direction::IS_FORWARD { it.next().unwrap() } else { it.next_back().unwrap() }
394394
};
395395

396396
for (i, statement) in body[block].statements.iter().enumerate() {
@@ -527,7 +527,7 @@ where
527527
_block_data: &mir::BasicBlockData<'tcx>,
528528
_block: BasicBlock,
529529
) {
530-
if A::Direction::is_forward() {
530+
if A::Direction::IS_FORWARD {
531531
self.prev_state.clone_from(state);
532532
}
533533
}
@@ -538,7 +538,7 @@ where
538538
_block_data: &mir::BasicBlockData<'tcx>,
539539
_block: BasicBlock,
540540
) {
541-
if A::Direction::is_backward() {
541+
if A::Direction::IS_BACKWARD {
542542
self.prev_state.clone_from(state);
543543
}
544544
}

compiler/rustc_mir_dataflow/src/framework/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl<D: Direction> MockAnalysis<'_, D> {
140140
SeekTarget::After(loc) => Effect::Primary.at_index(loc.statement_index),
141141
};
142142

143-
let mut pos = if D::is_forward() {
143+
let mut pos = if D::IS_FORWARD {
144144
Effect::Before.at_index(0)
145145
} else {
146146
Effect::Before.at_index(self.body[block].statements.len())
@@ -153,7 +153,7 @@ impl<D: Direction> MockAnalysis<'_, D> {
153153
return ret;
154154
}
155155

156-
if D::is_forward() {
156+
if D::IS_FORWARD {
157157
pos = pos.next_in_forward_order();
158158
} else {
159159
pos = pos.next_in_backward_order();

compiler/rustc_mir_dataflow/src/impls/storage_liveness.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
pub use super::*;
22

3-
use crate::storage::AlwaysLiveLocals;
43
use crate::{CallReturnPlaces, GenKill, Results, ResultsRefCursor};
54
use rustc_middle::mir::visit::{NonMutatingUseContext, PlaceContext, Visitor};
65
use rustc_middle::mir::*;
76
use std::cell::RefCell;
87

98
#[derive(Clone)]
109
pub struct MaybeStorageLive {
11-
always_live_locals: AlwaysLiveLocals,
10+
always_live_locals: BitSet<Local>,
1211
}
1312

1413
impl MaybeStorageLive {
15-
pub fn new(always_live_locals: AlwaysLiveLocals) -> Self {
14+
pub fn new(always_live_locals: BitSet<Local>) -> Self {
1615
MaybeStorageLive { always_live_locals }
1716
}
1817
}

compiler/rustc_mir_dataflow/src/storage.rs

+8-26
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,17 @@ use rustc_middle::mir::{self, Local};
77
//
88
// FIXME: Currently, we need to traverse the entire MIR to compute this. We should instead store it
99
// as a field in the `LocalDecl` for each `Local`.
10-
#[derive(Debug, Clone)]
11-
pub struct AlwaysLiveLocals(BitSet<Local>);
10+
pub fn always_live_locals(body: &mir::Body<'_>) -> BitSet<Local> {
11+
let mut always_live_locals = BitSet::new_filled(body.local_decls.len());
1212

13-
impl AlwaysLiveLocals {
14-
pub fn new(body: &mir::Body<'_>) -> Self {
15-
let mut always_live_locals = AlwaysLiveLocals(BitSet::new_filled(body.local_decls.len()));
16-
17-
for block in body.basic_blocks() {
18-
for statement in &block.statements {
19-
use mir::StatementKind::{StorageDead, StorageLive};
20-
if let StorageLive(l) | StorageDead(l) = statement.kind {
21-
always_live_locals.0.remove(l);
22-
}
13+
for block in body.basic_blocks() {
14+
for statement in &block.statements {
15+
use mir::StatementKind::{StorageDead, StorageLive};
16+
if let StorageLive(l) | StorageDead(l) = statement.kind {
17+
always_live_locals.remove(l);
2318
}
2419
}
25-
26-
always_live_locals
2720
}
2821

29-
pub fn into_inner(self) -> BitSet<Local> {
30-
self.0
31-
}
32-
}
33-
34-
impl std::ops::Deref for AlwaysLiveLocals {
35-
type Target = BitSet<Local>;
36-
37-
#[inline]
38-
fn deref(&self) -> &Self::Target {
39-
&self.0
40-
}
22+
always_live_locals
4123
}

compiler/rustc_mir_transform/src/generator.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ struct TransformVisitor<'tcx> {
228228
suspension_points: Vec<SuspensionPoint<'tcx>>,
229229

230230
// The set of locals that have no `StorageLive`/`StorageDead` annotations.
231-
always_live_locals: storage::AlwaysLiveLocals,
231+
always_live_locals: BitSet<Local>,
232232

233233
// The original RETURN_PLACE local
234234
new_ret_local: Local,
@@ -450,7 +450,7 @@ struct LivenessInfo {
450450
fn locals_live_across_suspend_points<'tcx>(
451451
tcx: TyCtxt<'tcx>,
452452
body: &Body<'tcx>,
453-
always_live_locals: &storage::AlwaysLiveLocals,
453+
always_live_locals: &BitSet<Local>,
454454
movable: bool,
455455
) -> LivenessInfo {
456456
let body_ref: &Body<'_> = &body;
@@ -615,7 +615,7 @@ impl ops::Deref for GeneratorSavedLocals {
615615
fn compute_storage_conflicts<'mir, 'tcx>(
616616
body: &'mir Body<'tcx>,
617617
saved_locals: &GeneratorSavedLocals,
618-
always_live_locals: storage::AlwaysLiveLocals,
618+
always_live_locals: BitSet<Local>,
619619
requires_storage: rustc_mir_dataflow::Results<'tcx, MaybeRequiresStorage<'mir, 'tcx>>,
620620
) -> BitMatrix<GeneratorSavedLocal, GeneratorSavedLocal> {
621621
assert_eq!(body.local_decls.len(), saved_locals.domain_size());
@@ -625,7 +625,7 @@ fn compute_storage_conflicts<'mir, 'tcx>(
625625

626626
// Locals that are always live or ones that need to be stored across
627627
// suspension points are not eligible for overlap.
628-
let mut ineligible_locals = always_live_locals.into_inner();
628+
let mut ineligible_locals = always_live_locals;
629629
ineligible_locals.intersect(&**saved_locals);
630630

631631
// Compute the storage conflicts for all eligible locals.
@@ -1300,7 +1300,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
13001300
},
13011301
);
13021302

1303-
let always_live_locals = storage::AlwaysLiveLocals::new(&body);
1303+
let always_live_locals = storage::always_live_locals(&body);
13041304

13051305
let liveness_info =
13061306
locals_live_across_suspend_points(tcx, body, &always_live_locals, movable);

compiler/rustc_typeck/src/astconv/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1577,18 +1577,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15771577
name: Symbol,
15781578
) -> ErrorGuaranteed {
15791579
let mut err = struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type");
1580-
if let (true, Ok(snippet)) = (
1581-
self.tcx()
1582-
.resolutions(())
1583-
.confused_type_with_std_module
1584-
.keys()
1585-
.any(|full_span| full_span.contains(span)),
1586-
self.tcx().sess.source_map().span_to_snippet(span),
1587-
) {
1580+
if self
1581+
.tcx()
1582+
.resolutions(())
1583+
.confused_type_with_std_module
1584+
.keys()
1585+
.any(|full_span| full_span.contains(span))
1586+
{
15881587
err.span_suggestion(
1589-
span,
1588+
span.shrink_to_lo(),
15901589
"you are looking for the module in `std`, not the primitive type",
1591-
format!("std::{}", snippet),
1590+
"std::".to_string(),
15921591
Applicability::MachineApplicable,
15931592
);
15941593
} else {

compiler/rustc_typeck/src/check/method/suggest.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
327327
);
328328
}
329329
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) {
330-
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*span) {
331-
err.span_suggestion(
332-
*span,
333-
"you are looking for the module in `std`, \
334-
not the primitive type",
335-
format!("std::{}", snippet),
336-
Applicability::MachineApplicable,
337-
);
338-
}
330+
err.span_suggestion(
331+
span.shrink_to_lo(),
332+
"you are looking for the module in `std`, not the primitive type",
333+
"std::".to_string(),
334+
Applicability::MachineApplicable,
335+
);
339336
}
340337
if let ty::RawPtr(_) = &actual.kind() {
341338
err.note(
342339
"try using `<*const T>::as_ref()` to get a reference to the \
343-
type behind the pointer: https://doc.rust-lang.org/std/\
344-
primitive.pointer.html#method.as_ref",
340+
type behind the pointer: https://doc.rust-lang.org/std/\
341+
primitive.pointer.html#method.as_ref",
345342
);
346343
err.note(
347-
"using `<*const T>::as_ref()` on a pointer \
348-
which is unaligned or points to invalid \
349-
or uninitialized memory is undefined behavior",
344+
"using `<*const T>::as_ref()` on a pointer which is unaligned or points \
345+
to invalid or uninitialized memory is undefined behavior",
350346
);
351347
}
352348

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// edition:2018
2+
3+
// Regression test for #95307.
4+
// The ICE occurred on all the editions, specifying edition:2018 to reduce diagnostics.
5+
6+
pub trait C {
7+
async fn new() -> [u8; _];
8+
//~^ ERROR: functions in traits cannot be declared `async`
9+
//~| ERROR: using `_` for array lengths is unstable
10+
//~| ERROR: in expressions, `_` can only be used on the left-hand side of an assignment
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)