提交 c0388cd6 编写于 作者: A Alex Crichton

Rewrite lint passes with less visitor cruft

This purges about 500 lines of visitor cruft from lint passes. All lints are
handled in a much more sane way at this point. The other huge bonus of this
commit is that there are no more @-boxes in the lint passes, fixing the 500MB
memory regression seen when the lint passes were refactored.

Closes #8589
上级 ccd9a963
...@@ -880,13 +880,13 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext, ...@@ -880,13 +880,13 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
// Because the ast visitor uses @IdVisitingOperation, I can't pass in // Because the ast visitor uses @IdVisitingOperation, I can't pass in
// ecx directly, but /I/ know that it'll be fine since the lifetime is // ecx directly, but /I/ know that it'll be fine since the lifetime is
// tied to the CrateContext that lives throughout this entire section. // tied to the CrateContext that lives throughout this entire section.
ast_util::visit_ids_for_inlined_item(ii, @SideTableEncodingIdVisitor { ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor {
ecx_ptr: unsafe { ecx_ptr: unsafe {
cast::transmute(ecx) cast::transmute(ecx)
}, },
new_ebml_w: new_ebml_w, new_ebml_w: new_ebml_w,
maps: maps, maps: maps,
} as @ast_util::IdVisitingOperation); });
ebml_w.end_tag(); ebml_w.end_tag();
} }
......
此差异已折叠。
...@@ -397,27 +397,17 @@ pub fn add(&mut self, id: NodeId) { ...@@ -397,27 +397,17 @@ pub fn add(&mut self, id: NodeId) {
} }
} }
pub fn id_visitor(operation: @IdVisitingOperation, pass_through_items: bool)
-> @mut Visitor<()> {
let visitor = @mut IdVisitor {
operation: operation,
pass_through_items: pass_through_items,
visited_outermost: false,
};
visitor as @mut Visitor<()>
}
pub trait IdVisitingOperation { pub trait IdVisitingOperation {
fn visit_id(&self, node_id: NodeId); fn visit_id(&self, node_id: NodeId);
} }
pub struct IdVisitor { pub struct IdVisitor<'self, O> {
operation: @IdVisitingOperation, operation: &'self O,
pass_through_items: bool, pass_through_items: bool,
visited_outermost: bool, visited_outermost: bool,
} }
impl IdVisitor { impl<'self, O: IdVisitingOperation> IdVisitor<'self, O> {
fn visit_generics_helper(&self, generics: &Generics) { fn visit_generics_helper(&self, generics: &Generics) {
for type_parameter in generics.ty_params.iter() { for type_parameter in generics.ty_params.iter() {
self.operation.visit_id(type_parameter.id) self.operation.visit_id(type_parameter.id)
...@@ -428,7 +418,7 @@ fn visit_generics_helper(&self, generics: &Generics) { ...@@ -428,7 +418,7 @@ fn visit_generics_helper(&self, generics: &Generics) {
} }
} }
impl Visitor<()> for IdVisitor { impl<'self, O: IdVisitingOperation> Visitor<()> for IdVisitor<'self, O> {
fn visit_mod(&mut self, fn visit_mod(&mut self,
module: &_mod, module: &_mod,
_: Span, _: Span,
...@@ -601,10 +591,18 @@ fn visit_struct_def(&mut self, ...@@ -601,10 +591,18 @@ fn visit_struct_def(&mut self,
struct_def.ctor_id.map(|&ctor_id| self.operation.visit_id(ctor_id)); struct_def.ctor_id.map(|&ctor_id| self.operation.visit_id(ctor_id));
visit::walk_struct_def(self, struct_def, ident, generics, id, ()); visit::walk_struct_def(self, struct_def, ident, generics, id, ());
} }
fn visit_trait_method(&mut self, tm: &ast::trait_method, _: ()) {
match *tm {
ast::required(ref m) => self.operation.visit_id(m.id),
ast::provided(ref m) => self.operation.visit_id(m.id),
}
visit::walk_trait_method(self, tm, ());
}
} }
pub fn visit_ids_for_inlined_item(item: &inlined_item, pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item,
operation: @IdVisitingOperation) { operation: &O) {
let mut id_visitor = IdVisitor { let mut id_visitor = IdVisitor {
operation: operation, operation: operation,
pass_through_items: true, pass_through_items: true,
...@@ -623,18 +621,14 @@ fn visit_id(&self, id: NodeId) { ...@@ -623,18 +621,14 @@ fn visit_id(&self, id: NodeId) {
} }
} }
pub fn compute_id_range(visit_ids_fn: &fn(@IdVisitingOperation)) -> id_range { pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range {
let result = @mut id_range::max(); let result = @mut id_range::max();
visit_ids_fn(@IdRangeComputingVisitor { visit_ids_for_inlined_item(item, &IdRangeComputingVisitor {
result: result, result: result,
} as @IdVisitingOperation); });
*result *result
} }
pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range {
compute_id_range(|f| visit_ids_for_inlined_item(item, f))
}
pub fn is_item_impl(item: @ast::item) -> bool { pub fn is_item_impl(item: @ast::item) -> bool {
match item.node { match item.node {
item_impl(*) => true, item_impl(*) => true,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册