Skip to content

Commit e29f8f1

Browse files
committed
Load the query result cache with a query
1 parent 9a80997 commit e29f8f1

File tree

7 files changed

+29
-20
lines changed

7 files changed

+29
-20
lines changed

src/librustc/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ macro_rules! arena_types {
3131
rustc::hir::def_id::DefId,
3232
rustc::ty::subst::SubstsRef<$tcx>
3333
)>,
34+
[few] on_disk_cache: rustc::ty::query::OnDiskCache<$tcx>,
3435
[few] dep_graph: rustc::dep_graph::DepGraph,
3536
[few] lowered_hir: rustc::hir::LoweredHir,
3637
[few] hir_map: rustc::hir::map::Map<$tcx>,

src/librustc/dep_graph/graph.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,7 @@ impl DepGraph {
809809

810810
// ... emitting any stored diagnostic ...
811811

812-
let diagnostics = tcx.queries.on_disk_cache
813-
.load_diagnostics(tcx, prev_dep_node_index);
812+
let diagnostics = tcx.on_disk_cache().load_diagnostics(tcx, prev_dep_node_index);
814813

815814
if unlikely!(diagnostics.len() > 0) {
816815
self.emit_diagnostics(
@@ -852,8 +851,7 @@ impl DepGraph {
852851
let handle = tcx.sess.diagnostic();
853852

854853
// Promote the previous diagnostics to the current session.
855-
tcx.queries.on_disk_cache
856-
.store_diagnostics(dep_node_index, diagnostics.clone().into());
854+
tcx.on_disk_cache().store_diagnostics(dep_node_index, diagnostics.clone().into());
857855

858856
for diagnostic in diagnostics {
859857
DiagnosticBuilder::new_diagnostic(handle, diagnostic).emit();

src/librustc/query/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ rustc_queries! {
4343
desc { "loading the dependency graph" }
4444
}
4545

46+
query load_query_result_cache(_: ()) -> &'tcx OnDiskCache<'tcx> {
47+
no_hash
48+
eval_always
49+
desc { "loading the query result cache" }
50+
}
51+
4652
query parse(_: ()) -> Result<Lrc<Steal<ast::Crate>>, ErrorReported> {
4753
no_hash
4854
eval_always
@@ -106,7 +112,7 @@ rustc_queries! {
106112
query generics_of(key: DefId) -> &'tcx ty::Generics {
107113
cache_on_disk_if { key.is_local() }
108114
load_cached(tcx, id) {
109-
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
115+
let generics: Option<ty::Generics> = tcx.on_disk_cache()
110116
.try_load_query_result(tcx, id);
111117
generics.map(|x| &*tcx.arena.alloc(x))
112118
}
@@ -184,8 +190,8 @@ rustc_queries! {
184190
query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> {
185191
cache_on_disk_if { key.is_local() }
186192
load_cached(tcx, id) {
187-
let mir: Option<crate::mir::Body<'tcx>> = tcx.queries.on_disk_cache
188-
.try_load_query_result(tcx, id);
193+
let mir: Option<crate::mir::Body<'tcx>> = tcx.on_disk_cache()
194+
.try_load_query_result(tcx, id);
189195
mir.map(|x| &*tcx.arena.alloc(x))
190196
}
191197
}
@@ -420,7 +426,7 @@ rustc_queries! {
420426
cache_on_disk_if { key.is_local() }
421427
load_cached(tcx, id) {
422428
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
423-
.queries.on_disk_cache
429+
.on_disk_cache()
424430
.try_load_query_result(tcx, id);
425431

426432
typeck_tables.map(|tables| &*tcx.arena.alloc(tables))

src/librustc/ty/context.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ impl<'tcx> TyCtxt<'tcx> {
11001100
#[inline(always)]
11011101
pub fn hir(self) -> &'tcx hir_map::Map<'tcx> {
11021102
self.hir_map.get_or_init(|| {
1103-
// We can use `with_ignore` here because the hir map does its own tracking
1103+
// We can use `ignore_deps` here because the hir map does its own tracking
11041104
DepGraph::ignore_deps(|| self.hir_map(LOCAL_CRATE))
11051105
})
11061106
}
@@ -1187,7 +1187,6 @@ impl<'tcx> TyCtxt<'tcx> {
11871187
local_providers: ty::query::Providers<'tcx>,
11881188
extern_providers: ty::query::Providers<'tcx>,
11891189
arenas: &'tcx AllArenas,
1190-
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
11911190
crate_name: Option<String>,
11921191
tx: mpsc::Sender<Box<dyn Any + Send>>,
11931192
io: InputsAndOutputs,
@@ -1227,7 +1226,6 @@ impl<'tcx> TyCtxt<'tcx> {
12271226
queries: query::Queries::new(
12281227
providers,
12291228
extern_providers,
1230-
on_disk_query_result_cache,
12311229
),
12321230
rcache: Default::default(),
12331231
selection_cache: Default::default(),
@@ -1424,7 +1422,7 @@ impl<'tcx> TyCtxt<'tcx> {
14241422
-> Result<(), E::Error>
14251423
where E: ty::codec::TyEncoder
14261424
{
1427-
self.queries.on_disk_cache.serialize(self.global_tcx(), encoder)
1425+
self.on_disk_cache().serialize(self.global_tcx(), encoder)
14281426
}
14291427

14301428
/// If true, we should use the AST-based borrowck (we may *also* use

src/librustc/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_data_structures::bit_set::BitSet;
4747
use rustc_data_structures::indexed_vec::IndexVec;
4848
use rustc_data_structures::fx::{FxIndexMap, FxHashMap, FxHashSet};
4949
use rustc_data_structures::stable_hasher::StableVec;
50-
use rustc_data_structures::sync::Lrc;
50+
use rustc_data_structures::sync::{Lrc, AtomicOnce};
5151
use rustc_data_structures::fingerprint::Fingerprint;
5252
use rustc_target::spec::PanicStrategy;
5353

src/librustc/ty/query/plumbing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ pub(super) enum TryGetJob<'a, 'tcx, D: QueryDescription<'tcx>> {
249249

250250
impl<'tcx> TyCtxt<'tcx> {
251251
#[inline(always)]
252-
pub fn on_disk_cache(self) -> &'gcx OnDiskCache<'gcx> {
252+
pub fn on_disk_cache(self) -> &'tcx OnDiskCache<'tcx> {
253253
self.queries.on_disk_cache.get_or_init(|| {
254254
// Don't track the loading of the query result cache
255-
self.dep_graph().with_ignore(|| self.load_query_result_cache(LocalCrate))
255+
self.dep_graph().with_ignore(|| self.load_query_result_cache(()))
256256
})
257257
}
258258

src/librustc_interface/passes.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc::middle::{self, reachable, resolve_lifetime, stability};
1212
use rustc::middle::privacy::AccessLevels;
1313
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt, GlobalCtxt};
1414
use rustc::ty::steal::Steal;
15+
use rustc::ty::query::OnDiskCache;
1516
use rustc::traits;
1617
use rustc::util::common::{time, ErrorReported};
1718
use rustc::util::profiling::ProfileCategory;
@@ -895,6 +896,15 @@ fn load_dep_graph<'tcx>(
895896
})
896897
}
897898

899+
fn load_query_result_cache<'tcx>(
900+
tcx: TyCtxt<'tcx>,
901+
_: (),
902+
) -> &'tcx OnDiskCache<'tcx> {
903+
time(tcx.sess, "load query result cache", || {
904+
tcx.arena.alloc(rustc_incremental::load_query_result_cache(tcx.sess))
905+
})
906+
}
907+
898908
pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
899909
providers.analysis = analysis;
900910
providers.hir_map = hir_map;
@@ -906,6 +916,7 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
906916
providers.early_crate_name = early_crate_name;
907917
providers.dep_graph_future = dep_graph_future;
908918
providers.load_dep_graph = load_dep_graph;
919+
providers.load_query_result_cache = load_query_result_cache;
909920
proc_macro_decls::provide(providers);
910921
plugin::build::provide(providers);
911922
hir::provide(providers);
@@ -966,10 +977,6 @@ pub fn create_global_ctxt(
966977
let global_ctxt: Option<GlobalCtxt<'_>>;
967978
let arenas = AllArenas::new();
968979

969-
let query_result_on_disk_cache = time(sess, "load query result cache", || {
970-
rustc_incremental::load_query_result_cache(sess)
971-
});
972-
973980
let mut local_providers = ty::query::Providers::default();
974981
default_provide(&mut local_providers);
975982
codegen_backend.provide(&mut local_providers);
@@ -985,7 +992,6 @@ pub fn create_global_ctxt(
985992
local_providers,
986993
extern_providers,
987994
&arenas,
988-
query_result_on_disk_cache,
989995
crate_name,
990996
tx,
991997
io,

0 commit comments

Comments
 (0)