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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 4 additions & 10 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 8 additions & 26 deletions
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
}

0 commit comments

Comments
 (0)