Skip to content

Commit 9734e44

Browse files
committed
Documentation fixes.
Remove old references to the HIR map.
1 parent 1a3dee4 commit 9734e44

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

Diff for: compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! 1. **Shallow visit**: Get a simple callback for every item (or item-like thing) in the HIR.
77
//! - Example: find all items with a `#[foo]` attribute on them.
88
//! - How: Use the `hir_crate_items` or `hir_module_items` query to traverse over item-like ids
9-
//! (ItemId, TraitItemId, etc.) and use tcx.def_kind and `tcx.hir().item*(id)` to filter and
9+
//! (ItemId, TraitItemId, etc.) and use tcx.def_kind and `tcx.hir_item*(id)` to filter and
1010
//! access actual item-like thing, respectively.
1111
//! - Pro: Efficient; just walks the lists of item ids and gives users control whether to access
1212
//! the hir_owners themselves or not.

Diff for: compiler/rustc_middle/src/hir/map.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! This module used to contain a type called `Map`. That type has since been
2+
//! eliminated, and all its methods are now on `TyCtxt`. But the module name
3+
//! stays as `map` because there isn't an obviously better name for it.
4+
15
use rustc_abi::ExternAbi;
26
use rustc_ast::visit::{VisitorResult, walk_list};
37
use rustc_data_structures::fingerprint::Fingerprint;
@@ -325,7 +329,7 @@ impl<'tcx> TyCtxt<'tcx> {
325329

326330
/// Returns an iterator of the `DefId`s for all body-owners in this
327331
/// crate. If you would prefer to iterate over the bodies
328-
/// themselves, you can do `self.hir().krate().body_ids.iter()`.
332+
/// themselves, you can do `self.hir_crate(()).body_ids.iter()`.
329333
#[inline]
330334
pub fn hir_body_owners(self) -> impl Iterator<Item = LocalDefId> {
331335
self.hir_crate_items(()).body_owners.iter().copied()

Diff for: compiler/rustc_middle/src/query/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ rustc_queries! {
161161

162162
/// Represents crate as a whole (as distinct from the top-level crate module).
163163
///
164-
/// If you call `hir_crate` (e.g., indirectly by calling `tcx.hir_crate()`),
165-
/// we will have to assume that any change means that you need to be recompiled.
166-
/// This is because the `hir_crate` query gives you access to all other items.
167-
/// To avoid this fate, do not call `tcx.hir_crate()`; instead,
168-
/// prefer wrappers like [`TyCtxt::hir_visit_all_item_likes_in_crate`].
164+
/// If you call `tcx.hir_crate(())` we will have to assume that any change
165+
/// means that you need to be recompiled. This is because the `hir_crate`
166+
/// query gives you access to all other items. To avoid this fate, do not
167+
/// call `tcx.hir_crate(())`; instead, prefer wrappers like
168+
/// [`TyCtxt::hir_visit_all_item_likes_in_crate`].
169169
query hir_crate(key: ()) -> &'tcx Crate<'tcx> {
170170
arena_cache
171171
eval_always
@@ -197,15 +197,15 @@ rustc_queries! {
197197

198198
/// Gives access to the HIR node's parent for the HIR owner `key`.
199199
///
200-
/// This can be conveniently accessed by methods on `tcx.hir()`.
200+
/// This can be conveniently accessed by `tcx.hir_*` methods.
201201
/// Avoid calling this query directly.
202202
query hir_owner_parent(key: hir::OwnerId) -> hir::HirId {
203203
desc { |tcx| "getting HIR parent of `{}`", tcx.def_path_str(key) }
204204
}
205205

206206
/// Gives access to the HIR nodes and bodies inside `key` if it's a HIR owner.
207207
///
208-
/// This can be conveniently accessed by methods on `tcx.hir()`.
208+
/// This can be conveniently accessed by `tcx.hir_*` methods.
209209
/// Avoid calling this query directly.
210210
query opt_hir_owner_nodes(key: LocalDefId) -> Option<&'tcx hir::OwnerNodes<'tcx>> {
211211
desc { |tcx| "getting HIR owner items in `{}`", tcx.def_path_str(key) }
@@ -214,7 +214,7 @@ rustc_queries! {
214214

215215
/// Gives access to the HIR attributes inside the HIR owner `key`.
216216
///
217-
/// This can be conveniently accessed by methods on `tcx.hir()`.
217+
/// This can be conveniently accessed by `tcx.hir_*` methods.
218218
/// Avoid calling this query directly.
219219
query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
220220
desc { |tcx| "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }

Diff for: src/doc/rustc-dev-guide/src/appendix/glossary.md

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Term | Meaning
3131
<span id="generics">generics</span> | The list of generic parameters defined on an item. There are three kinds of generic parameters: Type, lifetime and const parameters.
3232
<span id="hir">HIR</span> | The _high-level [IR](#ir)_, created by lowering and desugaring the AST. ([see more](../hir.md))
3333
<span id="hir-id">`HirId`</span> | Identifies a particular node in the HIR by combining a def-id with an "intra-definition offset". See [the HIR chapter for more](../hir.md#identifiers-in-the-hir).
34-
<span id="hir-map">HIR map</span> | The HIR map, accessible via `tcx.hir()`, allows you to quickly navigate the HIR and convert between various forms of identifiers.
3534
<span id="ice">ICE</span> | Short for _internal compiler error_, this is when the compiler crashes.
3635
<span id="ich">ICH</span> | Short for _incremental compilation hash_, these are used as fingerprints for things such as HIR and crate metadata, to check if changes have been made. This is useful in incremental compilation to see if part of a crate has changed and should be recompiled.
3736
<span id="infcx">`infcx`</span> | The type inference context (`InferCtxt`). (see `rustc_middle::infer`)

Diff for: src/doc/rustc-dev-guide/src/hir.md

+19-24
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ The HIR uses a bunch of different identifiers that coexist and serve different p
100100
a wrapper around a [`HirId`]. For more info about HIR bodies, please refer to the
101101
[HIR chapter][hir-bodies].
102102

103-
These identifiers can be converted into one another through the [HIR map][map].
103+
These identifiers can be converted into one another through the `TyCtxt`.
104104

105105
[`DefId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
106106
[`LocalDefId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html
@@ -110,30 +110,24 @@ These identifiers can be converted into one another through the [HIR map][map].
110110
[`CrateNum`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.CrateNum.html
111111
[`DefIndex`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefIndex.html
112112
[`Body`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Body.html
113-
[hir-map]: ./hir.md#the-hir-map
114113
[hir-bodies]: ./hir.md#hir-bodies
115-
[map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
116114

117-
## The HIR Map
115+
## HIR Operations
118116

119117
Most of the time when you are working with the HIR, you will do so via
120-
the **HIR Map**, accessible in the tcx via [`tcx.hir()`] (and defined in
121-
the [`hir::map`] module). The [HIR map] contains a [number of methods] to
122-
convert between IDs of various kinds and to lookup data associated
123-
with a HIR node.
118+
`TyCtxt`. It contains a number of methods, defined in the `hir::map` module and
119+
mostly prefixed with `hir_`, to convert between IDs of various kinds and to
120+
lookup data associated with a HIR node.
124121

125-
[`tcx.hir()`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir
126-
[`hir::map`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/index.html
127-
[HIR map]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html
128-
[number of methods]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#methods
122+
[`TyCtxt`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html
129123

130124
For example, if you have a [`LocalDefId`], and you would like to convert it
131-
to a [`HirId`], you can use [`tcx.hir().local_def_id_to_hir_id(def_id)`][local_def_id_to_hir_id].
125+
to a [`HirId`], you can use [`tcx.local_def_id_to_hir_id(def_id)`][local_def_id_to_hir_id].
132126
You need a `LocalDefId`, rather than a `DefId`, since only local items have HIR nodes.
133127

134-
[local_def_id_to_hir_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.local_def_id_to_hir_id
128+
[local_def_id_to_hir_id]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.local_def_id_to_hir_id
135129

136-
Similarly, you can use [`tcx.hir().find(n)`][find] to lookup the node for a
130+
Similarly, you can use [`tcx.hir_node(n)`][hir_node] to lookup the node for a
137131
[`HirId`]. This returns a `Option<Node<'hir>>`, where [`Node`] is an enum
138132
defined in the map. By matching on this, you can find out what sort of
139133
node the `HirId` referred to and also get a pointer to the data
@@ -142,26 +136,27 @@ that `n` must be some HIR expression, you can do
142136
[`tcx.hir_expect_expr(n)`][expect_expr], which will extract and return the
143137
[`&hir::Expr`][Expr], panicking if `n` is not in fact an expression.
144138

145-
[find]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.find
139+
[hir_node]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_node
146140
[`Node`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.Node.html
147141
[expect_expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.expect_expr
148142
[Expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Expr.html
149143

150-
Finally, you can use the HIR map to find the parents of nodes, via
151-
calls like [`tcx.hir().get_parent(n)`][get_parent].
144+
Finally, you can find the parents of nodes, via
145+
calls like [`tcx.parent_hir_node(n)`][parent_hir_node].
146+
147+
[get_parent_item]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.parent_hir_node
152148

153-
[get_parent]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.get_parent
154149

155150
## HIR Bodies
156151

157152
A [`rustc_hir::Body`] represents some kind of executable code, such as the body
158153
of a function/closure or the definition of a constant. Bodies are
159154
associated with an **owner**, which is typically some kind of item
160155
(e.g. an `fn()` or `const`), but could also be a closure expression
161-
(e.g. `|x, y| x + y`). You can use the HIR map to find the body
162-
associated with a given def-id ([`maybe_body_owned_by`]) or to find
163-
the owner of a body ([`body_owner_def_id`]).
156+
(e.g. `|x, y| x + y`). You can use the `TyCtxt` to find the body
157+
associated with a given def-id ([`hir_maybe_body_owned_by`]) or to find
158+
the owner of a body ([`hir_body_owner_def_id`]).
164159

165160
[`rustc_hir::Body`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Body.html
166-
[`maybe_body_owned_by`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.maybe_body_owned_by
167-
[`body_owner_def_id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.body_owner_def_id
161+
[`hir_maybe_body_owned_by`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_maybe_body_owned_by
162+
[`hir_body_owner_def_id`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.hir_body_owner_def_id

0 commit comments

Comments
 (0)