Skip to content

Commit

Permalink
Rollup merge of rust-lang#35090 - michaelwoerister:get-rid-of-id-visi…
Browse files Browse the repository at this point in the history
…tor, r=eddyb

intravisit: Fold functionality of IdVisitor into the regular Visitor.
  • Loading branch information
steveklabnik authored Jul 30, 2016
2 parents a6c519b + 415fde4 commit 8d6f9ae
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 233 deletions.
255 changes: 67 additions & 188 deletions src/librustc/hir/intravisit.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
fn visit_fn(&mut self, fk: intravisit::FnKind<'ast>, fd: &'ast FnDecl,
b: &'ast Block, s: Span, id: NodeId) {
assert_eq!(self.parent_node, id);
intravisit::walk_fn(self, fk, fd, b, s);
intravisit::walk_fn(self, fk, fd, b, s, id);
}

fn visit_block(&mut self, block: &'ast Block) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,9 @@ pub enum ViewPath_ {
/// TraitRef's appear in impls.
///
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
/// that the ref_id is for. The impl_id maps to the "self type" of this impl.
/// If this impl is an ItemImpl, the impl_id is redundant (it could be the
/// same as the impl's node id).
/// that the ref_id is for. Note that ref_id's value is not the NodeId of the
/// trait being referred to but just a unique NodeId that serves as a key
/// within the DefMap.
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct TraitRef {
pub path: Path,
Expand Down
36 changes: 25 additions & 11 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ use syntax_pos::Span;
use errors::DiagnosticBuilder;
use hir;
use hir::intravisit as hir_visit;
use hir::intravisit::{IdVisitor, IdVisitingOperation};
use syntax::visit as ast_visit;

/// Information about the registered lints.
Expand Down Expand Up @@ -663,9 +662,11 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
}

fn visit_ids<F>(&mut self, f: F)
where F: FnOnce(&mut IdVisitor<LateContext>)
where F: FnOnce(&mut IdVisitor)
{
let mut v = IdVisitor::new(self);
let mut v = IdVisitor {
cx: self
};
f(&mut v);
}
}
Expand Down Expand Up @@ -779,7 +780,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
fn visit_fn(&mut self, fk: hir_visit::FnKind<'v>, decl: &'v hir::FnDecl,
body: &'v hir::Block, span: Span, id: ast::NodeId) {
run_lints!(self, check_fn, late_passes, fk, decl, body, span, id);
hir_visit::walk_fn(self, fk, decl, body, span);
hir_visit::walk_fn(self, fk, decl, body, span, id);
run_lints!(self, check_fn_post, late_passes, fk, decl, body, span, id);
}

Expand Down Expand Up @@ -820,7 +821,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {

fn visit_mod(&mut self, m: &hir::Mod, s: Span, n: ast::NodeId) {
run_lints!(self, check_mod, late_passes, m, s, n);
hir_visit::walk_mod(self, m);
hir_visit::walk_mod(self, m, n);
run_lints!(self, check_mod_post, late_passes, m, s, n);
}

Expand Down Expand Up @@ -859,7 +860,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem) {
self.with_lint_attrs(&trait_item.attrs, |cx| {
run_lints!(cx, check_trait_item, late_passes, trait_item);
cx.visit_ids(|v| v.visit_trait_item(trait_item));
cx.visit_ids(|v| hir_visit::walk_trait_item(v, trait_item));
hir_visit::walk_trait_item(cx, trait_item);
run_lints!(cx, check_trait_item_post, late_passes, trait_item);
});
Expand All @@ -868,7 +869,7 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
self.with_lint_attrs(&impl_item.attrs, |cx| {
run_lints!(cx, check_impl_item, late_passes, impl_item);
cx.visit_ids(|v| v.visit_impl_item(impl_item));
cx.visit_ids(|v| hir_visit::walk_impl_item(v, impl_item));
hir_visit::walk_impl_item(cx, impl_item);
run_lints!(cx, check_impl_item_post, late_passes, impl_item);
});
Expand Down Expand Up @@ -1046,16 +1047,30 @@ impl<'a> ast_visit::Visitor for EarlyContext<'a> {
}
}

struct IdVisitor<'a, 'b: 'a, 'tcx: 'a+'b> {
cx: &'a mut LateContext<'b, 'tcx>
}

