Skip to content

Commit 1ff3641

Browse files
committed
rustc: don't call the HIR AST.
1 parent 45c8c56 commit 1ff3641

File tree

22 files changed

+345
-363
lines changed

22 files changed

+345
-363
lines changed

src/librustc/cfg/graphviz.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ use graphviz::IntoCow;
1717

1818
use syntax::ast;
1919

20-
use hir::map as ast_map;
20+
use hir::map as hir_map;
2121
use cfg;
2222

2323
pub type Node<'a> = (cfg::CFGIndex, &'a cfg::CFGNode);
2424
pub type Edge<'a> = &'a cfg::CFGEdge;
2525

26-
pub struct LabelledCFG<'a, 'ast: 'a> {
27-
pub ast_map: &'a ast_map::Map<'ast>,
26+
pub struct LabelledCFG<'a, 'hir: 'a> {
27+
pub hir_map: &'a hir_map::Map<'hir>,
2828
pub cfg: &'a cfg::CFG,
2929
pub name: String,
3030
/// `labelled_edges` controls whether we emit labels on the edges
@@ -52,7 +52,7 @@ fn replace_newline_with_backslash_l(s: String) -> String {
5252
}
5353
}
5454

55-
impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> {
55+
impl<'a, 'hir> dot::Labeller<'a> for LabelledCFG<'a, 'hir> {
5656
type Node = Node<'a>;
5757
type Edge = Edge<'a>;
5858
fn graph_id(&'a self) -> dot::Id<'a> { dot::Id::new(&self.name[..]).unwrap() }
@@ -69,7 +69,7 @@ impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> {
6969
} else if n.data.id() == ast::DUMMY_NODE_ID {
7070
dot::LabelText::LabelStr("(dummy_node)".into_cow())
7171
} else {
72-
let s = self.ast_map.node_to_string(n.data.id());
72+
let s = self.hir_map.node_to_string(n.data.id());
7373
// left-aligns the lines
7474
let s = replace_newline_with_backslash_l(s);
7575
dot::LabelText::EscStr(s.into_cow())
@@ -88,7 +88,7 @@ impl<'a, 'ast> dot::Labeller<'a> for LabelledCFG<'a, 'ast> {
8888
} else {
8989
put_one = true;
9090
}
91-
let s = self.ast_map.node_to_string(node_id);
91+
let s = self.hir_map.node_to_string(node_id);
9292
// left-aligns the lines
9393
let s = replace_newline_with_backslash_l(s);
9494
label.push_str(&format!("exiting scope_{} {}",
@@ -120,7 +120,7 @@ impl<'a> dot::GraphWalk<'a> for &'a cfg::CFG {
120120
}
121121
}
122122

123-
impl<'a, 'ast> dot::GraphWalk<'a> for LabelledCFG<'a, 'ast>
123+
impl<'a, 'hir> dot::GraphWalk<'a> for LabelledCFG<'a, 'hir>
124124
{
125125
type Node = Node<'a>;
126126
type Edge = Edge<'a>;

src/librustc/hir/intravisit.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1085,13 +1085,13 @@ impl IdRange {
10851085
}
10861086

10871087

1088-
pub struct IdRangeComputingVisitor<'a, 'ast: 'a> {
1088+
pub struct IdRangeComputingVisitor<'a, 'hir: 'a> {
10891089
result: IdRange,
1090-
map: &'a map::Map<'ast>,
1090+
map: &'a map::Map<'hir>,
10911091
}
10921092

1093-
impl<'a, 'ast> IdRangeComputingVisitor<'a, 'ast> {
1094-
pub fn new(map: &'a map::Map<'ast>) -> IdRangeComputingVisitor<'a, 'ast> {
1093+
impl<'a, 'hir> IdRangeComputingVisitor<'a, 'hir> {
1094+
pub fn new(map: &'a map::Map<'hir>) -> IdRangeComputingVisitor<'a, 'hir> {
10951095
IdRangeComputingVisitor { result: IdRange::max(), map: map }
10961096
}
10971097

@@ -1100,8 +1100,8 @@ impl<'a, 'ast> IdRangeComputingVisitor<'a, 'ast> {
11001100
}
11011101
}
11021102

1103-
impl<'a, 'ast> Visitor<'ast> for IdRangeComputingVisitor<'a, 'ast> {
1104-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
1103+
impl<'a, 'hir> Visitor<'hir> for IdRangeComputingVisitor<'a, 'hir> {
1104+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
11051105
NestedVisitorMap::OnlyBodies(&self.map)
11061106
}
11071107

src/librustc/hir/map/collector.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ use syntax::ast::{NodeId, CRATE_NODE_ID};
1616
use syntax_pos::Span;
1717

1818
/// A Visitor that walks over the HIR and collects Nodes into a HIR map
19-
pub struct NodeCollector<'ast> {
19+
pub struct NodeCollector<'hir> {
2020
/// The crate
21-
pub krate: &'ast Crate,
21+
pub krate: &'hir Crate,
2222
/// The node map
23-
pub(super) map: Vec<MapEntry<'ast>>,
23+
pub(super) map: Vec<MapEntry<'hir>>,
2424
/// The parent of this node
2525
pub parent_node: NodeId,
2626
}
2727

28-
impl<'ast> NodeCollector<'ast> {
29-
pub fn root(krate: &'ast Crate) -> NodeCollector<'ast> {
28+
impl<'hir> NodeCollector<'hir> {
29+
pub fn root(krate: &'hir Crate) -> NodeCollector<'hir> {
3030
let mut collector = NodeCollector {
3131
krate: krate,
3232
map: vec![],
@@ -37,16 +37,16 @@ impl<'ast> NodeCollector<'ast> {
3737
collector
3838
}
3939

40-
fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'ast>) {
41-
debug!("ast_map: {:?} => {:?}", id, entry);
40+
fn insert_entry(&mut self, id: NodeId, entry: MapEntry<'hir>) {
41+
debug!("hir_map: {:?} => {:?}", id, entry);
4242
let len = self.map.len();
4343
if id.as_usize() >= len {
4444
self.map.extend(repeat(NotPresent).take(id.as_usize() - len + 1));
4545
}
4646
self.map[id.as_usize()] = entry;
4747
}
4848

49-
fn insert(&mut self, id: NodeId, node: Node<'ast>) {
49+
fn insert(&mut self, id: NodeId, node: Node<'hir>) {
5050
let entry = MapEntry::from_node(self.parent_node, node);
5151
self.insert_entry(id, entry);
5252
}
@@ -59,12 +59,12 @@ impl<'ast> NodeCollector<'ast> {
5959
}
6060
}
6161

62-
impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
62+
impl<'hir> Visitor<'hir> for NodeCollector<'hir> {
6363
/// Because we want to track parent items and so forth, enable
6464
/// deep walking so that we walk nested items in the context of
6565
/// their outer items.
6666
67-
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'ast> {
67+
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
6868
panic!("visit_nested_xxx must be manually implemented in this visitor")
6969
}
7070

@@ -85,7 +85,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
8585
self.visit_body(self.krate.body(id));
8686
}
8787

88-
fn visit_item(&mut self, i: &'ast Item) {
88+
fn visit_item(&mut self, i: &'hir Item) {
8989
debug!("visit_item: {:?}", i);
9090

9191
self.insert(i.id, NodeItem(i));
@@ -104,39 +104,39 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
104104
});
105105
}
106106

107-
fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
107+
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
108108
self.insert(foreign_item.id, NodeForeignItem(foreign_item));
109109

110110
self.with_parent(foreign_item.id, |this| {
111111
intravisit::walk_foreign_item(this, foreign_item);
112112
});
113113
}
114114

115-
fn visit_generics(&mut self, generics: &'ast Generics) {
115+
fn visit_generics(&mut self, generics: &'hir Generics) {
116116
for ty_param in generics.ty_params.iter() {
117117
self.insert(ty_param.id, NodeTyParam(ty_param));
118118
}
119119

120120
intravisit::walk_generics(self, generics);
121121
}
122122

123-
fn visit_trait_item(&mut self, ti: &'ast TraitItem) {
123+
fn visit_trait_item(&mut self, ti: &'hir TraitItem) {
124124
self.insert(ti.id, NodeTraitItem(ti));
125125

126126
self.with_parent(ti.id, |this| {
127127
intravisit::walk_trait_item(this, ti);
128128
});
129129
}
130130

131-
fn visit_impl_item(&mut self, ii: &'ast ImplItem) {
131+
fn visit_impl_item(&mut self, ii: &'hir ImplItem) {
132132
self.insert(ii.id, NodeImplItem(ii));
133133

134134
self.with_parent(ii.id, |this| {
135135
intravisit::walk_impl_item(this, ii);
136136
});
137137
}
138138

139-
fn visit_pat(&mut self, pat: &'ast Pat) {
139+
fn visit_pat(&mut self, pat: &'hir Pat) {
140140
let node = if let PatKind::Binding(..) = pat.node {
141141
NodeLocal(pat)
142142
} else {
@@ -149,15 +149,15 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
149149
});
150150
}
151151

152-
fn visit_expr(&mut self, expr: &'ast Expr) {
152+
fn visit_expr(&mut self, expr: &'hir Expr) {
153153
self.insert(expr.id, NodeExpr(expr));
154154

155155
self.with_parent(expr.id, |this| {
156156
intravisit::walk_expr(this, expr);
157157
});
158158
}
159159

160-
fn visit_stmt(&mut self, stmt: &'ast Stmt) {
160+
fn visit_stmt(&mut self, stmt: &'hir Stmt) {
161161
let id = stmt.node.id();
162162
self.insert(id, NodeStmt(stmt));
163163

@@ -166,40 +166,40 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
166166
});
167167
}
168168

169-
fn visit_ty(&mut self, ty: &'ast Ty) {
169+
fn visit_ty(&mut self, ty: &'hir Ty) {
170170
self.insert(ty.id, NodeTy(ty));
171171

172172
self.with_parent(ty.id, |this| {
173173
intravisit::walk_ty(this, ty);
174174
});
175175
}
176176

177-
fn visit_trait_ref(&mut self, tr: &'ast TraitRef) {
177+
fn visit_trait_ref(&mut self, tr: &'hir TraitRef) {
178178
self.insert(tr.ref_id, NodeTraitRef(tr));
179179

180180
self.with_parent(tr.ref_id, |this| {
181181
intravisit::walk_trait_ref(this, tr);
182182
});
183183
}
184184

185-
fn visit_fn(&mut self, fk: intravisit::FnKind<'ast>, fd: &'ast FnDecl,
185+
fn visit_fn(&mut self, fk: intravisit::FnKind<'hir>, fd: &'hir FnDecl,
186186
b: BodyId, s: Span, id: NodeId) {
187187
assert_eq!(self.parent_node, id);
188188
intravisit::walk_fn(self, fk, fd, b, s, id);
189189
}
190190

191-
fn visit_block(&mut self, block: &'ast Block) {
191+
fn visit_block(&mut self, block: &'hir Block) {
192192
self.insert(block.id, NodeBlock(block));
193193
self.with_parent(block.id, |this| {
194194
intravisit::walk_block(this, block);
195195
});
196196
}
197197

198-
fn visit_lifetime(&mut self, lifetime: &'ast Lifetime) {
198+
fn visit_lifetime(&mut self, lifetime: &'hir Lifetime) {
199199
self.insert(lifetime.id, NodeLifetime(lifetime));
200200
}
201201

202-
fn visit_vis(&mut self, visibility: &'ast Visibility) {
202+
fn visit_vis(&mut self, visibility: &'hir Visibility) {
203203
match *visibility {
204204
Visibility::Public |
205205
Visibility::Crate |
@@ -213,19 +213,19 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
213213
}
214214
}
215215

216-
fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
216+
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
217217
self.insert_entry(macro_def.id, NotPresent);
218218
}
219219

220-
fn visit_variant(&mut self, v: &'ast Variant, g: &'ast Generics, item_id: NodeId) {
220+
fn visit_variant(&mut self, v: &'hir Variant, g: &'hir Generics, item_id: NodeId) {
221221
let id = v.node.data.id();
222222
self.insert(id, NodeVariant(v));
223223
self.with_parent(id, |this| {
224224
intravisit::walk_variant(this, v, g, item_id);
225225
});
226226
}
227227

228-
fn visit_struct_field(&mut self, field: &'ast StructField) {
228+
fn visit_struct_field(&mut self, field: &'hir StructField) {
229229
self.insert(field.id, NodeField(field));
230230
self.with_parent(field.id, |this| {
231231
intravisit::walk_struct_field(this, field);

0 commit comments

Comments
 (0)