Skip to content

Commit 516d5cd

Browse files
authored
Rollup merge of #139772 - nnethercote:rm-hir-Map, r=Zalathar
Remove `hir::Map` A follow-up to rust-lang/rust#139232. r? `@Zalathar`
2 parents 6ca7376 + b557b97 commit 516d5cd

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

Diff for: 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/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)