config.rs 18.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
use dep_graph::SerializedDepNodeIndex;
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
use hir::def_id::{CrateNum, DefId, DefIndex};
use ty::{self, Ty, TyCtxt};
use ty::maps::queries;
use ty::subst::Substs;

use std::hash::Hash;
use syntax_pos::symbol::InternedString;

/// Query configuration and description traits.

pub trait QueryConfig {
    type Key: Eq + Hash + Clone;
    type Value;
}

27
pub(super) trait QueryDescription<'tcx>: QueryConfig {
28
    fn describe(tcx: TyCtxt, key: Self::Key) -> String;
29 30 31 32 33 34 35 36 37 38

    fn cache_on_disk(_: Self::Key) -> bool {
        false
    }

    fn load_from_disk<'a>(_: TyCtxt<'a, 'tcx, 'tcx>,
                          _: SerializedDepNodeIndex)
                          -> Self::Value {
        bug!("QueryDescription::load_from_disk() called for unsupport query.")
    }
39 40
}

41
impl<'tcx, M: QueryConfig<Key=DefId>> QueryDescription<'tcx> for M {
42
    default fn describe(tcx: TyCtxt, def_id: DefId) -> String {
43 44 45 46 47 48
        if !tcx.sess.verbose() {
            format!("processing `{}`", tcx.item_path_str(def_id))
        } else {
            let name = unsafe { ::std::intrinsics::type_name::<M>() };
            format!("processing `{}` applied to `{:?}`", name, def_id)
        }
49 50 51
    }
}

52
impl<'tcx> QueryDescription<'tcx> for queries::is_copy_raw<'tcx> {
53 54 55 56 57
    fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
        format!("computing whether `{}` is `Copy`", env.value)
    }
}

58
impl<'tcx> QueryDescription<'tcx> for queries::is_sized_raw<'tcx> {
59 60 61 62 63
    fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
        format!("computing whether `{}` is `Sized`", env.value)
    }
}

64
impl<'tcx> QueryDescription<'tcx> for queries::is_freeze_raw<'tcx> {
65 66 67 68 69
    fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
        format!("computing whether `{}` is freeze", env.value)
    }
}

70
impl<'tcx> QueryDescription<'tcx> for queries::needs_drop_raw<'tcx> {
71 72 73 74 75
    fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
        format!("computing whether `{}` needs drop", env.value)
    }
}

76
impl<'tcx> QueryDescription<'tcx> for queries::layout_raw<'tcx> {
77 78 79 80 81
    fn describe(_tcx: TyCtxt, env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> String {
        format!("computing layout of `{}`", env.value)
    }
}

82
impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
83 84 85 86 87 88
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("computing the supertraits of `{}`",
                tcx.item_path_str(def_id))
    }
}

89
impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
90 91 92 93 94
    fn describe(_tcx: TyCtxt, ty: Ty<'tcx>) -> String {
        format!("erasing regions from `{:?}`", ty)
    }
}

95
impl<'tcx> QueryDescription<'tcx> for queries::type_param_predicates<'tcx> {
96 97 98 99 100 101 102
    fn describe(tcx: TyCtxt, (_, def_id): (DefId, DefId)) -> String {
        let id = tcx.hir.as_local_node_id(def_id).unwrap();
        format!("computing the bounds for type parameter `{}`",
                tcx.hir.ty_param_name(id))
    }
}

103
impl<'tcx> QueryDescription<'tcx> for queries::coherent_trait<'tcx> {
104 105 106 107 108 109
    fn describe(tcx: TyCtxt, (_, def_id): (CrateNum, DefId)) -> String {
        format!("coherence checking all impls of trait `{}`",
                tcx.item_path_str(def_id))
    }
}

110
impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls<'tcx> {
111 112 113 114 115
    fn describe(_: TyCtxt, k: CrateNum) -> String {
        format!("all inherent impls defined in crate `{:?}`", k)
    }
}

116
impl<'tcx> QueryDescription<'tcx> for queries::crate_inherent_impls_overlap_check<'tcx> {
117 118 119 120 121
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        format!("check for overlap between inherent impls defined in this crate")
    }
}

122
impl<'tcx> QueryDescription<'tcx> for queries::crate_variances<'tcx> {
123 124 125 126 127
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("computing the variances for items in this crate")
    }
}

128
impl<'tcx> QueryDescription<'tcx> for queries::mir_shims<'tcx> {
129 130 131 132 133 134
    fn describe(tcx: TyCtxt, def: ty::InstanceDef<'tcx>) -> String {
        format!("generating MIR shim for `{}`",
                tcx.item_path_str(def.def_id()))
    }
}

