Skip to content

Commit 4581d16

Browse files
committed
Move the query system to rustc_query_impl.
1 parent 71f749a commit 4581d16

File tree

17 files changed

+170
-83
lines changed

17 files changed

+170
-83
lines changed

Cargo.lock

+24
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,7 @@ dependencies = [
39013901
"rustc_passes",
39023902
"rustc_plugin_impl",
39033903
"rustc_privacy",
3904+
"rustc_query_impl",
39043905
"rustc_resolve",
39053906
"rustc_serialize",
39063907
"rustc_session",
@@ -4167,6 +4168,29 @@ dependencies = [
41674168
"tracing",
41684169
]
41694170

4171+
[[package]]
4172+
name = "rustc_query_impl"
4173+
version = "0.0.0"
4174+
dependencies = [
4175+
"measureme",
4176+
"rustc-rayon-core",
4177+
"rustc_ast",
4178+
"rustc_attr",
4179+
"rustc_data_structures",
4180+
"rustc_errors",
4181+
"rustc_feature",
4182+
"rustc_hir",
4183+
"rustc_index",
4184+
"rustc_macros",
4185+
"rustc_middle",
4186+
"rustc_query_system",
4187+
"rustc_serialize",
4188+
"rustc_session",
4189+
"rustc_span",
4190+
"rustc_target",
4191+
"tracing",
4192+
]
4193+
41704194
[[package]]
41714195
name = "rustc_query_system"
41724196
version = "0.0.0"

compiler/rustc_interface/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rustc_lint = { path = "../rustc_lint" }
4141
rustc_errors = { path = "../rustc_errors" }
4242
rustc_plugin_impl = { path = "../rustc_plugin_impl" }
4343
rustc_privacy = { path = "../rustc_privacy" }
44+
rustc_query_impl = { path = "../rustc_query_impl" }
4445
rustc_resolve = { path = "../rustc_resolve" }
4546
rustc_trait_selection = { path = "../rustc_trait_selection" }
4647
rustc_ty_utils = { path = "../rustc_ty_utils" }

compiler/rustc_interface/src/passes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ use rustc_middle::arena::Arena;
2121
use rustc_middle::dep_graph::DepGraph;
2222
use rustc_middle::middle;
2323
use rustc_middle::middle::cstore::{CrateStore, MetadataLoader, MetadataLoaderDyn};
24-
use rustc_middle::ty::query;
2524
use rustc_middle::ty::query::Providers;
2625
use rustc_middle::ty::{self, GlobalCtxt, ResolverOutputs, TyCtxt};
2726
use rustc_mir as mir;
2827
use rustc_mir_build as mir_build;
2928
use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str};
3029
use rustc_passes::{self, hir_stats, layout_test};
3130
use rustc_plugin_impl as plugin;
31+
use rustc_query_impl::Queries as TcxQueries;
3232
use rustc_resolve::{Resolver, ResolverArenas};
3333
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType, PpMode, PpSourceMode};
3434
use rustc_session::lint;
@@ -762,7 +762,7 @@ pub fn create_global_ctxt<'tcx>(
762762
mut resolver_outputs: ResolverOutputs,
763763
outputs: OutputFilenames,
764764
crate_name: &str,
765-
queries: &'tcx OnceCell<query::Queries<'tcx>>,
765+
queries: &'tcx OnceCell<TcxQueries<'tcx>>,
766766
global_ctxt: &'tcx OnceCell<GlobalCtxt<'tcx>>,
767767
arena: &'tcx WorkerLocal<Arena<'tcx>>,
768768
) -> QueryContext<'tcx> {
@@ -791,7 +791,7 @@ pub fn create_global_ctxt<'tcx>(
791791
let max_cnum = crates.iter().map(|c| c.as_usize()).max().unwrap_or(0);
792792
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
793793
providers[LOCAL_CRATE] = local_providers;
794-
queries.get_or_init(|| query::Queries::new(providers, extern_providers))
794+
queries.get_or_init(|| TcxQueries::new(providers, extern_providers))
795795
};
796796

