Skip to content

Commit 9457497

Browse files
nikomatsakisflodiebold
authored andcommittedNov 29, 2016
update comments
1 parent 104125d commit 9457497

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed
 

‎src/librustc/hir/intravisit.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,37 @@ impl<'a> FnKind<'a> {
6767
}
6868
}
6969

70-
/// Specifies what nested things a visitor wants to visit. Currently there are
71-
/// two modes: `OnlyBodies` descends into item bodies, but not into nested
72-
/// items; `All` descends into item bodies and nested items.
70+
/// Specifies what nested things a visitor wants to visit. The most
71+
/// common choice is `OnlyBodies`, which will cause the visitor to
72+
/// visit fn bodies for fns that it encounters, but skip over nested
73+
/// item-like things.
74+
///
75+
/// See the comments on `ItemLikeVisitor` for more details on the overall
76+
/// visit strategy.
7377
pub enum NestedVisitorMap<'this, 'tcx: 'this> {
7478
/// Do not visit any nested things. When you add a new
7579
/// "non-nested" thing, you will want to audit such uses to see if
7680
/// they remain valid.
81+
///
82+
/// Use this if you are only walking some particular kind of tree
83+
/// (i.e., a type, or fn signature) and you don't want to thread a
84+
/// HIR map around.
7785
None,
7886

7987
/// Do not visit nested item-like things, but visit nested things
8088
/// that are inside of an item-like.
8189
///
82-
/// **This is the default mode.**
90+
/// **This is the most common choice.** A very commmon pattern is
91+
/// to use `tcx.visit_all_item_likes_in_krate()` as an outer loop,
92+
/// and to have the visitor that visits the contents of each item
93+
/// using this setting.
8394
OnlyBodies(&'this Map<'tcx>),
8495

8596
/// Visit all nested things, including item-likes.
97+
///
98+
/// **This is an unusual choice.** It is used when you want to
99+
/// process everything within their lexical context. Typically you
100+
/// kick off the visit by doing `walk_krate()`.
86101
All(&'this Map<'tcx>),
87102
}
88103

@@ -128,13 +143,15 @@ pub trait Visitor<'v> : Sized {
128143
///////////////////////////////////////////////////////////////////////////
129144
// Nested items.
130145

131-
/// The default versions of the `visit_nested_XXX` routines invoke this
132-
/// method to get a map to use; if they get back `None`, they just skip
133-
/// nested things. Otherwise, they will lookup the nested thing in the map
134-
/// and visit it depending on what `nested_visit_mode` returns. So the best
135-
/// way to implement a nested visitor is to override this method to return a
136-
/// `Map`; one advantage of this is that if we add more types of nested
137-
/// things in the future, they will automatically work.
146+
/// The default versions of the `visit_nested_XXX` routines invoke
147+
/// this method to get a map to use. By selecting an enum variant,
148+
/// you control which kinds of nested HIR are visited; see
149+
/// `NestedVisitorMap` for details. By "nested HIR", we are
150+
/// referring to bits of HIR that are not directly embedded within
151+
/// one another but rather indirectly, through a table in the
152+
/// crate. This is done to control dependencies during incremental
153+
/// compilation: the non-inline bits of HIR can be tracked and
154+
/// hashed separately.
138155
///
139156
/// **If for some reason you want the nested behavior, but don't
140157
/// have a `Map` are your disposal:** then you should override the

‎src/librustc/hir/itemlikevisit.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ use super::intravisit::Visitor;
4141
/// item-like things.
4242
/// - Example: Lifetime resolution, which wants to bring lifetimes declared on the
4343
/// impl into scope while visiting the impl-items, and then back out again.
44-
/// - How: Implement `intravisit::Visitor` and override the `visit_nested_foo()` foo methods
45-
/// as needed. Walk your crate with `intravisit::walk_crate()` invoked on `tcx.map.krate()`.
44+
/// - How: Implement `intravisit::Visitor` and override the
45+
/// `visit_nested_map()` methods to return
46+
/// `NestedVisitorMap::All`. Walk your crate with
47+
/// `intravisit::walk_crate()` invoked on `tcx.map.krate()`.
4648
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
4749
/// - Pro: Preserves nesting information
4850
/// - Con: Does not integrate well into dependency tracking.

0 commit comments

Comments
 (0)
Please sign in to comment.