135
impl<'tcx> QueryDescription<'tcx> for queries::privacy_access_levels<'tcx> {
136 137 138 139 140
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        format!("privacy access levels")
    }
}

141
impl<'tcx> QueryDescription<'tcx> for queries::typeck_item_bodies<'tcx> {
142 143 144 145 146
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        format!("type-checking all item bodies")
    }
}

147
impl<'tcx> QueryDescription<'tcx> for queries::reachable_set<'tcx> {
148 149 150 151 152
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        format!("reachability")
    }
}

153
impl<'tcx> QueryDescription<'tcx> for queries::const_eval<'tcx> {
154 155 156 157 158
    fn describe(tcx: TyCtxt, key: ty::ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)>) -> String {
        format!("const-evaluating `{}`", tcx.item_path_str(key.value.0))
    }
}

159
impl<'tcx> QueryDescription<'tcx> for queries::mir_keys<'tcx> {
160 161 162 163 164
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        format!("getting a list of all mir_keys")
    }
}

165
impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
166 167 168 169 170
    fn describe(_tcx: TyCtxt, instance: ty::Instance<'tcx>) -> String {
        format!("computing the symbol for `{}`", instance)
    }
}

171
impl<'tcx> QueryDescription<'tcx> for queries::describe_def<'tcx> {
172 173 174 175 176
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("describe_def")
    }
}

177
impl<'tcx> QueryDescription<'tcx> for queries::def_span<'tcx> {
178 179 180 181 182 183
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("def_span")
    }
}


184
impl<'tcx> QueryDescription<'tcx> for queries::lookup_stability<'tcx> {
185 186 187 188 189
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("stability")
    }
}

190
impl<'tcx> QueryDescription<'tcx> for queries::lookup_deprecation_entry<'tcx> {
191 192 193 194 195
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("deprecation")
    }
}

196
impl<'tcx> QueryDescription<'tcx> for queries::item_attrs<'tcx> {
197 198 199 200 201
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("item_attrs")
    }
}

202
impl<'tcx> QueryDescription<'tcx> for queries::is_exported_symbol<'tcx> {
203 204 205 206 207
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("is_exported_symbol")
    }
}

208
impl<'tcx> QueryDescription<'tcx> for queries::fn_arg_names<'tcx> {
209 210 211 212 213
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("fn_arg_names")
    }
}

214
impl<'tcx> QueryDescription<'tcx> for queries::impl_parent<'tcx> {
215 216 217 218 219
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("impl_parent")
    }
}

220
impl<'tcx> QueryDescription<'tcx> for queries::trait_of_item<'tcx> {
221 222 223 224 225
    fn describe(_: TyCtxt, _: DefId) -> String {
        bug!("trait_of_item")
    }
}

226
impl<'tcx> QueryDescription<'tcx> for queries::item_body_nested_bodies<'tcx> {
227 228 229 230 231
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("nested item bodies of `{}`", tcx.item_path_str(def_id))
    }
}

232
impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_static<'tcx> {
233 234 235 236 237 238
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("const checking if rvalue is promotable to static `{}`",
            tcx.item_path_str(def_id))
    }
}

239
impl<'tcx> QueryDescription<'tcx> for queries::rvalue_promotable_map<'tcx> {
240 241 242 243 244 245
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("checking which parts of `{}` are promotable to static",
                tcx.item_path_str(def_id))
    }
}

246
impl<'tcx> QueryDescription<'tcx> for queries::is_mir_available<'tcx> {
247 248 249 250 251 252
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("checking if item is mir available: `{}`",
            tcx.item_path_str(def_id))
    }
}

253
impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> {
254 255 256 257 258
    fn describe(tcx: TyCtxt, key: (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>)) -> String {
        format!("checking if `{}` fulfills its obligations", tcx.item_path_str(key.1.def_id()))
    }
}

259
impl<'tcx> QueryDescription<'tcx> for queries::trait_impls_of<'tcx> {
260 261 262 263 264
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("trait impls of `{}`", tcx.item_path_str(def_id))
    }
}

265
impl<'tcx> QueryDescription<'tcx> for queries::is_object_safe<'tcx> {
266 267 268 269 270
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("determine object safety of trait `{}`", tcx.item_path_str(def_id))
    }
}

271
impl<'tcx> QueryDescription<'tcx> for queries::is_const_fn<'tcx> {
272 273 274 275 276
    fn describe(tcx: TyCtxt, def_id: DefId) -> String {
        format!("checking if item is const fn: `{}`", tcx.item_path_str(def_id))
    }
}

277
impl<'tcx> QueryDescription<'tcx> for queries::dylib_dependency_formats<'tcx> {
278 279 280 281 282
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        "dylib dependency formats of crate".to_string()
    }
}

