]>
git.proxmox.com Git - rustc.git/blob - src/librustc/dep_graph/visit.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use hir
::def_id
::DefId
;
13 use hir
::intravisit
::Visitor
;
16 use super::dep_node
::DepNode
;
19 /// Visit all the items in the krate in some order. When visiting a
20 /// particular item, first create a dep-node by calling `dep_node_fn`
21 /// and push that onto the dep-graph stack of tasks, and also create a
22 /// read edge from the corresponding AST node. This is used in
23 /// compiler passes to automatically record the item that they are
25 pub fn visit_all_items_in_krate
<'tcx
,V
,F
>(tcx
: &TyCtxt
<'tcx
>,
28 where F
: FnMut(DefId
) -> DepNode
<DefId
>, V
: Visitor
<'tcx
>
30 struct TrackingVisitor
<'visit
, 'tcx
: 'visit
, F
: 'visit
, V
: 'visit
> {
31 tcx
: &'visit TyCtxt
<'tcx
>,
32 dep_node_fn
: &'visit
mut F
,
33 visitor
: &'visit
mut V
36 impl<'visit
, 'tcx
, F
, V
> Visitor
<'tcx
> for TrackingVisitor
<'visit
, 'tcx
, F
, V
>
37 where F
: FnMut(DefId
) -> DepNode
<DefId
>, V
: Visitor
<'tcx
>
39 fn visit_item(&mut self, i
: &'tcx hir
::Item
) {
40 let item_def_id
= self.tcx
.map
.local_def_id(i
.id
);
41 let task_id
= (self.dep_node_fn
)(item_def_id
);
42 let _task
= self.tcx
.dep_graph
.in_task(task_id
);
43 debug
!("Started task {:?}", task_id
);
44 self.tcx
.dep_graph
.read(DepNode
::Hir(item_def_id
));
45 self.visitor
.visit_item(i
)
49 let krate
= tcx
.dep_graph
.with_ignore(|| tcx
.map
.krate());
50 let mut tracking_visitor
= TrackingVisitor
{
52 dep_node_fn
: &mut dep_node_fn
,
55 krate
.visit_all_items(&mut tracking_visitor
)