Skip to content

Commit 37daf4f

Browse files
Make rustc_peek use the unified dataflow framework
1 parent 798caf9 commit 37daf4f

File tree

2 files changed

+30
-34
lines changed

2 files changed

+30
-34
lines changed

src/librustc_mir/transform/rustc_peek.rs

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@ use rustc::ty::{self, Ty, TyCtxt};
99
use rustc_hir::def_id::DefId;
1010
use rustc_index::bit_set::BitSet;
1111

12+
use crate::dataflow::generic::{Analysis, Engine, Results, ResultsCursor};
1213
use crate::dataflow::move_paths::{HasMoveData, MoveData};
1314
use crate::dataflow::move_paths::{LookupResult, MovePathIndex};
14-
use crate::dataflow::BitDenotation;
15-
use crate::dataflow::DataflowResults;
16-
use crate::dataflow::DataflowResultsCursor;
1715
use crate::dataflow::IndirectlyMutableLocals;
1816
use crate::dataflow::MoveDataParamEnv;
1917
use crate::dataflow::{do_dataflow, DebugFormatted};
2018
use crate::dataflow::{
2119
DefinitelyInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,
2220
};
2321

24-
use crate::dataflow::has_rustc_mir_with;
25-
2622
pub struct SanityCheck;
2723

2824
impl<'tcx> MirPass<'tcx> for SanityCheck {
2925
fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut BodyAndCache<'tcx>) {
26+
use crate::dataflow::has_rustc_mir_with;
27+
3028
let def_id = src.def_id();
3129
if !tcx.has_attr(def_id, sym::rustc_mir) {
3230
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
@@ -40,34 +38,25 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
4038
let move_data = MoveData::gather_moves(body, tcx, param_env).unwrap();
4139
let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env };
4240
let dead_unwinds = BitSet::new_empty(body.basic_blocks().len());
43-
let flow_inits = do_dataflow(
44-
tcx,
45-
body,
46-
def_id,
47-
&attributes,
48-
&dead_unwinds,
49-
MaybeInitializedPlaces::new(tcx, body, &mdpe),
50-
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
51-
);
52-
let flow_uninits = do_dataflow(
41+
42+
let flow_inits =
43+
Engine::new_gen_kill(tcx, body, def_id, MaybeInitializedPlaces::new(tcx, body, &mdpe))
44+
.iterate_to_fixpoint();
45+
let flow_uninits = Engine::new_gen_kill(
5346
tcx,
5447
body,
5548
def_id,
56-
&attributes,
57-
&dead_unwinds,
5849
MaybeUninitializedPlaces::new(tcx, body, &mdpe),
59-
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
60-
);
61-
let flow_def_inits = do_dataflow(
50+
)
51+
.iterate_to_fixpoint();
52+
let flow_def_inits = Engine::new_gen_kill(
6253
tcx,
6354
body,
6455
def_id,
65-
&attributes,
66-
&dead_unwinds,
6756
DefinitelyInitializedPlaces::new(tcx, body, &mdpe),
68-
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
69-
);
70-
let flow_indirectly_mut = do_dataflow(
57+
)
58+
.iterate_to_fixpoint();
59+
let _flow_indirectly_mut = do_dataflow(
7160
tcx,
7261
body,
7362
def_id,
@@ -86,9 +75,12 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
8675
if has_rustc_mir_with(&attributes, sym::rustc_peek_definite_init).is_some() {
8776
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_def_inits);
8877
}
78+
// FIXME: Uncomment these as analyses are migrated to the new framework
79+
/*
8980
if has_rustc_mir_with(&attributes, sym::rustc_peek_indirectly_mutable).is_some() {
9081
sanity_check_via_rustc_peek(tcx, body, def_id, &attributes, &flow_indirectly_mut);
9182
}
83+
*/
9284
if has_rustc_mir_with(&attributes, sym::stop_after_dataflow).is_some() {
9385
tcx.sess.fatal("stop_after_dataflow ended compilation");
9486
}
@@ -111,18 +103,18 @@ impl<'tcx> MirPass<'tcx> for SanityCheck {
111103
/// (If there are any calls to `rustc_peek` that do not match the
112104
/// expression form above, then that emits an error as well, but those
113105
/// errors are not intended to be used for unit tests.)
114-
pub fn sanity_check_via_rustc_peek<'tcx, O>(
106+
pub fn sanity_check_via_rustc_peek<'tcx, A>(
115107
tcx: TyCtxt<'tcx>,
116108
body: &Body<'tcx>,
117109
def_id: DefId,
118110
_attributes: &[ast::Attribute],
119-
results: &DataflowResults<'tcx, O>,
111+
results: &Results<'tcx, A>,
120112
) where
121-
O: RustcPeekAt<'tcx>,
113+
A: RustcPeekAt<'tcx>,
122114
{
123115
debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id);
124116

125-
let mut cursor = DataflowResultsCursor::new(results, body);
117+
let mut cursor = ResultsCursor::new(body, results);
126118

127119
let peek_calls = body.basic_blocks().iter_enumerated().filter_map(|(bb, block_data)| {
128120
PeekCall::from_terminator(tcx, block_data.terminator()).map(|call| (bb, block_data, call))
@@ -153,9 +145,9 @@ pub fn sanity_check_via_rustc_peek<'tcx, O>(
153145
| (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Move(place)))
154146
| (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Copy(place))) => {
155147
let loc = Location { block: bb, statement_index };
156-
cursor.seek(loc);
148+
cursor.seek_before(loc);
157149
let state = cursor.get();
158-
results.operator().peek_at(tcx, place, state, call);
150+
results.analysis.peek_at(tcx, place, state, call);
159151
}
160152

161153
_ => {
@@ -255,7 +247,7 @@ impl PeekCall {
255247
}
256248
}
257249

258-
pub trait RustcPeekAt<'tcx>: BitDenotation<'tcx> {
250+
pub trait RustcPeekAt<'tcx>: Analysis<'tcx> {
259251
fn peek_at(
260252
&self,
261253
tcx: TyCtxt<'tcx>,
@@ -265,9 +257,9 @@ pub trait RustcPeekAt<'tcx>: BitDenotation<'tcx> {
265257
);
266258
}
267259

268-
impl<'tcx, O> RustcPeekAt<'tcx> for O
260+
impl<'tcx, A> RustcPeekAt<'tcx> for A
269261
where
270-
O: BitDenotation<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
262+
A: Analysis<'tcx, Idx = MovePathIndex> + HasMoveData<'tcx>,
271263
{
272264
fn peek_at(
273265
&self,
@@ -292,6 +284,7 @@ where
292284
}
293285
}
294286

287+
/* FIXME: Add this back once `IndirectlyMutableLocals` uses the new dataflow framework.
295288
impl<'tcx> RustcPeekAt<'tcx> for IndirectlyMutableLocals<'_, 'tcx> {
296289
fn peek_at(
297290
&self,
@@ -313,3 +306,4 @@ impl<'tcx> RustcPeekAt<'tcx> for IndirectlyMutableLocals<'_, 'tcx> {
313306
}
314307
}
315308
}
309+
*/

src/test/ui/mir-dataflow/indirect-mutation-offset.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// compile-flags: -Zunleash-the-miri-inside-of-you
22

3+
// ignore-test Temporarily ignored while this analysis is migrated to the new framework.
4+
35
#![feature(core_intrinsics, rustc_attrs, const_raw_ptr_deref)]
46

57
use std::cell::UnsafeCell;

0 commit comments

Comments
 (0)