about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Jasper <mjjasper1@gmail.com>2019-09-06 18:02:12 +0100
committerMatthew Jasper <mjjasper1@gmail.com>2019-09-06 18:02:12 +0100
commit10f46b69bc32bd1cb5f013ce904957aeb28603bb (patch)
tree7d3fffcc8a4e86ad0fa2325edd656dc0083fbaf2
parent1fb3c4ec7ca37d33bd1e68cce669d171c2752615 (diff)
downloadrust-10f46b69bc32bd1cb5f013ce904957aeb28603bb.tar.gz
rust-10f46b69bc32bd1cb5f013ce904957aeb28603bb.zip
Move the HIR cfg to `rustc_ast_borrowck`
No new code should be using it.
-rw-r--r--src/librustc/lib.rs1
-rw-r--r--src/librustc_ast_borrowck/borrowck/mod.rs2
-rw-r--r--src/librustc_ast_borrowck/borrowck/move_data.rs2
-rw-r--r--src/librustc_ast_borrowck/cfg/construct.rs (renamed from src/librustc/cfg/construct.rs)12
-rw-r--r--src/librustc_ast_borrowck/cfg/graphviz.rs (renamed from src/librustc/cfg/graphviz.rs)11
-rw-r--r--src/librustc_ast_borrowck/cfg/mod.rs (renamed from src/librustc/cfg/mod.rs)31
-rw-r--r--src/librustc_ast_borrowck/dataflow.rs5
-rw-r--r--src/librustc_ast_borrowck/graphviz.rs7
-rw-r--r--src/librustc_ast_borrowck/lib.rs1
-rw-r--r--src/librustc_driver/pretty.rs3
10 files changed, 32 insertions, 43 deletions
diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs
index 368f5bb64fe..bf4330a29a7 100644
--- a/src/librustc/lib.rs
+++ b/src/librustc/lib.rs
@@ -97,7 +97,6 @@ pub mod query;
 
 #[macro_use]
 pub mod arena;
-pub mod cfg;
 pub mod dep_graph;
 pub mod hir;
 pub mod ich;
diff --git a/src/librustc_ast_borrowck/borrowck/mod.rs b/src/librustc_ast_borrowck/borrowck/mod.rs
index 3bbd7ae5c35..23d5480c605 100644
--- a/src/librustc_ast_borrowck/borrowck/mod.rs
+++ b/src/librustc_ast_borrowck/borrowck/mod.rs
@@ -9,7 +9,6 @@ use InteriorKind::*;
 
 use rustc::hir::HirId;
 use rustc::hir::Node;
-use rustc::cfg;
 use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
 use rustc::hir::def_id::{DefId, LocalDefId};
 use rustc::middle::mem_categorization as mc;
@@ -28,6 +27,7 @@ use log::debug;
 
 use rustc::hir;
 
+use crate::cfg;
 use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
 
 pub mod check_loans;
diff --git a/src/librustc_ast_borrowck/borrowck/move_data.rs b/src/librustc_ast_borrowck/borrowck/move_data.rs
index 887a0e2f20e..67d818161b1 100644
--- a/src/librustc_ast_borrowck/borrowck/move_data.rs
+++ b/src/librustc_ast_borrowck/borrowck/move_data.rs
@@ -4,7 +4,7 @@
 use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
 
 use crate::borrowck::*;
-use rustc::cfg;
+use crate::cfg;
 use rustc::ty::{self, TyCtxt};
 use rustc::util::nodemap::FxHashMap;
 
diff --git a/src/librustc/cfg/construct.rs b/src/librustc_ast_borrowck/cfg/construct.rs
index 0dad2dda837..339d92145c6 100644
--- a/src/librustc/cfg/construct.rs
+++ b/src/librustc_ast_borrowck/cfg/construct.rs
@@ -1,11 +1,11 @@
 use crate::cfg::*;
-use crate::middle::region;
 use rustc_data_structures::graph::implementation as graph;
-use crate::ty::{self, TyCtxt};
+use rustc::middle::region;
+use rustc::ty::{self, TyCtxt};
 
