@@ -76,8 +76,8 @@ dependencies of the local crate). Note that what determines the crate
76
76
that a query is targeting is not the * kind* of query, but the * key* .
77
77
For example, when you invoke ` tcx.type_of(def_id) ` , that could be a
78
78
local query or an external query, depending on what crate the ` def_id `
79
- is referring to (see the ` self::keys::Key ` trait for more information
80
- on how that works).
79
+ is referring to (see the [ ` self::keys::Key ` ] [ Key ] trait for more
80
+ information on how that works).
81
81
82
82
Providers always have the same signature:
83
83
@@ -96,8 +96,10 @@ They return the result of the query.
96
96
#### How providers are setup
97
97
98
98
When the tcx is created, it is given the providers by its creator using
99
- the ` Providers ` struct. This struct is generated by the macros here, but it
100
- is basically a big list of function pointers:
99
+ the [ ` Providers ` ] [ providers_struct ] struct. This struct is generated by
100
+ the macros here, but it is basically a big list of function pointers:
101
+
102
+ [ providers_struct ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/query/struct.Providers.html
101
103
102
104
``` rust,ignore
103
105
struct Providers {
@@ -110,11 +112,13 @@ At present, we have one copy of the struct for local crates, and one
110
112
for external crates, though the plan is that we may eventually have
111
113
one per crate.
112
114
113
- These ` Provider ` structs are ultimately created and populated by
115
+ These ` Providers ` structs are ultimately created and populated by
114
116
` librustc_driver ` , but it does this by distributing the work
115
117
throughout the other ` rustc_* ` crates. This is done by invoking
116
- various ` provide ` functions. These functions tend to look something
117
- like this:
118
+ various [ ` provide ` ] [ provide_fn ] functions. These functions tend to look
119
+ something like this:
120
+
121
+ [ provide_fn ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/hir/fn.provide.html
118
122
119
123
``` rust,ignore
120
124
pub fn provide(providers: &mut Providers) {
@@ -147,13 +151,16 @@ fn fubar<'tcx>(tcx: TyCtxt<'tcx>, key: DefId) -> Fubar<'tcx> { ... }
147
151
148
152
N.B. Most of the ` rustc_* ` crates only provide ** local
149
153
providers** . Almost all ** extern providers** wind up going through the
150
- [ ` rustc_metadata ` crate] [ rustc_metadata ] , which loads the information from the
151
- crate metadata. But in some cases there are crates that provide queries for
152
- * both* local and external crates, in which case they define both a
153
- ` provide ` and a ` provide_extern ` function that ` rustc_driver ` can
154
- invoke.
154
+ [ ` rustc_metadata ` crate] [ rustc_metadata ] , which loads the information
155
+ from the crate metadata. But in some cases there are crates that
156
+ provide queries for * both* local and external crates, in which case
157
+ they define both a [ ` provide ` ] [ ext_provide ] and a
158
+ [ ` provide_extern ` ] [ ext_provide_extern ] function that ` rustc_driver `
159
+ can invoke.
155
160
156
161
[ rustc_metadata ] : https://github.com/rust-lang/rust/tree/master/src/librustc_metadata
162
+ [ ext_provide ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_llvm/attributes/fn.provide.html
163
+ [ ext_provide_extern ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_codegen_llvm/attributes/fn.provide_extern.html
157
164
158
165
### Adding a new kind of query
159
166
@@ -205,7 +212,7 @@ Let's go over them one by one:
205
212
(` ty::queries::type_of ` ) that will be generated to represent
206
213
this query.
207
214
- ** Query key type:** the type of the argument to this query.
208
- This type must implement the ` ty::query::keys::Key ` trait, which
215
+ This type must implement the [ ` ty::query::keys::Key ` ] [ Key ] trait, which
209
216
defines (for example) how to map it to a crate, and so forth.
210
217
- ** Result type of query:** the type produced by this query. This type
211
218
should (a) not use ` RefCell ` or other interior mutability and (b) be
@@ -218,6 +225,8 @@ Let's go over them one by one:
218
225
- ** Query modifiers:** various flags and options that customize how the
219
226
query is processed.
220
227
228
+ [ Key ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/query/keys/trait.Key.html
229
+
221
230
So, to add a query:
222
231
223
232
- Add an entry to ` rustc_queries! ` using the format above.
@@ -229,7 +238,7 @@ So, to add a query:
229
238
For each kind, the ` rustc_queries ` macro will generate a "query struct"
230
239
named after the query. This struct is a kind of a place-holder
231
240
describing the query. Each such struct implements the
232
- ` self::config::QueryConfig ` trait, which has associated types for the
241
+ [ ` self::config::QueryConfig ` ] [ QueryConfig ] trait, which has associated types for the
233
242
key/value of that particular query. Basically the code generated looks something
234
243
like this:
235
244
@@ -247,13 +256,16 @@ impl<'tcx> QueryConfig for type_of<'tcx> {
247
256
```
248
257
249
258
There is an additional trait that you may wish to implement called
250
- ` self::config::QueryDescription ` . This trait is used during cycle
251
- errors to give a "human readable" name for the query, so that we can
252
- summarize what was happening when the cycle occurred. Implementing
253
- this trait is optional if the query key is ` DefId ` , but if you * don't *
254
- implement it, you get a pretty generic error ("processing ` foo ` ...").
259
+ [ ` self::config::QueryDescription ` ] [ QueryDescription ] . This trait is
260
+ used during cycle errors to give a "human readable" name for the query,
261
+ so that we can summarize what was happening when the cycle occurred.
262
+ Implementing this trait is optional if the query key is ` DefId ` , but
263
+ if you * don't * implement it, you get a pretty generic error ("processing ` foo ` ...").
255
264
You can put new impls into the ` config ` module. They look something like this:
256
265
266
+ [ QueryConfig ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/query/trait.QueryConfig.html
267
+ [ QueryDescription ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/query/config/trait.QueryDescription.html
268
+
257
269
``` rust,ignore
258
270
impl<'tcx> QueryDescription for queries::type_of<'tcx> {
259
271
fn describe(tcx: TyCtxt, key: DefId) -> String {
0 commit comments