Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c0388cd

Browse files
committedOct 3, 2013
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
1 parent ccd9a96 commit c0388cd

File tree

3 files changed

+423
-926
lines changed

3 files changed

+423
-926
lines changed
 

‎src/librustc/middle/astencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,13 +880,13 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
880880
// Because the ast visitor uses @IdVisitingOperation, I can't pass in
881881
// ecx directly, but /I/ know that it'll be fine since the lifetime is
882882
// tied to the CrateContext that lives throughout this entire section.
883-
ast_util::visit_ids_for_inlined_item(ii, @SideTableEncodingIdVisitor {
883+
ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor {
884884
ecx_ptr: unsafe {
885885
cast::transmute(ecx)
886886
},
887887
new_ebml_w: new_ebml_w,
888888
maps: maps,
889-
} as @ast_util::IdVisitingOperation);
889+
});
890890
ebml_w.end_tag();
891891
}
892892

‎src/librustc/middle/lint.rs

Lines changed: 404 additions & 901 deletions
Large diffs are not rendered by default.

‎src/libsyntax/ast_util.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -397,27 +397,17 @@ impl id_range {
397397
}
398398
}
399399

400-
pub fn id_visitor(operation: @IdVisitingOperation, pass_through_items: bool)
401-
-> @mut Visitor<()> {
402-
let visitor = @mut IdVisitor {
403-
operation: operation,
404-
pass_through_items: pass_through_items,
405-
visited_outermost: false,
406-
};
407-
visitor as @mut Visitor<()>
408-
}
409-
410400
pub trait IdVisitingOperation {
411401
fn visit_id(&self, node_id: NodeId);
412402
}
413403

414-
pub struct IdVisitor {
415-
operation: @IdVisitingOperation,
404+
pub struct IdVisitor<'self, O> {
405+
operation: &'self O,
416406
pass_through_items: bool,
417407
visited_outermost: bool,
418408
}
419409

420-
impl IdVisitor {
410+
impl<'self, O: IdVisitingOperation> IdVisitor<'self, O> {
421411
fn visit_generics_helper(&self, generics: &Generics) {
422412
for type_parameter in generics.ty_params.iter() {
423413
self.operation.visit_id(type_parameter.id)
@@ -428,7 +418,7 @@ impl IdVisitor {
428418
}
429419
}
430420

431-
impl Visitor<()> for IdVisitor {
421+
impl<'self, O: IdVisitingOperation> Visitor<()> for IdVisitor<'self, O> {
432422
fn visit_mod(&mut self,
433423
module: &_mod,
434424
_: Span,
@@ -601,10 +591,18 @@ impl Visitor<()> for IdVisitor {
601591
struct_def.ctor_id.map(|&ctor_id| self.operation.visit_id(ctor_id));
602592
visit::walk_struct_def(self, struct_def, ident, generics, id, ());
603593
}
594+
595+
fn visit_trait_method(&mut self, tm: &ast::trait_method, _: ()) {
596+
match *tm {
597+
ast::required(ref m) => self.operation.visit_id(m.id),
598+
ast::provided(ref m) => self.operation.visit_id(m.id),
599+
}
600+
visit::walk_trait_method(self, tm, ());
601+
}
604602
}
605603

606-
pub fn visit_ids_for_inlined_item(item: &inlined_item,
607-
operation: @IdVisitingOperation) {
604+
pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &inlined_item,
605+
operation: &O) {
608606
let mut id_visitor = IdVisitor {
609607
operation: operation,
610608
pass_through_items: true,
@@ -623,18 +621,14 @@ impl IdVisitingOperation for IdRangeComputingVisitor {
623621
}
624622
}
625623

626-
pub fn compute_id_range(visit_ids_fn: &fn(@IdVisitingOperation)) -> id_range {
624+
pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range {
627625
let result = @mut id_range::max();
628-
visit_ids_fn(@IdRangeComputingVisitor {
626+
visit_ids_for_inlined_item(item, &IdRangeComputingVisitor {
629627
result: result,
630-
} as @IdVisitingOperation);
628+
});
631629
*result
632630
}
633631

634-
pub fn compute_id_range_for_inlined_item(item: &inlined_item) -> id_range {
635-
compute_id_range(|f| visit_ids_for_inlined_item(item, f))
636-
}
637-
638632
pub fn is_item_impl(item: @ast::item) -> bool {
639633
match item.node {
640634
item_impl(*) => true,

5 commit comments

Comments
 (5)

bors commented on Oct 3, 2013

@bors
Collaborator

saw approval from thestinger
at alexcrichton@c0388cd

bors commented on Oct 3, 2013

@bors
Collaborator

merging alexcrichton/rust/lint = c0388cd into auto

bors commented on Oct 3, 2013

@bors
Collaborator

alexcrichton/rust/lint = c0388cd merged ok, testing candidate = 9344e2a

bors commented on Oct 3, 2013

@bors
Collaborator

fast-forwarding master to auto = 9344e2a

Please sign in to comment.