Skip to main content

rustc_query_impl/
lib.rs

1//! Support for serializing the dep-graph and reloading it.
2
3// tidy-alphabetical-start
4#![allow(internal_features)]
5#![feature(core_intrinsics)]
6#![feature(min_specialization)]
7#![feature(rustc_attrs)]
8#![feature(try_blocks)]
9// tidy-alphabetical-end
10
11use rustc_data_structures::sync::AtomicU64;
12use rustc_middle::dep_graph;
13use rustc_middle::queries::{ExternProviders, Providers};
14use rustc_middle::query::on_disk_cache::OnDiskCache;
15use rustc_middle::query::{QueryCache, QuerySystem, QueryVTable};
16use rustc_middle::ty::TyCtxt;
17
18pub use crate::dep_kind_vtables::make_dep_kind_vtables;
19pub use crate::execution::{CollectActiveJobsKind, collect_active_query_jobs};
20pub use crate::job::{QueryJobMap, break_query_cycles, print_query_stack};
21
22mod dep_kind_vtables;
23mod error;
24mod execution;
25mod handle_cycle_error;
26mod job;
27mod plumbing;
28mod profiling_support;
29mod query_impl;
30
31/// Trait that knows how to look up the [`QueryVTable`] for a particular query.
32///
33/// This trait allows some per-query code to be defined in generic functions
34/// with a trait bound, instead of having to be defined inline within a macro
35/// expansion.
36///
37/// There is one macro-generated implementation of this trait for each query,
38/// on the type `rustc_query_impl::query_impl::$name::VTableGetter`.
39trait GetQueryVTable<'tcx> {
40    type Cache: QueryCache + 'tcx;
41
42    fn query_vtable(tcx: TyCtxt<'tcx>) -> &'tcx QueryVTable<'tcx, Self::Cache>;
43}
44
45pub fn query_system<'tcx>(
46    local_providers: Providers,
47    extern_providers: ExternProviders,
48    on_disk_cache: Option<OnDiskCache>,
49    incremental: bool,
50) -> QuerySystem<'tcx> {
51    let mut query_vtables = query_impl::make_query_vtables(incremental);
52    handle_cycle_error::specialize_query_vtables(&mut query_vtables);
53    QuerySystem {
54        arenas: Default::default(),
55        query_vtables,
56        side_effects: Default::default(),
57        on_disk_cache,
58        local_providers,
59        extern_providers,
60        jobs: AtomicU64::new(1),
61    }
62}
63
64pub fn provide(providers: &mut rustc_middle::util::Providers) {
65    providers.hooks.alloc_self_profile_query_strings =
66        profiling_support::alloc_self_profile_query_strings;
67    providers.hooks.verify_query_key_hashes = plumbing::verify_query_key_hashes;
68    providers.hooks.encode_query_values = plumbing::encode_query_values;
69}