]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/maps/config.rs
Rollup merge of #46218 - rust-lang:frewsxcv-rename-slice-swap-param, r=kennytm
[rust.git] / src / librustc / ty / maps / config.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use dep_graph::SerializedDepNodeIndex;
12 use hir::def_id::{CrateNum, DefId, DefIndex};
13 use ty::{self, Ty, TyCtxt};
14 use ty::maps::queries;
15 use ty::subst::Substs;
16
17 use std::hash::Hash;
18 use syntax_pos::symbol::InternedString;
19
20 /// Query configuration and description traits.
21
22 pub trait QueryConfig {
23     type Key: Eq + Hash + Clone;
24     type Value;
25 }
26
27 pub(super) trait QueryDescription<'tcx>: QueryConfig {
28     fn describe(tcx: TyCtxt, key: Self::Key) -> String;
29
30     fn cache_on_disk(_: Self::Key) -> bool {
31         false
32     }
33
34     fn load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
35                           _: SerializedDepNodeIndex)
36                           -> Self::Value {
37         bug!("QueryDescription::load_from_disk() called for unsupport query.")
38     }
39 }
40
41 impl<'tcx, M: QueryConfig<Key=DefId>> QueryDescription<'tcx> for M {
42     default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
43         if !tcx.sess.verbose() {
44             format!("processing `{}`", tcx.item_path_str(def_id))
45         } else {
46             let name = unsafe { ::std::intrinsics::type_name::<M>() };
47             format!("processing `{}` applied to `{:?}`", name, def_id)
48         }
49     }
50 }
51
52 impl<'tcx> QueryDescription<'tcx> for queries::is_copy_raw<'tcx> {
53     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
54         format!("computing whether `{}` is `Copy`", env.value)
55     }
56 }
57
58 impl<'tcx> QueryDescription<'tcx> for queries::is_sized_raw<'tcx> {
59     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
60         format!("computing whether `{}` is `Sized`", env.value)
61     }
62 }
63
64 impl<'tcx> QueryDescription<'tcx> for queries::is_freeze_raw<'tcx> {
65     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
66         format!("computing whether `{}` is freeze", env.value)
67     }
68 }
69
70 impl<'tcx> QueryDescription<'tcx> for queries::needs_drop_raw<'tcx> {
71     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
72         format!("computing whether `{}` needs drop", env.value)
73     }
74 }
75
76 impl<'tcx> QueryDescription<'tcx> for queries::layout_raw<'tcx> {
77     fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
78         format!("computing layout of `{}`", env.value)
79     }
80 }
81
82 impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
83     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
84         format!("computing the supertraits of `{}`",
85                 tcx.item_path_str(def_id))
86     }
87 }
88
89 impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
90     fn describe(_tcx: TyCtxt, ty: Ty<'tcx>) -> String {
91         format!("erasing regions from `{:?}`", ty)
92     }
93 }
94
95 impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
96     fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
97         let id = tcx.hir.as_local_node_id(def_id).unwrap();
98         format!("computing the bounds for type parameter `{}`",
99                 tcx.hir.ty_param_name(id))
100     }
101 }
102
103 impl<'tcx> QueryDescription<'tcx> for queries::coherent_trait<'tcx> {
104     fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
105         format!("coherence checking all impls of trait `{}`",
106                 tcx.item_path_str(def_id))
107     }
108 }
109
110 impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls<'tcx> {
111     fn describe(_: TyCtxt, k: CrateNum) -> String {
112         format!("all inherent impls defined in crate `{:?}`", k)
113     }
114 }
115
116 impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls_overlap_check<'tcx> {
117     fn describe(_: TyCtxt, _: CrateNum) -> String {
118         format!("check for overlap between inherent impls defined in this crate")
119     }
120 }
121
122 impl<'tcx> QueryDescription<'tcx> for queries::crate_variances<'tcx> {
123     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
124         format!("computing the variances for items in this crate")
125     }
126 }
127
128 impl<'tcx> QueryDescription<'tcx> for queries::mir_shims<'tcx> {
129     fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
130         format!("generating MIR shim for `{}`",
131                 tcx.item_path_str(def.def_id()))
132     }
133 }
134
135 impl<'tcx> QueryDescription<'tcx> for queries::privacy_access_levels<'tcx> {
136     fn describe(_: TyCtxt, _: CrateNum) -> String {
137         format!("privacy access levels")
138     }
139 }
140
141 impl<'tcx> QueryDescription<'tcx> for queries::typeck_item_bodies<'tcx> {
142     fn describe(_: TyCtxt, _: CrateNum) -> String {
143         format!("type-checking all item bodies")
144     }
145 }
146
147 impl<'tcx> QueryDescription<'tcx> for queries::reachable_set<'tcx> {
148     fn describe(_: TyCtxt, _: CrateNum) -> String {
149         format!("reachability")
150     }
151 }
152
153 impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> {
154     fn describe(tcx: TyCtxt, key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>) -> String {
155         format!("const-evaluating `{}`", tcx.item_path_str(key.value.0))
156     }
157 }
158
159 impl<'tcx> QueryDescription<'tcx> for queries::mir_keys<'tcx> {
160     fn describe(_: TyCtxt, _: CrateNum) -> String {
161         format!("getting a list of all mir_keys")
162     }
163 }
164
165 impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
166     fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
167         format!("computing the symbol for `{}`", instance)
168     }
169 }
170
171 impl<'tcx> QueryDescription<'tcx> for queries::describe_def<'tcx> {
172     fn describe(_: TyCtxt, _: DefId) -> String {
173         bug!("describe_def")
174     }
175 }
176
177 impl<'tcx> QueryDescription<'tcx> for queries::def_span<'tcx> {
178     fn describe(_: TyCtxt, _: DefId) -> String {
179         bug!("def_span")
180     }
181 }
182
183
184 impl<'tcx> QueryDescription<'tcx> for queries::lookup_stability<'tcx> {
185     fn describe(_: TyCtxt, _: DefId) -> String {
186         bug!("stability")
187     }
188 }
189
190 impl<'tcx> QueryDescription<'tcx> for queries::lookup_deprecation_entry<'tcx> {
191     fn describe(_: TyCtxt, _: DefId) -> String {
192         bug!("deprecation")
193     }
194 }
195
196 impl<'tcx> QueryDescription<'tcx> for queries::item_attrs<'tcx> {
197     fn describe(_: TyCtxt, _: DefId) -> String {
198         bug!("item_attrs")
199     }
200 }
201
202 impl<'tcx> QueryDescription<'tcx> for queries::is_exported_symbol<'tcx> {
203     fn describe(_: TyCtxt, _: DefId) -> String {
204         bug!("is_exported_symbol")
205     }
206 }
207
208 impl<'tcx> QueryDescription<'tcx> for queries::fn_arg_names<'tcx> {
209     fn describe(_: TyCtxt, _: DefId) -> String {
210         bug!("fn_arg_names")
211     }
212 }
213
214 impl<'tcx> QueryDescription<'tcx> for queries::impl_parent<'tcx> {
215     fn describe(_: TyCtxt, _: DefId) -> String {
216         bug!("impl_parent")
217     }
218 }
219
220 impl<'tcx> QueryDescription<'tcx> for queries::trait_of_item<'tcx> {
221     fn describe(_: TyCtxt, _: DefId) -> String {
222         bug!("trait_of_item")
223     }
224 }
225
226 impl<'tcx> QueryDescription<'tcx> for queries::item_body_nested_bodies<'tcx> {
227     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
228         format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
229     }
230 }
231
232 impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_static<'tcx> {
233     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
234         format!("const checking if rvalue is promotable to static `{}`",
235             tcx.item_path_str(def_id))
236     }
237 }
238
239 impl<'tcx> QueryDescription<'tcx> for queries::rvalue_promotable_map<'tcx> {
240     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
241         format!("checking which parts of `{}` are promotable to static",
242                 tcx.item_path_str(def_id))
243     }
244 }
245
246 impl<'tcx> QueryDescription<'tcx> for queries::is_mir_available<'tcx> {
247     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
248         format!("checking if item is mir available: `{}`",
249             tcx.item_path_str(def_id))
250     }
251 }
252
253 impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> {
254     fn describe(tcx: TyCtxt, key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> String {
255         format!("checking if `{}` fulfills its obligations", tcx.item_path_str(key.1.def_id()))
256     }
257 }
258
259 impl<'tcx> QueryDescription<'tcx> for queries::trait_impls_of<'tcx> {
260     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
261         format!("trait impls of `{}`", tcx.item_path_str(def_id))
262     }
263 }
264
265 impl<'tcx> QueryDescription<'tcx> for queries::is_object_safe<'tcx> {
266     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
267         format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
268     }
269 }
270
271 impl<'tcx> QueryDescription<'tcx> for queries::is_const_fn<'tcx> {
272     fn describe(tcx: TyCtxt, def_id: DefId) -> String {
273         format!("checking if item is const fn: `{}`", tcx.item_path_str(def_id))
274     }
275 }
276
277 impl<'tcx> QueryDescription<'tcx> for queries::dylib_dependency_formats<'tcx> {
278     fn describe(_: TyCtxt, _: CrateNum) -> String {
279         "dylib dependency formats of crate".to_string()
280     }
281 }
282
283 impl<'tcx> QueryDescription<'tcx> for queries::is_panic_runtime<'tcx> {
284     fn describe(_: TyCtxt, _: CrateNum) -> String {
285         "checking if the crate is_panic_runtime".to_string()
286     }
287 }
288
289 impl<'tcx> QueryDescription<'tcx> for queries::is_compiler_builtins<'tcx> {
290     fn describe(_: TyCtxt, _: CrateNum) -> String {
291         "checking if the crate is_compiler_builtins".to_string()
292     }
293 }
294
295 impl<'tcx> QueryDescription<'tcx> for queries::has_global_allocator<'tcx> {
296     fn describe(_: TyCtxt, _: CrateNum) -> String {
297         "checking if the crate has_global_allocator".to_string()
298     }
299 }
300
301 impl<'tcx> QueryDescription<'tcx> for queries::extern_crate<'tcx> {
302     fn describe(_: TyCtxt, _: DefId) -> String {
303         "getting crate's ExternCrateData".to_string()
304     }
305 }
306
307 impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
308     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
309         format!("computing the lint levels for items in this crate")
310     }
311 }
312
313 impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
314     fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
315         format!("computing whether impls specialize one another")
316     }
317 }
318
319 impl<'tcx> QueryDescription<'tcx> for queries::in_scope_traits_map<'tcx> {
320     fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
321         format!("traits in scope at a block")
322     }
323 }
324
325 impl<'tcx> QueryDescription<'tcx> for queries::is_no_builtins<'tcx> {
326     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
327         format!("test whether a crate has #![no_builtins]")
328     }
329 }
330
331 impl<'tcx> QueryDescription<'tcx> for queries::panic_strategy<'tcx> {
332     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
333         format!("query a crate's configured panic strategy")
334     }
335 }
336
337 impl<'tcx> QueryDescription<'tcx> for queries::is_profiler_runtime<'tcx> {
338     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
339         format!("query a crate is #![profiler_runtime]")
340     }
341 }
342
343 impl<'tcx> QueryDescription<'tcx> for queries::is_sanitizer_runtime<'tcx> {
344     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
345         format!("query a crate is #![sanitizer_runtime]")
346     }
347 }
348
349 impl<'tcx> QueryDescription<'tcx> for queries::exported_symbol_ids<'tcx> {
350     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
351         format!("looking up the exported symbols of a crate")
352     }
353 }
354
355 impl<'tcx> QueryDescription<'tcx> for queries::native_libraries<'tcx> {
356     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
357         format!("looking up the native libraries of a linked crate")
358     }
359 }
360
361 impl<'tcx> QueryDescription<'tcx> for queries::plugin_registrar_fn<'tcx> {
362     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
363         format!("looking up the plugin registrar for a crate")
364     }
365 }
366
367 impl<'tcx> QueryDescription<'tcx> for queries::derive_registrar_fn<'tcx> {
368     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
369         format!("looking up the derive registrar for a crate")
370     }
371 }
372
373 impl<'tcx> QueryDescription<'tcx> for queries::crate_disambiguator<'tcx> {
374     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
375         format!("looking up the disambiguator a crate")
376     }
377 }
378
379 impl<'tcx> QueryDescription<'tcx> for queries::crate_hash<'tcx> {
380     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
381         format!("looking up the hash a crate")
382     }
383 }
384
385 impl<'tcx> QueryDescription<'tcx> for queries::original_crate_name<'tcx> {
386     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
387         format!("looking up the original name a crate")
388     }
389 }
390
391 impl<'tcx> QueryDescription<'tcx> for queries::implementations_of_trait<'tcx> {
392     fn describe(_tcx: TyCtxt, _: (CrateNum, DefId)) -> String {
393         format!("looking up implementations of a trait in a crate")
394     }
395 }
396
397 impl<'tcx> QueryDescription<'tcx> for queries::all_trait_implementations<'tcx> {
398     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
399         format!("looking up all (?) trait implementations")
400     }
401 }
402
403 impl<'tcx> QueryDescription<'tcx> for queries::link_args<'tcx> {
404     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
405         format!("looking up link arguments for a crate")
406     }
407 }
408
409 impl<'tcx> QueryDescription<'tcx> for queries::named_region_map<'tcx> {
410     fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
411         format!("looking up a named region")
412     }
413 }
414
415 impl<'tcx> QueryDescription<'tcx> for queries::is_late_bound_map<'tcx> {
416     fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
417         format!("testing if a region is late boudn")
418     }
419 }
420
421 impl<'tcx> QueryDescription<'tcx> for queries::object_lifetime_defaults_map<'tcx> {
422     fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
423         format!("looking up lifetime defaults for a region")
424     }
425 }
426
427 impl<'tcx> QueryDescription<'tcx> for queries::dep_kind<'tcx> {
428     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
429         format!("fetching what a dependency looks like")
430     }
431 }
432
433 impl<'tcx> QueryDescription<'tcx> for queries::crate_name<'tcx> {
434     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
435         format!("fetching what a crate is named")
436     }
437 }
438
439 impl<'tcx> QueryDescription<'tcx> for queries::get_lang_items<'tcx> {
440     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
441         format!("calculating the lang items map")
442     }
443 }
444
445 impl<'tcx> QueryDescription<'tcx> for queries::defined_lang_items<'tcx> {
446     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
447         format!("calculating the lang items defined in a crate")
448     }
449 }
450
451 impl<'tcx> QueryDescription<'tcx> for queries::missing_lang_items<'tcx> {
452     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
453         format!("calculating the missing lang items in a crate")
454     }
455 }
456
457 impl<'tcx> QueryDescription<'tcx> for queries::visible_parent_map<'tcx> {
458     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
459         format!("calculating the visible parent map")
460     }
461 }
462
463 impl<'tcx> QueryDescription<'tcx> for queries::missing_extern_crate_item<'tcx> {
464     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
465         format!("seeing if we're missing an `extern crate` item for this crate")
466     }
467 }
468
469 impl<'tcx> QueryDescription<'tcx> for queries::used_crate_source<'tcx> {
470     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
471         format!("looking at the source for a crate")
472     }
473 }
474
475 impl<'tcx> QueryDescription<'tcx> for queries::postorder_cnums<'tcx> {
476     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
477         format!("generating a postorder list of CrateNums")
478     }
479 }
480
481 impl<'tcx> QueryDescription<'tcx> for queries::maybe_unused_extern_crates<'tcx> {
482     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
483         format!("looking up all possibly unused extern crates")
484     }
485 }
486
487 impl<'tcx> QueryDescription<'tcx> for queries::stability_index<'tcx> {
488     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
489         format!("calculating the stability index for the local crate")
490     }
491 }
492
493 impl<'tcx> QueryDescription<'tcx> for queries::all_crate_nums<'tcx> {
494     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
495         format!("fetching all foreign CrateNum instances")
496     }
497 }
498
499 impl<'tcx> QueryDescription<'tcx> for queries::exported_symbols<'tcx> {
500     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
501         format!("exported_symbols")
502     }
503 }
504
505 impl<'tcx> QueryDescription<'tcx> for queries::collect_and_partition_translation_items<'tcx> {
506     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
507         format!("collect_and_partition_translation_items")
508     }
509 }
510
511 impl<'tcx> QueryDescription<'tcx> for queries::codegen_unit<'tcx> {
512     fn describe(_tcx: TyCtxt, _: InternedString) -> String {
513         format!("codegen_unit")
514     }
515 }
516
517 impl<'tcx> QueryDescription<'tcx> for queries::compile_codegen_unit<'tcx> {
518     fn describe(_tcx: TyCtxt, _: InternedString) -> String {
519         format!("compile_codegen_unit")
520     }
521 }
522
523 impl<'tcx> QueryDescription<'tcx> for queries::output_filenames<'tcx> {
524     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
525         format!("output_filenames")
526     }
527 }
528
529 impl<'tcx> QueryDescription<'tcx> for queries::has_clone_closures<'tcx> {
530     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
531         format!("seeing if the crate has enabled `Clone` closures")
532     }
533 }
534
535 impl<'tcx> QueryDescription<'tcx> for queries::vtable_methods<'tcx> {
536     fn describe(tcx: TyCtxt, key: ty::PolyTraitRef<'tcx> ) -> String {
537         format!("finding all methods for trait {}", tcx.item_path_str(key.def_id()))
538     }
539 }
540
541 impl<'tcx> QueryDescription<'tcx> for queries::has_copy_closures<'tcx> {
542     fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
543         format!("seeing if the crate has enabled `Copy` closures")
544     }
545 }
546
547 impl<'tcx> QueryDescription<'tcx> for queries::fully_normalize_monormophic_ty<'tcx> {
548     fn describe(_tcx: TyCtxt, _: Ty) -> String {
549         format!("normalizing types")
550     }
551 }
552
553 impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
554     #[inline]
555     fn cache_on_disk(def_id: Self::Key) -> bool {
556         def_id.is_local()
557     }
558
559     fn load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
560                           id: SerializedDepNodeIndex)
561                           -> Self::Value {
562         let typeck_tables: ty::TypeckTables<'tcx> = tcx.on_disk_query_result_cache
563                                                        .load_query_result(tcx, id);
564         tcx.alloc_tables(typeck_tables)
565     }
566 }
567