797797
let gcx = sess.time("setup_global_ctxt", || {
@@ -805,7 +805,7 @@ pub fn create_global_ctxt<'tcx>(
805805
defs,
806806
dep_graph,
807807
query_result_on_disk_cache,
808-
queries,
808+
queries.as_dyn(),
809809
&crate_name,
810810
&outputs,
811811
)

compiler/rustc_interface/src/queries.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_incremental::DepGraphFuture;
1313
use rustc_lint::LintStore;
1414
use rustc_middle::arena::Arena;
1515
use rustc_middle::dep_graph::DepGraph;
16-
use rustc_middle::ty::query;
1716
use rustc_middle::ty::{GlobalCtxt, ResolverOutputs, TyCtxt};
17+
use rustc_query_impl::Queries as TcxQueries;
1818
use rustc_serialize::json;
1919
use rustc_session::config::{self, OutputFilenames, OutputType};
2020
use rustc_session::{output::find_crate_name, Session};
@@ -72,7 +72,7 @@ impl<T> Default for Query<T> {
7272
pub struct Queries<'tcx> {
7373
compiler: &'tcx Compiler,
7474
gcx: OnceCell<GlobalCtxt<'tcx>>,
75-
queries: OnceCell<query::Queries<'tcx>>,
75+
queries: OnceCell<TcxQueries<'tcx>>,
7676

7777
arena: WorkerLocal<Arena<'tcx>>,
7878
hir_arena: WorkerLocal<rustc_ast_lowering::Arena<'tcx>>,
@@ -429,11 +429,11 @@ impl Compiler {
429429
{
430430
let _prof_timer =
431431
queries.session().prof.generic_activity("self_profile_alloc_query_strings");
432-
gcx.enter(query::alloc_self_profile_query_strings);
432+
gcx.enter(rustc_query_impl::alloc_self_profile_query_strings);
433433
}
434434

435435
if self.session().opts.debugging_opts.query_stats {
436-
gcx.enter(query::print_stats);
436+
gcx.enter(rustc_query_impl::print_stats);
437437
}
438438
}
439439

compiler/rustc_macros/src/query.rs

+3
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
495495
}
496496

497497
TokenStream::from(quote! {
498+
#[macro_export]
498499
macro_rules! rustc_query_append {
499500
([$($macro:tt)*][$($other:tt)*]) => {
500501
$($macro)* {
@@ -514,11 +515,13 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
514515
);
515516
}
516517
}
518+
#[macro_export]
517519
macro_rules! rustc_cached_queries {
518520
($($macro:tt)*) => {
519521
$($macro)*(#cached_queries);
520522
}
521523
}
524+
#[macro_export]
522525
macro_rules! rustc_query_description {
523526
() => { #query_description_stream }
524527
}

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ pub struct GlobalCtxt<'tcx> {
966966
/// Do not access this directly. It is only meant to be used by
967967
/// `DepGraph::try_mark_green()` and the query infrastructure.
968968
/// This is `None` if we are not incremental compilation mode
969-
pub(crate) on_disk_cache: Option<OnDiskCache<'tcx>>,
969+
pub on_disk_cache: Option<OnDiskCache<'tcx>>,
970970

971971
pub queries: &'tcx dyn query::QueryEngine<'tcx>,
972972
pub query_caches: query::QueryCaches<'tcx>,

compiler/rustc_middle/src/ty/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ pub use self::list::List;
100100

101101
pub use self::trait_def::TraitDef;
102102

103-
pub use self::query::queries;
104-
105103
pub use self::consts::{Const, ConstInt, ConstKind, InferConst, ScalarInt};
106104

107105
pub mod _match;

compiler/rustc_middle/src/ty/query/mod.rs

+16-28
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ use crate::traits::{self, ImplSource};
3131
use crate::ty::subst::{GenericArg, SubstsRef};
3232
use crate::ty::util::AlwaysRequiresDrop;
3333
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
34-
use rustc_data_structures::fingerprint::Fingerprint;
3534
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
3635
use rustc_data_structures::stable_hasher::StableVec;
3736
use rustc_data_structures::steal::Steal;
3837
use rustc_data_structures::svh::Svh;
3938
use rustc_data_structures::sync::Lrc;
40-
use rustc_errors::{Diagnostic, ErrorReported, Handler, Level};
39+
use rustc_errors::{ErrorReported, Handler};
4140
use rustc_hir as hir;
4241
use rustc_hir::def::DefKind;
4342
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
@@ -59,34 +58,12 @@ use std::ops::Deref;
5958
use std::path::PathBuf;
6059
use std::sync::Arc;
6160

62-
#[macro_use]
63-
mod plumbing;
64-
pub use plumbing::QueryCtxt;
65-
use plumbing::QueryStruct;
66-
pub(crate) use rustc_query_system::query::CycleError;
61+
pub(crate) use rustc_query_system::query::QueryJobId;
6762
use rustc_query_system::query::*;
6863

69-
mod stats;
70-
pub use self::stats::print_stats;
71-
72-
pub use rustc_query_system::query::{QueryInfo, QueryJob, QueryJobId};
73-
74-
mod keys;
75-
use self::keys::Key;
76-
77-
mod values;
78-
use self::values::Value;
79-
80-
use rustc_query_system::query::QueryAccessors;
81-
pub use rustc_query_system::query::QueryConfig;
82-
pub(crate) use rustc_query_system::query::QueryDescription;
83-
84-
mod on_disk_cache;
64+
pub mod on_disk_cache;
8565
pub use self::on_disk_cache::OnDiskCache;
8666

87-
mod profiling_support;
88-
pub use self::profiling_support::alloc_self_profile_query_strings;
89-
9067
#[derive(Copy, Clone)]
9168
pub struct TyCtxtAt<'tcx> {
9269
pub tcx: TyCtxt<'tcx>,
@@ -131,6 +108,18 @@ macro_rules! query_helper_param_ty {
131108
($K:ty) => { $K };
132109
}
133110

111+
macro_rules! query_storage {
112+
([][$K:ty, $V:ty]) => {
113+
<DefaultCacheSelector as CacheSelector<$K, $V>>::Cache
114+
};
115+
([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
116+
<$ty as CacheSelector<$K, $V>>::Cache
117+
};
118+
([$other:ident $(($($other_args:tt)*))* $(, $($modifiers:tt)*)*][$($args:tt)*]) => {
119+
query_storage!([$($($modifiers)*)*][$($args)*])
120+
};
121+
}
122+
134123
macro_rules! define_callbacks {
135124
(<$tcx:tt>
136125
$($(#[$attr:meta])*
@@ -169,7 +158,7 @@ macro_rules! define_callbacks {
169158

170159
#[derive(Default)]
171160
pub struct QueryCaches<$tcx> {
172-
$($(#[$attr])* $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
161+
$($(#[$attr])* pub $name: QueryCacheStore<query_storage::$name<$tcx>>,)*
173162
}
174163

175164
impl TyCtxtEnsure<$tcx> {
@@ -288,7 +277,6 @@ macro_rules! define_callbacks {
288277
// Queries marked with `fatal_cycle` do not need the latter implementation,
289278
// as they will raise an fatal error on query cycles instead.
290279

291-
rustc_query_append! { [define_queries!][<'tcx>] }
292280
rustc_query_append! { [define_callbacks!][<'tcx>] }
293281

294282
mod sealed {

compiler/rustc_middle/src/ty/query/on_disk_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'sess> OnDiskCache<'sess> {
502502

503503
/// Returns the cached query result if there is something in the cache for
504504
/// the given `SerializedDepNodeIndex`; otherwise returns `None`.
505-
crate fn try_load_query_result<'tcx, T>(
505+
pub fn try_load_query_result<'tcx, T>(
506506
&self,
507507
tcx: TyCtxt<'tcx>,
508508
dep_node_index: SerializedDepNodeIndex,
@@ -665,7 +665,7 @@ impl<'sess> OnDiskCache<'sess> {
665665
/// A decoder that can read from the incremental compilation cache. It is similar to the one
666666
/// we use for crate metadata decoding in that it can rebase spans and eventually
667667
/// will also handle things that contain `Ty` instances.
668-
crate struct CacheDecoder<'a, 'tcx> {
668+
pub struct CacheDecoder<'a, 'tcx> {
669669
tcx: TyCtxt<'tcx>,
670670
opaque: opaque::Decoder<'a>,
671671
source_map: &'a SourceMap,

compiler/rustc_query_impl/Cargo.toml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[package]
2+
authors = ["The Rust Project Developers"]
3+
name = "rustc_query_impl"
4+
version = "0.0.0"
5+
edition = "2018"
6+
7+
[lib]
8+
doctest = false
9+
10+
[dependencies]
11+
measureme = "9.0.0"
12+
rustc-rayon-core = "0.3.0"
13+
tracing = "0.1"
14+
rustc_ast = { path = "../rustc_ast" }
15+
rustc_attr = { path = "../rustc_attr" }
16+
rustc_data_structures = { path = "../rustc_data_structures" }
17+
rustc_errors = { path = "../rustc_errors" }
18+
rustc_feature = { path = "../rustc_feature" }
19+
rustc_hir = { path = "../rustc_hir" }
20+
rustc_index = { path = "../rustc_index" }
21+
rustc_macros = { path = "../rustc_macros" }
22+
rustc_middle = { path = "../rustc_middle" }
23+
rustc_query_system = { path = "../rustc_query_system" }
24+
rustc_span = { path = "../rustc_span" }
25+
rustc_serialize = { path = "../rustc_serialize" }
26+
rustc_session = { path = "../rustc_session" }
27+
rustc_target = { path = "../rustc_target" }

compiler/rustc_middle/src/ty/query/keys.rs renamed to compiler/rustc_query_impl/src/keys.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Defines the set of legal keys that can be used in queries.
22
3-
use crate::infer::canonical::Canonical;
4-
use crate::mir;
5-
use crate::ty::fast_reject::SimplifiedType;
6-
use crate::ty::subst::{GenericArg, SubstsRef};
7-
use crate::ty::{self, Ty, TyCtxt};
83
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
4+
use rustc_middle::infer::canonical::Canonical;
5+
use rustc_middle::mir;
6+
use rustc_middle::ty::fast_reject::SimplifiedType;
7+
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
8+
use rustc_middle::ty::{self, Ty, TyCtxt};
99
use rustc_span::symbol::{Ident, Symbol};
1010
use rustc_span::{Span, DUMMY_SP};
1111

compiler/rustc_query_impl/src/lib.rs

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! Support for serializing the dep-graph and reloading it.
2+
3+
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
4+
#![feature(in_band_lifetimes)]
5+
#![feature(exhaustive_patterns)]
6+
#![feature(nll)]
7+
#![feature(min_specialization)]
8+
#![feature(crate_visibility_modifier)]
9+
#![feature(once_cell)]
10+
#![feature(rustc_attrs)]
11+
#![feature(never_type)]
12+
#![recursion_limit = "256"]
13+
14+
#[macro_use]
15+
extern crate rustc_middle;
16+
#[macro_use]
17+
extern crate tracing;
18+
19+
use rustc_data_structures::fingerprint::Fingerprint;
20+
use rustc_data_structures::fx::FxHashMap;
21+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
22+
use rustc_errors::{Diagnostic, Handler, Level};
23+
use rustc_hir::def_id::CrateNum;
24+
use rustc_index::vec::IndexVec;
25+
use rustc_middle::dep_graph;
26+
use rustc_middle::ich::StableHashingContext;
27+
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
28+
use rustc_middle::ty::query::{Providers, QueryEngine};
29+
use rustc_middle::ty::TyCtxt;
30+
use rustc_serialize::opaque;
31+
use rustc_span::{Span, DUMMY_SP};
32+
use std::mem;
33+
34+
#[macro_use]
35+
mod plumbing;
36+
pub use plumbing::QueryCtxt;
37+
use plumbing::QueryStruct;
38+
use rustc_query_system::query::*;
39+
40+
mod stats;
41+
pub use self::stats::print_stats;
42+
43+
mod keys;
44+
use keys::Key;
45+
46+
mod values;
47+
use self::values::Value;
48+
49+
use rustc_query_system::query::QueryAccessors;
50+
pub use rustc_query_system::query::QueryConfig;
51+
pub(crate) use rustc_query_system::query::QueryDescription;
52+
53+
use rustc_middle::ty::query::on_disk_cache;
54+
55+
mod profiling_support;
56+
pub use self::profiling_support::alloc_self_profile_query_strings;
57+
58+
rustc_query_append! { [define_queries!][<'tcx>] }
59+
60+
impl<'tcx> Queries<'tcx> {
61+
// Force codegen in the dyn-trait transformation in this crate.
62+
pub fn as_dyn(&'tcx self) -> &'tcx dyn QueryEngine<'tcx> {
63+
self
64+
}
65+
}

0 commit comments

Comments
 (0)