about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2017-07-04 12:38:48 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2017-08-16 15:53:27 +0200
commite8ebc902e8973700002bd0e9e7e366f3244be948 (patch)
treedcbe9de4674cb24b5851a0cb0f1df4fa63f8f957 /src
parent9f6ef669d607928078ab931120386c22bdb907bc (diff)
Migrated some code out of `dataflow::drop_flag_effects` and into its parent module.
(This code is more general purpose than just supporting drop flag elaboration.)
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/dataflow/drop_flag_effects.rs72
-rw-r--r--src/librustc_mir/dataflow/mod.rs73
2 files changed, 71 insertions, 74 deletions
diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs
index a7894f02499..bd41bce67da 100644
--- a/src/librustc_mir/dataflow/drop_flag_effects.rs
+++ b/src/librustc_mir/dataflow/drop_flag_effects.rs
@@ -8,84 +8,16 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use syntax::ast::{self, MetaItem};
 use syntax_pos::DUMMY_SP;
 
-
-use rustc::mir::{self, Mir, BasicBlock, Location};
-use rustc::session::Session;
+use rustc::mir::{self, Mir, Location};
 use rustc::ty::{self, TyCtxt};
 use util::elaborate_drops::DropFlagState;
-use rustc_data_structures::indexed_set::{IdxSet};
-
-use std::fmt;
 
-use super::{Dataflow, DataflowBuilder, DataflowAnalysis};
-use super::{BitDenotation, DataflowOperator, DataflowResults};
+use super::{MoveDataParamEnv};
 use super::indexes::MovePathIndex;
 use super::move_paths::{MoveData, LookupResult};
 
-pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
-    for attr in attrs {
-        if attr.check_name("rustc_mir") {
-            let items = attr.meta_item_list();
-            for item in items.iter().flat_map(|l| l.iter()) {
-                match item.meta_item() {
-                    Some(mi) if mi.check_name(name) => return Some(mi.clone()),
-                    _ => continue
-                }
-            }
-        }
-    }
-    return None;
-}
-
-pub struct MoveDataParamEnv<'tcx> {
-    pub(crate) move_data: MoveData<'tcx>,
-    pub(crate) param_env: ty::ParamEnv<'tcx>,
-}
-
-pub(crate) fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
-                                mir: &Mir<'tcx>,
-                                node_id: ast::NodeId,
-                                attributes: &[ast::Attribute],
-                                dead_unwinds: &IdxSet<BasicBlock>,
-                                bd: BD,
-                                p: P)
-                                -> DataflowResults<BD>
-    where BD: BitDenotation<Idx=MovePathIndex> + DataflowOperator,
-          P: Fn(&BD, BD::Idx) -> &fmt::Debug
-{
-    let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
-        if let Some(item) = has_rustc_mir_with(attrs, name) {
-            if let Some(s) = item.value_str() {
-                return Some(s.to_string())
-            } else {
-                sess.span_err(
-                    item.span,
-                    &format!("{} attribute requires a path", item.name()));
-                return None;
-            }
-        }
-        return None;
-    };
-
-    let print_preflow_to =
-        name_found(tcx.sess, attributes, "borrowck_graphviz_preflow");
-    let print_postflow_to =
-        name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");
-
-    let mut mbcx = DataflowBuilder {
-        node_id,
-        print_preflow_to,
-        print_postflow_to,
-        flow_state: DataflowAnalysis::new(tcx, mir, dead_unwinds, bd),
-    };
-
-    mbcx.dataflow(p);
-    mbcx.flow_state.results()
-}
-
 pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
                                         path: MovePathIndex,
                                         mut cond: F)
diff --git a/src/librustc_mir/dataflow/mod.rs b/src/librustc_mir/dataflow/mod.rs
index 6e44a36aa01..eb040284cfa 100644
--- a/src/librustc_mir/dataflow/mod.rs
+++ b/src/librustc_mir/dataflow/mod.rs
@@ -8,16 +8,17 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use syntax::ast;
+use syntax::ast::{self, MetaItem};
 
 use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf};
 use rustc_data_structures::indexed_vec::Idx;
 use rustc_data_structures::bitslice::{bitwise, BitwiseOperator};
 
-use rustc::ty::{TyCtxt};
-use rustc::mir::{self, Mir, Location};
+use rustc::ty::{self, TyCtxt};
+use rustc::mir::{self, Mir, BasicBlock, Location};
+use rustc::session::Session;
 
-use std::fmt::Debug;
+use std::fmt::{self, Debug};
 use std::io;
 use std::mem;
 use std::path::PathBuf;
@@ -28,6 +29,9 @@ pub use self::impls::{DefinitelyInitializedLvals, MovingOutStatements};
 pub use self::impls::borrows::{Borrows, BorrowData, BorrowIndex};
 pub(crate) use self::drop_flag_effects::*;
 
+use self::move_paths::MoveData;
+use self::indexes::MovePathIndex;
+
 mod drop_flag_effects;
 mod graphviz;
 mod impls;
@@ -58,6 +62,67 @@ impl<'a, 'tcx: 'a, BD> Dataflow<BD> for DataflowBuilder<'a, 'tcx, BD>
     }
 }
 
+pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<MetaItem> {
+    for attr in attrs {
+        if attr.check_name("rustc_mir") {
+            let items = attr.meta_item_list();
+            for item in items.iter().flat_map(|l| l.iter()) {
+                match item.meta_item() {
+                    Some(mi) if mi.check_name(name) => return Some(mi.clone()),
+                    _ => continue
+                }
+            }
+        }
+    }
+    return None;
+}
+
+pub struct MoveDataParamEnv<'tcx> {
+    pub(crate) move_data: MoveData<'tcx>,
+    pub(crate) param_env: ty::ParamEnv<'tcx>,
+}
+
+pub(crate) fn do_dataflow<'a, 'tcx, BD, P>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                                mir: &Mir<'tcx>,
+                                node_id: ast::NodeId,
+                                attributes: &[ast::Attribute],
+                                dead_unwinds: &IdxSet<BasicBlock>,
+                                bd: BD,
+                                p: P)
+                                -> DataflowResults<BD>
+    where BD: BitDenotation<Idx=MovePathIndex> + DataflowOperator,
+          P: Fn(&BD, BD::Idx) -> &fmt::Debug
+{
+    let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
+        if let Some(item) = has_rustc_mir_with(attrs, name) {
+            if let Some(s) = item.value_str() {
+                return Some(s.to_string())
+            } else {
+                sess.span_err(
+                    item.span,
+                    &format!("{} attribute requires a path", item.name()));
+                return None;
+            }
+        }
+        return None;
+    };
+
+    let print_preflow_to =
+        name_found(tcx.sess, attributes, "borrowck_graphviz_preflow");
+    let print_postflow_to =
+        name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");
+
+    let mut mbcx = DataflowBuilder {
+        node_id,
+        print_preflow_to,
+        print_postflow_to,
+        flow_state: DataflowAnalysis::new(tcx, mir, dead_unwinds, bd),
+    };
+
+    mbcx.dataflow(p);
+    mbcx.flow_state.results()
+}
+
 struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O>
     where O: 'b + BitDenotation
 {