@@ -169,20 +169,25 @@ they define both a `provide` and a `provide_extern` function, through
169
169
How do you add a new query?
170
170
Defining a query takes place in two steps:
171
171
172
- 1 . Specify the query name and its arguments.
172
+ 1 . Declare the query name, its arguments and description .
173
173
2 . Supply query providers where needed.
174
174
175
- To specify the query name and arguments, you simply add an entry to
176
- the big macro invocation in
177
- [ ` compiler/rustc_middle/src/query/mod.rs ` ] [ query-mod ] , which looks something like:
175
+ To declare the query name and arguments, you simply add an entry to
176
+ the big macro invocation in [ ` compiler/rustc_middle/src/query/mod.rs ` ] [ query-mod ] .
177
+ Then you need to add a documentation comment to it with some _ internal_ description.
178
+ Then, provide the ` desc ` attribute which contains a short description of the query.
179
+ This description is shown to the user in query cycles.
180
+
181
+ This looks something like:
178
182
179
183
[ query-mod ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/query/index.html
180
184
181
185
``` rust,ignore
182
186
rustc_queries! {
183
187
/// Records the type of every item.
184
188
query type_of(key: DefId) -> Ty<'tcx> {
185
- cache { key.is_local() }
189
+ cache_on_disk_if { key.is_local() }
190
+ desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
186
191
}
187
192
...
188
193
}
@@ -261,21 +266,6 @@ extra methods which are used by the query system.
261
266
[ QueryConfig ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryConfig.html
262
267
[ QueryDescription ] : https://doc.rust-lang.org/nightly/nightly-rustc/rustc_query_system/query/config/trait.QueryDescription.html
263
268
264
-
265
- Queries also have a description, which is specified using the ` desc ` modifier.
266
- This description is shown to the user when cycle errors happen.
267
-
268
- ``` rust,ignore
269
- rustc_queries! {
270
- Other {
271
- /// Records the type of every item.
272
- query type_of(key: DefId) -> Ty<'tcx> {
273
- desc { |tcx| "computing the type of `{}`", tcx.def_path_str(key) }
274
- }
275
- }
276
- }
277
- ```
278
-
279
269
## External links
280
270
281
271
Related design ideas, and tracking issues:
0 commit comments