283
impl<'tcx> QueryDescription<'tcx> for queries::is_panic_runtime<'tcx> {
284 285 286 287 288
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        "checking if the crate is_panic_runtime".to_string()
    }
}

289
impl<'tcx> QueryDescription<'tcx> for queries::is_compiler_builtins<'tcx> {
290 291 292 293 294
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        "checking if the crate is_compiler_builtins".to_string()
    }
}

295
impl<'tcx> QueryDescription<'tcx> for queries::has_global_allocator<'tcx> {
296 297 298 299 300
    fn describe(_: TyCtxt, _: CrateNum) -> String {
        "checking if the crate has_global_allocator".to_string()
    }
}

301
impl<'tcx> QueryDescription<'tcx> for queries::extern_crate<'tcx> {
302 303 304 305 306
    fn describe(_: TyCtxt, _: DefId) -> String {
        "getting crate's ExternCrateData".to_string()
    }
}

307
impl<'tcx> QueryDescription<'tcx> for queries::lint_levels<'tcx> {
308 309 310 311 312
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("computing the lint levels for items in this crate")
    }
}

313
impl<'tcx> QueryDescription<'tcx> for queries::specializes<'tcx> {
314 315 316 317 318
    fn describe(_tcx: TyCtxt, _: (DefId, DefId)) -> String {
        format!("computing whether impls specialize one another")
    }
}

319
impl<'tcx> QueryDescription<'tcx> for queries::in_scope_traits_map<'tcx> {
320 321 322 323 324
    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
        format!("traits in scope at a block")
    }
}

325
impl<'tcx> QueryDescription<'tcx> for queries::is_no_builtins<'tcx> {
326 327 328 329 330
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("test whether a crate has #![no_builtins]")
    }
}

331
impl<'tcx> QueryDescription<'tcx> for queries::panic_strategy<'tcx> {
332 333 334 335 336
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("query a crate's configured panic strategy")
    }
}

337
impl<'tcx> QueryDescription<'tcx> for queries::is_profiler_runtime<'tcx> {
338 339 340 341 342
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("query a crate is #![profiler_runtime]")
    }
}

343
impl<'tcx> QueryDescription<'tcx> for queries::is_sanitizer_runtime<'tcx> {
344 345 346 347 348
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("query a crate is #![sanitizer_runtime]")
    }
}

349
impl<'tcx> QueryDescription<'tcx> for queries::exported_symbol_ids<'tcx> {
350 351 352 353 354
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the exported symbols of a crate")
    }
}

355
impl<'tcx> QueryDescription<'tcx> for queries::native_libraries<'tcx> {
356 357 358 359 360
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the native libraries of a linked crate")
    }
}

361
impl<'tcx> QueryDescription<'tcx> for queries::plugin_registrar_fn<'tcx> {
362 363 364 365 366
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the plugin registrar for a crate")
    }
}

367
impl<'tcx> QueryDescription<'tcx> for queries::derive_registrar_fn<'tcx> {
368 369 370 371 372
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the derive registrar for a crate")
    }
}

373
impl<'tcx> QueryDescription<'tcx> for queries::crate_disambiguator<'tcx> {
374 375 376 377 378
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the disambiguator a crate")
    }
}

379
impl<'tcx> QueryDescription<'tcx> for queries::crate_hash<'tcx> {
380 381 382 383 384
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the hash a crate")
    }
}

385
impl<'tcx> QueryDescription<'tcx> for queries::original_crate_name<'tcx> {
386 387 388 389 390
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up the original name a crate")
    }
}

391
impl<'tcx> QueryDescription<'tcx> for queries::implementations_of_trait<'tcx> {
392 393 394 395 396
    fn describe(_tcx: TyCtxt, _: (CrateNum, DefId)) -> String {
        format!("looking up implementations of a trait in a crate")
    }
}

397
impl<'tcx> QueryDescription<'tcx> for queries::all_trait_implementations<'tcx> {
398 399 400 401 402
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up all (?) trait implementations")
    }
}

403
impl<'tcx> QueryDescription<'tcx> for queries::link_args<'tcx> {
404 405 406 407 408
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up link arguments for a crate")
    }
}

409
impl<'tcx> QueryDescription<'tcx> for queries::named_region_map<'tcx> {
410 411 412 413 414
    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
        format!("looking up a named region")
    }
}

415
impl<'tcx> QueryDescription<'tcx> for queries::is_late_bound_map<'tcx> {
416 417 418 419 420
    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
        format!("testing if a region is late boudn")
    }
}

421
impl<'tcx> QueryDescription<'tcx> for queries::object_lifetime_defaults_map<'tcx> {
422 423 424 425 426
    fn describe(_tcx: TyCtxt, _: DefIndex) -> String {
        format!("looking up lifetime defaults for a region")
    }
}

