Skip to content

Commit 1ec9917

Browse files
Add an into_engine method to Analysis
This makes it more ergonomic to create a dataflow engine and obviates the need to pick between `new_gen_kill` and `new_generic`.
1 parent e2b9d6e commit 1ec9917

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/librustc_mir/dataflow/generic/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
use std::io;
3636

3737
use rustc::mir::{self, BasicBlock, Location};
38+
use rustc::ty::TyCtxt;
39+
use rustc_hir::def_id::DefId;
3840
use rustc_index::bit_set::{BitSet, HybridBitSet};
3941
use rustc_index::vec::{Idx, IndexVec};
4042

@@ -166,6 +168,22 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
166168
args: &[mir::Operand<'tcx>],
167169
return_place: &mir::Place<'tcx>,
168170
);
171+
172+
/// Creates an `Engine` to find the fixpoint for this dataflow problem.
173+
///
174+
/// This is functionally equivalent to calling the appropriate `Engine` constructor. It should
175+
/// not be overridden. Its purpose is to allow consumers of this API to use method-chaining.
176+
fn into_engine(
177+
self,
178+
tcx: TyCtxt<'tcx>,
179+
body: &'mir mir::Body<'tcx>,
180+
def_id: DefId,
181+
) -> Engine<'mir, 'tcx, Self>
182+
where
183+
Self: Sized,
184+
{
185+
Engine::new_generic(tcx, body, def_id, self)
186+
}
169187
}
170188

171189
/// A gen/kill dataflow problem.
@@ -272,6 +290,18 @@ where
272290
) {
273291
self.call_return_effect(state, block, func, args, return_place);
274292
}
293+
294+
fn into_engine(
295+
self,
296+
tcx: TyCtxt<'tcx>,
297+
body: &'mir mir::Body<'tcx>,
298+
def_id: DefId,
299+
) -> Engine<'mir, 'tcx, Self>
300+
where
301+
Self: Sized,
302+
{
303+
Engine::new_gen_kill(tcx, body, def_id, self)
304+
}
275305
}
276306

277307
/// The legal operations for a transfer function in a gen/kill problem.

src/librustc_mir/transform/check_consts/validation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use super::resolver::FlowSensitiveAnalysis;
2222
use super::{is_lang_panic_fn, ConstKind, Item, Qualif};
2323
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
2424
use crate::dataflow::{self as old_dataflow, generic as dataflow};
25+
use dataflow::Analysis;
2526

2627
pub type IndirectlyMutableResults<'mir, 'tcx> =
2728
old_dataflow::DataflowResultsCursor<'mir, 'tcx, IndirectlyMutableLocals<'mir, 'tcx>>;
@@ -33,10 +34,10 @@ struct QualifCursor<'a, 'mir, 'tcx, Q: Qualif> {
3334

3435
impl<Q: Qualif> QualifCursor<'a, 'mir, 'tcx, Q> {
3536
pub fn new(q: Q, item: &'a Item<'mir, 'tcx>) -> Self {
36-
let analysis = FlowSensitiveAnalysis::new(q, item);
37-
let results = dataflow::Engine::new_generic(item.tcx, &item.body, item.def_id, analysis)
38-
.iterate_to_fixpoint();
39-
let cursor = dataflow::ResultsCursor::new(*item.body, results);
37+
let cursor = FlowSensitiveAnalysis::new(q, item)
38+
.into_engine(item.tcx, &item.body, item.def_id)
39+
.iterate_to_fixpoint()
40+
.into_results_cursor(*item.body);
4041

4142
let mut in_any_value_of_ty = BitSet::new_empty(item.body.local_decls.len());
4243
for (local, decl) in item.body.local_decls.iter_enumerated() {

0 commit comments

Comments
 (0)