Commit 85cc4b2
authored
Rollup merge of #152958 - nnethercote:rustc_queries-fixes, r=oli-obk
`rustc_queries` simplifications
Queries have two ways of specifying code snippets, in `desc` and `cache_on_disk_if` blocks. An example:
```rust
query check_liveness(key: LocalDefId) -> &'tcx rustc_index::bit_set::DenseBitSet<abi::FieldIdx> {
arena_cache
desc { |tcx| "checking liveness of variables in `{}`", tcx.def_path_str(key.to_def_id()) }
cache_on_disk_if(tcx) { tcx.is_typeck_child(key.to_def_id()) }
}
```
If you need to use `tcx` in the snippet, you can use an explicit binding. But there are multiple problems with this.
- The syntax used is different in the two snippets: `|tcx|` within the block vs. `(tcx)` outside the block. (!!)
- Bug 1: In `desc` snippets you can leave out the `|tcx|` and still use `tcx`. Several existing queries do this.
- Bug 2: In `desc` snippets you can always use `key` in the snippet to refer to the key, even if that's not the identifier used in the query head.
- Finally, you can bind `tcx` and not use it, without a warning. Several existing queries do this.
I think explicit `tcx` binding is silly. Many queries need `tcx` and this macro is already super-magical, so just making `tcx` implicitly available seems fine, rather than making the query writer jump through a little syntactic hoop. This makes both the query definitions and the proc macro simpler.
r? @petrochenkov2 files changed
Lines changed: 186 additions & 203 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | | - | |
113 | 111 | | |
114 | 112 | | |
115 | 113 | | |
| |||
192 | 190 | | |
193 | 191 | | |
194 | 192 | | |
195 | | - | |
| 193 | + | |
196 | 194 | | |
197 | 195 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | 196 | | |
207 | | - | |
| 197 | + | |
208 | 198 | | |
209 | 199 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 200 | + | |
222 | 201 | | |
223 | | - | |
| 202 | + | |
224 | 203 | | |
225 | 204 | | |
226 | 205 | | |
| |||
313 | 292 | | |
314 | 293 | | |
315 | 294 | | |
316 | | - | |
317 | | - | |
318 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
319 | 300 | | |
320 | 301 | | |
321 | 302 | | |
322 | | - | |
| 303 | + | |
323 | 304 | | |
324 | 305 | | |
325 | 306 | | |
326 | 307 | | |
327 | | - | |
328 | | - | |
| 308 | + | |
329 | 309 | | |
330 | 310 | | |
331 | 311 | | |
332 | | - | |
333 | | - | |
| 312 | + | |
334 | 313 | | |
335 | 314 | | |
336 | 315 | | |
| |||
0 commit comments