// Output any lints that were previously added to the session.
impl<'a, 'tcx> IdVisitingOperation for LateContext<'a, 'tcx> {
impl<'a, 'b, 'tcx, 'v> hir_visit::Visitor<'v> for IdVisitor<'a, 'b, 'tcx> {

fn visit_id(&mut self, id: ast::NodeId) {
if let Some(lints) = self.sess().lints.borrow_mut().remove(&id) {
if let Some(lints) = self.cx.sess().lints.borrow_mut().remove(&id) {
debug!("LateContext::visit_id: id={:?} lints={:?}", id, lints);
for (lint_id, span, msg) in lints {
self.span_lint(lint_id.lint, span, &msg[..])
self.cx.span_lint(lint_id.lint, span, &msg[..])
}
}
}

fn visit_trait_item(&mut self, _ti: &hir::TraitItem) {
// Do not recurse into trait or impl items automatically. These are
// processed separately by calling hir_visit::walk_trait_item()
}

fn visit_impl_item(&mut self, _ii: &hir::ImplItem) {
// See visit_trait_item()
}
}

enum CheckLintNameResult {
Expand Down Expand Up @@ -1172,7 +1187,6 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,

// Visit the whole crate.
cx.with_lint_attrs(&krate.attrs, |cx| {
cx.visit_id(ast::CRATE_NODE_ID);
cx.visit_ids(|v| {
hir_visit::walk_crate(v, krate);
});
Expand Down
7 changes: 1 addition & 6 deletions src/librustc/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use syntax::parse::token::InternedString;
use syntax_pos::Span;
use rustc_back::target::Target;
use hir;
use hir::intravisit::{IdVisitor, IdVisitingOperation, Visitor};
use hir::intravisit::Visitor;

pub use self::DefLike::{DlDef, DlField, DlImpl};
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
Expand Down Expand Up @@ -292,11 +292,6 @@ impl InlinedItem {
InlinedItem::ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
}
}

pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
let mut id_visitor = IdVisitor::new(operation);
self.visit(&mut id_visitor);
}
}

// FIXME: find a better place for this?
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> {

impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
fn visit_fn(&mut self, fn_kind: FnKind<'v>, fn_decl: &'v hir::FnDecl,
block: &'v hir::Block, span: Span, _: ast::NodeId) {
block: &'v hir::Block, span: Span, id: ast::NodeId) {

let (is_item_fn, is_unsafe_fn) = match fn_kind {
FnKind::ItemFn(_, _, unsafety, _, _, _, _) =>
Expand All @@ -96,7 +96,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EffectCheckVisitor<'a, 'tcx> {
self.unsafe_context = UnsafeContext::new(SafeContext)
}

intravisit::walk_fn(self, fn_kind, fn_decl, block, span);
intravisit::walk_fn(self, fn_kind, fn_decl, block, span, id);

self.unsafe_context = old_unsafe_context
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ fn visit_fn(ir: &mut IrMaps,

// gather up the various local variables, significant expressions,
// and so forth:
intravisit::walk_fn(&mut fn_maps, fk, decl, body, sp);
intravisit::walk_fn(&mut fn_maps, fk, decl, body, sp, id);

// Special nodes and variables:
// - exit_ln represents the end of the fn, either by return or panic
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
decl,
body);

intravisit::walk_fn(this, fk, decl, body, sp);
intravisit::walk_fn(this, fk, decl, body, sp, id);
}

fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
Expand Down
10 changes: 4 additions & 6 deletions src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::iter::{FromIterator, IntoIterator, repeat};

use rustc::hir;
use rustc::hir::{Pat, PatKind};
use rustc::hir::intravisit::{self, IdVisitor, IdVisitingOperation, Visitor, FnKind};
use rustc::hir::intravisit::{self, Visitor, FnKind};
use rustc_back::slice;

use syntax::ast::{self, DUMMY_NODE_ID, NodeId};
Expand Down Expand Up @@ -474,7 +474,7 @@ struct RenamingRecorder<'map> {
renaming_map: &'map mut FnvHashMap<(NodeId, Span), NodeId>
}

impl<'map> IdVisitingOperation for RenamingRecorder<'map> {
impl<'v, 'map> Visitor<'v> for RenamingRecorder<'map> {
fn visit_id(&mut self, node_id: NodeId) {
let key = (node_id, self.origin_span);
self.renaming_map.insert(key, self.substituted_node_id);
Expand Down Expand Up @@ -529,9 +529,7 @@ impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> {
renaming_map: renaming_map,
};

let mut id_visitor = IdVisitor::new(&mut renaming_recorder);

id_visitor.visit_expr(const_expr);
renaming_recorder.visit_expr(const_expr);
}
}
}
Expand Down Expand Up @@ -1049,7 +1047,7 @@ fn check_fn(cx: &mut MatchCheckCtxt,
_ => cx.param_env = ParameterEnvironment::for_item(cx.tcx, fn_id),
}

intravisit::walk_fn(cx, kind, decl, body, sp);
intravisit::walk_fn(cx, kind, decl, body, sp, fn_id);

for input in &decl.inputs {
check_irrefutable(cx, &input.pat, true);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_incremental/calculate_svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ mod svh_visitor {
SawItem.hash(self.st); visit::walk_item(self, i)
}

fn visit_mod(&mut self, m: &'a Mod, _s: Span, _n: NodeId) {
fn visit_mod(&mut self, m: &'a Mod, _s: Span, n: NodeId) {
debug!("visit_mod: st={:?}", self.st);
SawMod.hash(self.st); visit::walk_mod(self, m)
SawMod.hash(self.st); visit::walk_mod(self, m, n)
}

fn visit_decl(&mut self, d: &'a Decl) {
Expand All @@ -405,9 +405,9 @@ mod svh_visitor {
}

fn visit_fn(&mut self, fk: FnKind<'a>, fd: &'a FnDecl,
b: &'a Block, s: Span, _: NodeId) {
b: &'a Block, s: Span, n: NodeId) {
debug!("visit_fn: st={:?}", self.st);
SawFn.hash(self.st); visit::walk_fn(self, fk, fd, b, s)
SawFn.hash(self.st); visit::walk_fn(self, fk, fd, b, s, n)
}

fn visit_trait_item(&mut self, ti: &'a TraitItem) {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_metadata/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc::session::Session;
use rustc::hir;
use rustc::hir::fold;
use rustc::hir::fold::Folder;
use rustc::hir::intravisit::{IdRange, IdRangeComputingVisitor, IdVisitingOperation};
use rustc::hir::intravisit::{Visitor, IdRangeComputingVisitor, IdRange};

use common as c;
use cstore;
Expand Down Expand Up @@ -693,7 +693,7 @@ struct SideTableEncodingIdVisitor<'a, 'b:'a, 'c:'a, 'tcx:'c> {
rbml_w: &'a mut Encoder<'b>,
}

impl<'a, 'b, 'c, 'tcx> IdVisitingOperation for
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for
SideTableEncodingIdVisitor<'a, 'b, 'c, 'tcx> {
fn visit_id(&mut self, id: ast::NodeId) {
encode_side_tables_for_id(self.ecx, self.rbml_w, id)
Expand All @@ -704,7 +704,7 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
rbml_w: &mut Encoder,
ii: &InlinedItem) {
rbml_w.start_tag(c::tag_table as usize);
ii.visit_ids(&mut SideTableEncodingIdVisitor {
ii.visit(&mut SideTableEncodingIdVisitor {
ecx: ecx,
rbml_w: rbml_w
});
Expand Down Expand Up @@ -1242,9 +1242,9 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
}
}

fn inlined_item_id_range(v: &InlinedItem) -> IdRange {
fn inlined_item_id_range(ii: &InlinedItem) -> IdRange {
let mut visitor = IdRangeComputingVisitor::new();
v.visit_ids(&mut visitor);
ii.visit(&mut visitor);
visitor.result()
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/mir_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BuildMir<'a, 'tcx> {
build::construct_fn(cx, id, arguments, fn_sig.output, body)
});

intravisit::walk_fn(self, fk, decl, body, span);
intravisit::walk_fn(self, fk, decl, body, span, id);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {

let qualif = self.with_mode(mode, |this| {
this.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b));
intravisit::walk_fn(this, fk, fd, b, s);
intravisit::walk_fn(this, fk, fd, b, s, fn_id);
this.qualif
});

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/rvalues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, 'tcx, 'v> intravisit::Visitor<'v> for RvalueContext<'a, 'tcx> {
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx);
euv.walk_fn(fd, b);
});
intravisit::walk_fn(self, fk, fd, b, s)
intravisit::walk_fn(self, fk, fd, b, s, fn_id)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
}
}

intravisit::walk_mod(self, m);
intravisit::walk_mod(self, m, id);
}

fn visit_macro_def(&mut self, md: &'v hir::MacroDef) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl<'a, 'gcx, 'tcx, 'v> Visitor<'v> for AdjustBorrowKind<'a, 'gcx, 'tcx> {
span: Span,
id: ast::NodeId)
{
intravisit::walk_fn(self, fn_kind, decl, body, span);
intravisit::walk_fn(self, fn_kind, decl, body, span, id);
self.analyze_closure(id, span, decl, body);
}
}
Expand Down

0 comments on commit 8d6f9ae

Please sign in to comment.