Skip to content

Commit 10f46b6

Browse files
committed
Move the HIR cfg to rustc_ast_borrowck
No new code should be using it.
1 parent 1fb3c4e commit 10f46b6

File tree

10 files changed

+32
-43
lines changed

10 files changed

+32
-43
lines changed

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ pub mod query;
9797

9898
#[macro_use]
9999
pub mod arena;
100-
pub mod cfg;
101100
pub mod dep_graph;
102101
pub mod hir;
103102
pub mod ich;

src/librustc_ast_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use InteriorKind::*;
99

1010
use rustc::hir::HirId;
1111
use rustc::hir::Node;
12-
use rustc::cfg;
1312
use rustc::middle::borrowck::{BorrowCheckResult, SignalledError};
1413
use rustc::hir::def_id::{DefId, LocalDefId};
1514
use rustc::middle::mem_categorization as mc;
@@ -28,6 +27,7 @@ use log::debug;
2827

2928
use rustc::hir;
3029

30+
use crate::cfg;
3131
use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
3232

3333
pub mod check_loans;

src/librustc_ast_borrowck/borrowck/move_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::dataflow::{DataFlowContext, BitwiseOperator, DataFlowOperator, KillFrom};
55

66
use crate::borrowck::*;
7-
use rustc::cfg;
7+
use crate::cfg;
88
use rustc::ty::{self, TyCtxt};
99
use rustc::util::nodemap::FxHashMap;
1010

src/librustc/cfg/construct.rs src/librustc_ast_borrowck/cfg/construct.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::cfg::*;
2-
use crate::middle::region;
32
use rustc_data_structures::graph::implementation as graph;
4-
use crate::ty::{self, TyCtxt};
3+
use rustc::middle::region;
4+
use rustc::ty::{self, TyCtxt};
55

6-
use crate::hir::{self, PatKind};
7-
use crate::hir::def_id::DefId;
8-
use crate::hir::ptr::P;
6+
use rustc::hir::{self, PatKind};
7+
use rustc::hir::def_id::DefId;
8+
use rustc::hir::ptr::P;
99

