Skip to content

Commit 4f23572

Browse files
committed
Reimplement standard ConstProp using DataflowConstProp.
1 parent ffc48e3 commit 4f23572

File tree

67 files changed

+245
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+245
-697
lines changed

compiler/rustc_mir_dataflow/src/value_analysis.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,13 @@ impl Map {
638638
///
639639
/// This is currently the only way to create a [`Map`]. The way in which the tracked places are
640640
/// chosen is an implementation detail and may not be relied upon (other than that their type
641-
/// are scalars).
642-
pub fn new<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, value_limit: Option<usize>) -> Self {
641+
/// are scalars and pass the filter).
642+
pub fn from_filter<'tcx>(
643+
tcx: TyCtxt<'tcx>,
644+
body: &Body<'tcx>,
645+
filter: impl Fn(Local) -> bool,
646+
value_limit: Option<usize>,
647+
) -> Self {
643648
let mut map = Self {
644649
locals: IndexVec::new(),
645650
projections: FxHashMap::default(),
@@ -648,8 +653,7 @@ impl Map {
648653
inner_values: IndexVec::new(),
649654
inner_values_buffer: Vec::new(),
650655
};
651-
let exclude = excluded_locals(body);
652-
map.register(tcx, body, exclude, value_limit);
656+
map.register(tcx, body, filter, value_limit);
653657
debug!("registered {} places ({} nodes in total)", map.value_count, map.places.len());
654658
map
655659
}
@@ -659,7 +663,7 @@ impl Map {
659663
&mut self,
660664
tcx: TyCtxt<'tcx>,
661665
body: &Body<'tcx>,
662-
exclude: BitSet<Local>,
666+
filter: impl Fn(Local) -> bool,
663667
value_limit: Option<usize>,
664668
) {
665669
let mut worklist = VecDeque::with_capacity(value_limit.unwrap_or(body.local_decls.len()));
@@ -668,7 +672,7 @@ impl Map {
668672
// Start by constructing the places for each bare local.
669673
self.locals = IndexVec::from_elem(None, &body.local_decls);
670674
for (local, decl) in body.local_decls.iter_enumerated() {
671-
if exclude.contains(local) {
675+
if !filter(local) {
672676
continue;
673677
}
674678

0 commit comments

Comments
 (0)