@@ -64,7 +64,6 @@ use rustc::ty::{ToPredicate, ReprOptions};
6464use rustc:: ty:: { self , AdtKind , ToPolyTraitRef , Ty , TyCtxt } ;
6565use rustc:: ty:: maps:: Providers ;
6666use rustc:: ty:: util:: IntTypeExt ;
67- use rustc:: dep_graph:: DepNode ;
6867use util:: nodemap:: { NodeMap , FxHashMap } ;
6968
7069use rustc_const_math:: ConstInt ;
@@ -87,7 +86,7 @@ use rustc::hir::def_id::DefId;
8786
8887pub fn collect_item_types < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
8988 let mut visitor = CollectItemTypesVisitor { tcx : tcx } ;
90- tcx. visit_all_item_likes_in_krate ( DepNode :: CollectItem , & mut visitor. as_deep_visitor ( ) ) ;
89+ tcx. hir . krate ( ) . visit_all_item_likes ( & mut visitor. as_deep_visitor ( ) ) ;
9190}
9291
9392pub fn provide ( providers : & mut Providers ) {
@@ -126,57 +125,13 @@ struct CollectItemTypesVisitor<'a, 'tcx: 'a> {
126125 tcx : TyCtxt < ' a , ' tcx , ' tcx >
127126}
128127
129- impl < ' a , ' tcx > CollectItemTypesVisitor < ' a , ' tcx > {
130- /// Collect item types is structured into two tasks. The outer
131- /// task, `CollectItem`, walks the entire content of an item-like
132- /// thing, including its body. It also spawns an inner task,
133- /// `CollectItemSig`, which walks only the signature. This inner
134- /// task is the one that writes the item-type into the various
135- /// maps. This setup ensures that the item body is never
136- /// accessible to the task that computes its signature, so that
137- /// changes to the body don't affect the signature.
138- ///
139- /// Consider an example function `foo` that also has a closure in its body:
140- ///
141- /// ```
142- /// fn foo(<sig>) {
143- /// ...
144- /// let bar = || ...; // we'll label this closure as "bar" below
145- /// }
146- /// ```
147- ///
148- /// This results in a dep-graph like so. I've labeled the edges to
149- /// document where they arise.
150- ///
151- /// ```
152- /// [HirBody(foo)] -2--> [CollectItem(foo)] -4-> [ItemSignature(bar)]
153- /// ^ ^
154- /// 1 3
155- /// [Hir(foo)] -----------+-6-> [CollectItemSig(foo)] -5-> [ItemSignature(foo)]
156- /// ```
157- ///
158- /// 1. This is added by the `visit_all_item_likes_in_krate`.
159- /// 2. This is added when we fetch the item body.
160- /// 3. This is added because `CollectItem` launches `CollectItemSig`.
161- /// - it is arguably false; if we refactor the `with_task` system;
162- /// we could get probably rid of it, but it is also harmless enough.
163- /// 4. This is added by the code in `visit_expr` when we write to `item_types`.
164- /// 5. This is added by the code in `convert_item` when we write to `item_types`;
165- /// note that this write occurs inside the `CollectItemSig` task.
166- /// 6. Added by reads from within `op`.
167- fn with_collect_item_sig ( & self , id : ast:: NodeId , op : fn ( TyCtxt < ' a , ' tcx , ' tcx > , ast:: NodeId ) ) {
168- let def_id = self . tcx . hir . local_def_id ( id) ;
169- self . tcx . dep_graph . with_task ( DepNode :: CollectItemSig ( def_id) , self . tcx , id, op) ;
170- }
171- }
172-
173128impl < ' a , ' tcx > Visitor < ' tcx > for CollectItemTypesVisitor < ' a , ' tcx > {
174129 fn nested_visit_map < ' this > ( & ' this mut self ) -> NestedVisitorMap < ' this , ' tcx > {
175130 NestedVisitorMap :: OnlyBodies ( & self . tcx . hir )
176131 }
177132
178133 fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
179- self . with_collect_item_sig ( item. id , convert_item ) ;
134+ convert_item ( self . tcx , item. id ) ;
180135 intravisit:: walk_item ( self , item) ;
181136 }
182137
@@ -209,12 +164,12 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> {
209164 }
210165
211166 fn visit_trait_item ( & mut self , trait_item : & ' tcx hir:: TraitItem ) {
212- self . with_collect_item_sig ( trait_item. id , convert_trait_item ) ;
167+ convert_trait_item ( self . tcx , trait_item. id ) ;
213168 intravisit:: walk_trait_item ( self , trait_item) ;
214169 }
215170
216171 fn visit_impl_item ( & mut self , impl_item : & ' tcx hir:: ImplItem ) {
217- self . with_collect_item_sig ( impl_item. id , convert_impl_item ) ;
172+ convert_impl_item ( self . tcx , impl_item. id ) ;
218173 intravisit:: walk_impl_item ( self , impl_item) ;
219174 }
220175}
0 commit comments