1010
struct CFGBuilder<'a, 'tcx> {
1111
tcx: TyCtxt<'tcx>,
@@ -30,7 +30,7 @@ struct LoopScope {
3030
break_index: CFGIndex, // where to go on a `break`
3131
}
3232

33-
pub fn construct(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
33+
pub(super) fn construct(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
3434
let mut graph = graph::Graph::new();
3535
let entry = graph.add_node(CFGNodeData::Entry);
3636

src/librustc/cfg/graphviz.rs src/librustc_ast_borrowck/cfg/graphviz.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
/// This module provides linkage between rustc::middle::graph and
22
/// libgraphviz traits.
33
4-
// For clarity, rename the graphviz crate locally to dot.
5-
use graphviz as dot;
6-
74
use crate::cfg;
8-
use crate::hir;
9-
use crate::ty::TyCtxt;
5+
use rustc::hir;
6+
use rustc::ty::TyCtxt;
107

11-
pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
12-
pub type Edge<'a> = &'a cfg::CFGEdge;
8+
pub(crate) type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
9+
pub(crate) type Edge<'a> = &'a cfg::CFGEdge;
1310

1411
pub struct LabelledCFG<'a, 'tcx> {
1512
pub tcx: TyCtxt<'tcx>,

src/librustc/cfg/mod.rs src/librustc_ast_borrowck/cfg/mod.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
//! Uses `Graph` as the underlying representation.
33
44
use rustc_data_structures::graph::implementation as graph;
5-
use crate::ty::TyCtxt;
6-
use crate::hir;
7-
use crate::hir::def_id::DefId;
5+
use rustc::ty::TyCtxt;
6+
use rustc::hir;
7+
use rustc::hir::def_id::DefId;
88

99
mod construct;
1010
pub mod graphviz;
1111

1212
pub struct CFG {
13-
pub owner_def_id: DefId,
14-
pub graph: CFGGraph,
15-
pub entry: CFGIndex,
16-
pub exit: CFGIndex,
13+
owner_def_id: DefId,
14+
pub(crate) graph: CFGGraph,
15+
pub(crate) entry: CFGIndex,
16+
exit: CFGIndex,
1717
}
1818

1919
#[derive(Copy, Clone, Debug, PartialEq)]
@@ -26,7 +26,7 @@ pub enum CFGNodeData {
2626
}
2727

2828
impl CFGNodeData {
29-
pub fn id(&self) -> hir::ItemLocalId {
29+
pub(crate) fn id(&self) -> hir::ItemLocalId {
3030
if let CFGNodeData::AST(id) = *self {
3131
id
3232
} else {
@@ -37,24 +37,19 @@ impl CFGNodeData {
3737

3838
#[derive(Debug)]
3939
pub struct CFGEdgeData {
40-
pub exiting_scopes: Vec<hir::ItemLocalId>
40+
pub(crate) exiting_scopes: Vec<hir::ItemLocalId>
4141
}
4242

43-
pub type CFGIndex = graph::NodeIndex;
43+
pub(crate) type CFGIndex = graph::NodeIndex;
4444

45-
pub type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
45+
pub(crate) type CFGGraph = graph::Graph<CFGNodeData, CFGEdgeData>;
4646

47-
pub type CFGNode = graph::Node<CFGNodeData>;
47+
pub(crate) type CFGNode = graph::Node<CFGNodeData>;
4848

49-
pub type CFGEdge = graph::Edge<CFGEdgeData>;
49+
pub(crate) type CFGEdge = graph::Edge<CFGEdgeData>;
5050

5151
impl CFG {
5252
pub fn new(tcx: TyCtxt<'_>, body: &hir::Body) -> CFG {
5353
construct::construct(tcx, body)
5454
}
55-
56-
pub fn node_is_reachable(&self, id: hir::ItemLocalId) -> bool {
57-
self.graph.depth_traverse(self.entry, graph::OUTGOING)
58-
.any(|idx| self.graph.node_data(idx).id() == id)
59-
}
6055
}

src/librustc_ast_borrowck/dataflow.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
//! and thus uses bitvectors. Your job is simply to specify the so-called
44
//! GEN and KILL bits for each expression.
55
6-
use rustc::cfg;
7-
use rustc::cfg::CFGIndex;
8-
use rustc::ty::TyCtxt;
6+
use crate::cfg::{self, CFGIndex};
97
use std::mem;
108
use std::usize;
119
use log::debug;
@@ -16,6 +14,7 @@ use rustc::util::nodemap::FxHashMap;
1614
use rustc::hir;
1715
use rustc::hir::intravisit;
1816
use rustc::hir::print as pprust;
17+
use rustc::ty::TyCtxt;
1918

2019
#[derive(Copy, Clone, Debug)]
2120
pub enum EntryOrExit {

src/librustc_ast_borrowck/graphviz.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
55
pub use Variant::*;
66

7-
pub use rustc::cfg::graphviz::{Node, Edge};
8-
use rustc::cfg::graphviz as cfg_dot;
9-
7+
pub(crate) use crate::cfg::graphviz::{Node, Edge};
8+
use crate::cfg::graphviz as cfg_dot;
9+
use crate::cfg::CFGIndex;
1010
use crate::borrowck::{self, BorrowckCtxt, LoanPath};
1111
use crate::dataflow::{DataFlowOperator, DataFlowContext, EntryOrExit};
1212
use log::debug;
13-
use rustc::cfg::CFGIndex;
1413
use std::rc::Rc;
1514

1615
#[derive(Debug, Copy, Clone)]

src/librustc_ast_borrowck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ mod borrowck;
1818
pub mod graphviz;
1919

2020
mod dataflow;
21+
pub mod cfg;
2122

2223
pub use borrowck::provide;

src/librustc_driver/pretty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! The various pretty-printing routines.
22
3-
use rustc::cfg;
4-
use rustc::cfg::graphviz::LabelledCFG;
53
use rustc::hir;
64
use rustc::hir::map as hir_map;
75
use rustc::hir::map::blocks;
@@ -14,6 +12,7 @@ use rustc::util::common::ErrorReported;
1412
use rustc_interface::util::ReplaceBodyWithLoop;
1513
use rustc_ast_borrowck as borrowck;
1614
use rustc_ast_borrowck::graphviz as borrowck_dot;
15+
use rustc_ast_borrowck::cfg::{self, graphviz::LabelledCFG};
1716
use rustc_mir::util::{write_mir_pretty, write_mir_graphviz};
1817

1918
use syntax::ast;

0 commit comments

Comments
 (0)