427
impl<'tcx> QueryDescription<'tcx> for queries::dep_kind<'tcx> {
428 429 430 431 432
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("fetching what a dependency looks like")
    }
}

433
impl<'tcx> QueryDescription<'tcx> for queries::crate_name<'tcx> {
434 435 436 437 438
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("fetching what a crate is named")
    }
}

439
impl<'tcx> QueryDescription<'tcx> for queries::get_lang_items<'tcx> {
440 441 442 443 444
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("calculating the lang items map")
    }
}

445
impl<'tcx> QueryDescription<'tcx> for queries::defined_lang_items<'tcx> {
446 447 448 449 450
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("calculating the lang items defined in a crate")
    }
}

451
impl<'tcx> QueryDescription<'tcx> for queries::missing_lang_items<'tcx> {
452 453 454 455 456
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("calculating the missing lang items in a crate")
    }
}

457
impl<'tcx> QueryDescription<'tcx> for queries::visible_parent_map<'tcx> {
458 459 460 461 462
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("calculating the visible parent map")
    }
}

463
impl<'tcx> QueryDescription<'tcx> for queries::missing_extern_crate_item<'tcx> {
464 465 466 467 468
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("seeing if we're missing an `extern crate` item for this crate")
    }
}

469
impl<'tcx> QueryDescription<'tcx> for queries::used_crate_source<'tcx> {
470 471 472 473 474
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking at the source for a crate")
    }
}

475
impl<'tcx> QueryDescription<'tcx> for queries::postorder_cnums<'tcx> {
476 477 478 479 480
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("generating a postorder list of CrateNums")
    }
}

481
impl<'tcx> QueryDescription<'tcx> for queries::maybe_unused_extern_crates<'tcx> {
482 483 484 485 486
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("looking up all possibly unused extern crates")
    }
}

487
impl<'tcx> QueryDescription<'tcx> for queries::stability_index<'tcx> {
488 489 490 491 492
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("calculating the stability index for the local crate")
    }
}

493
impl<'tcx> QueryDescription<'tcx> for queries::all_crate_nums<'tcx> {
494 495 496 497 498
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("fetching all foreign CrateNum instances")
    }
}

499
impl<'tcx> QueryDescription<'tcx> for queries::exported_symbols<'tcx> {
500 501 502 503 504
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("exported_symbols")
    }
}

505
impl<'tcx> QueryDescription<'tcx> for queries::collect_and_partition_translation_items<'tcx> {
506 507 508 509 510
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("collect_and_partition_translation_items")
    }
}

511
impl<'tcx> QueryDescription<'tcx> for queries::codegen_unit<'tcx> {
512 513 514 515 516
    fn describe(_tcx: TyCtxt, _: InternedString) -> String {
        format!("codegen_unit")
    }
}

517
impl<'tcx> QueryDescription<'tcx> for queries::compile_codegen_unit<'tcx> {
518 519 520 521 522
    fn describe(_tcx: TyCtxt, _: InternedString) -> String {
        format!("compile_codegen_unit")
    }
}

523
impl<'tcx> QueryDescription<'tcx> for queries::output_filenames<'tcx> {
524 525 526 527
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("output_filenames")
    }
}
S
Fix ICE  
scalexm 已提交
528

529
impl<'tcx> QueryDescription<'tcx> for queries::has_clone_closures<'tcx> {
S
Fix ICE  
scalexm 已提交
530 531 532 533 534
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("seeing if the crate has enabled `Clone` closures")
    }
}

535
impl<'tcx> QueryDescription<'tcx> for queries::vtable_methods<'tcx> {
536 537 538 539 540
    fn describe(tcx: TyCtxt, key: ty::PolyTraitRef<'tcx> ) -> String {
        format!("finding all methods for trait {}", tcx.item_path_str(key.def_id()))
    }
}

541
impl<'tcx> QueryDescription<'tcx> for queries::has_copy_closures<'tcx> {
S
Fix ICE  
scalexm 已提交
542 543 544 545
    fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
        format!("seeing if the crate has enabled `Copy` closures")
    }
}
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 554 555 556 557 558 559 560 561 562 563 564 565 566 567

impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
    #[inline]
    fn cache_on_disk(def_id: Self::Key) -> bool {
        def_id.is_local()
    }

    fn load_from_disk<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                          id: SerializedDepNodeIndex)
                          -> Self::Value {
        let typeck_tables: ty::TypeckTables<'tcx> = tcx.on_disk_query_result_cache
                                                       .load_query_result(tcx, id);
        tcx.alloc_tables(typeck_tables)
    }
}