-use crate::hir::{self, PatKind};
-use crate::hir::def_id::DefId;
-use crate::hir::ptr::P;
+use rustc::hir::{self, PatKind};
+use rustc::hir::def_id::DefId;
+use rustc::hir::ptr::P;
 
 struct CFGBuilder<'a, 'tcx> {
     tcx: TyCtxt<'tcx>,
@@ -30,7 +30,7 @@ struct LoopScope {
     break_index: CFGIndex,    // where to go on a `break`
 }
 
-pub fn construct(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
+pub(super) fn construct(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
     let mut graph = graph::Graph::new();
     let entry = graph.add_node(CFGNodeData::Entry);
 
diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc_ast_borrowck/cfg/graphviz.rs
index 918120057d4..46409f1a1ce 100644
--- a/src/librustc/cfg/graphviz.rs
+++ b/src/librustc_ast_borrowck/cfg/graphviz.rs
@@ -1,15 +1,12 @@
 /// This module provides linkage between rustc::middle::graph and
 /// libgraphviz traits.
 
-// For clarity, rename the graphviz crate locally to dot.
-use graphviz as dot;
-
 use crate::cfg;
-use crate::hir;
-use crate::ty::TyCtxt;
+use rustc::hir;
+use rustc::ty::TyCtxt;
 
-pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
-pub type Edge<'a> = &'a cfg::CFGEdge;
+pub(crate) type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
+pub(crate) type Edge<'a> = &'a cfg::CFGEdge;
 
 pub struct LabelledCFG<'a, 'tcx> {
     pub tcx: TyCtxt<'tcx>,
diff --git a/src/librustc/cfg/mod.rs b/src/librustc_ast_borrowck/cfg/mod.rs
index 88fc7fbfad5..981199c91d5 100644
--- a/src/librustc/cfg/mod.rs
+++ b/src/librustc_ast_borrowck/cfg/mod.rs
@@ -2,18 +2,18 @@
 //! Uses `Graph` as the underlying representation.
 
 use rustc_data_structures::graph::implementation as graph;
-use crate::ty::TyCtxt;
-use crate::hir;
-use crate::hir::def_id::DefId;
+use rustc::ty::TyCtxt;
+use rustc::hir;
+use rustc::hir::def_id::DefId;
 
 mod construct;
 pub mod graphviz;
 
 pub struct CFG {
-    pub owner_def_id: DefId,
-    pub graph: CFGGraph,
-    pub entry: CFGIndex,
-    pub exit: CFGIndex,
+    owner_def_id: DefId,
+    pub(crate) graph: CFGGraph,
+    pub(crate) entry: CFGIndex,
+    exit: CFGIndex,
 }
 
 #[derive(Copy, Clone, Debug, PartialEq)]
@@ -26,7 +26,7 @@ pub enum CFGNodeData {
 }
 
 impl CFGNodeData {
-    pub fn id(&self) -> hir::ItemLocalId {
+    pub(crate) fn id(&self) -> hir::ItemLocalId {
         if let CFGNodeData::AST(id) = *self {
             id
         } else {
@@ -37,24 +37,19 @@ impl CFGNodeData {
 
 #[derive(Debug)]
 pub struct CFGEdgeData {
-    pub exiting_scopes: Vec<hir::ItemLocalId>
+    pub(crate) exiting_scopes: Vec<hir::ItemLocalId>
 }
 
-pub type CFGIndex = graph::NodeIndex;
+pub(crate) type CFGIndex = graph::NodeIndex;
 
-pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
+pub(crate) type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
 
-pub type CFGNode = graph::Node<CFGNodeData>;
+pub(crate) type CFGNode = graph::Node<CFGNodeData>;
 
-pub type CFGEdge = graph::Edge<CFGEdgeData>;
+pub(crate) type CFGEdge = graph::Edge<CFGEdgeData>;
 
 impl CFG {
     pub fn new(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
         construct::construct(tcx, body)
     }
-
-    pub fn node_is_reachable(&self, id: hir::ItemLocalId) -> bool {
-        self.graph.depth_traverse(self.entry, graph::OUTGOING)
-                  .any(|idx| self.graph.node_data(idx).id() == id)
-    }
 }
diff --git a/src/librustc_ast_borrowck/dataflow.rs b/src/librustc_ast_borrowck/dataflow.rs
index 3a4c8c92476..a8562901d99 100644
--- a/src/librustc_ast_borrowck/dataflow.rs
+++ b/src/librustc_ast_borrowck/dataflow.rs
@@ -3,9 +3,7 @@
 //! and thus uses bitvectors. Your job is simply to specify the so-called
 //! GEN and KILL bits for each expression.
 
-use rustc::cfg;
-use rustc::cfg::CFGIndex;
-use rustc::ty::TyCtxt;
+use crate::cfg::{self, CFGIndex};
 use std::mem;
 use std::usize;
 use log::debug;
@@ -16,6 +14,7 @@ use rustc::util::nodemap::FxHashMap;
 use rustc::hir;
 use rustc::hir::intravisit;
 use rustc::hir::print as pprust;
+use rustc::ty::TyCtxt;
 
 #[derive(Copy, Clone, Debug)]
 pub enum EntryOrExit {
diff --git a/src/librustc_ast_borrowck/graphviz.rs b/src/librustc_ast_borrowck/graphviz.rs
index 7a8a23ca76a..c077dc828ab 100644
--- a/src/librustc_ast_borrowck/graphviz.rs
+++ b/src/librustc_ast_borrowck/graphviz.rs
@@ -4,13 +4,12 @@
 
 pub use Variant::*;
 
-pub use rustc::cfg::graphviz::{Node, Edge};
-use rustc::cfg::graphviz as cfg_dot;
-
+pub(crate) use crate::cfg::graphviz::{Node, Edge};
+use crate::cfg::graphviz as cfg_dot;
+use crate::cfg::CFGIndex;
 use crate::borrowck::{self, BorrowckCtxt, LoanPath};
 use crate::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
 use log::debug;
-use rustc::cfg::CFGIndex;
 use std::rc::Rc;
 
 #[derive(Debug, Copy, Clone)]
diff --git a/src/librustc_ast_borrowck/lib.rs b/src/librustc_ast_borrowck/lib.rs
index dc818278a4b..aea97fea1a9 100644
--- a/src/librustc_ast_borrowck/lib.rs
+++ b/src/librustc_ast_borrowck/lib.rs
@@ -18,5 +18,6 @@ mod borrowck;
 pub mod graphviz;
 
 mod dataflow;
+pub mod cfg;
 
 pub use borrowck::provide;
diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs
index cb17401f624..c4d3ad946f9 100644
--- a/src/librustc_driver/pretty.rs
+++ b/src/librustc_driver/pretty.rs
@@ -1,7 +1,5 @@
 //! The various pretty-printing routines.
 
-use rustc::cfg;
-use rustc::cfg::graphviz::LabelledCFG;
 use rustc::hir;
 use rustc::hir::map as hir_map;
 use rustc::hir::map::blocks;
@@ -14,6 +12,7 @@ use rustc::util::common::ErrorReported;
 use rustc_interface::util::ReplaceBodyWithLoop;
 use rustc_ast_borrowck as borrowck;
 use rustc_ast_borrowck::graphviz as borrowck_dot;
+use rustc_ast_borrowck::cfg::{self, graphviz::LabelledCFG};
 use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
 
 use syntax::ast;