Skip to content

Commit 075809d

Browse files
committed
Load the query result cache with a query
1 parent e482df6 commit 075809d

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,7 @@ impl DepGraph {
810810

811811
// ... emitting any stored diagnostic ...
812812

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

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

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

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

src/librustc/query/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ rustc_queries! {
4242
desc { "loading the dependency graph" }
4343
}
4444

45+
query load_query_result_cache(_: LocalCrate) -> &'tcx OnDiskCache<'tcx> {
46+
no_hash
47+
eval_always
48+
desc { "loading the query result cache" }
49+
}
50+
4551
query parse(_: LocalCrate) -> Result<Lrc<Steal<ast::Crate>>, ErrorReported> {
4652
no_hash
4753
eval_always
@@ -105,7 +111,7 @@ rustc_queries! {
105111
query generics_of(key: DefId) -> &'tcx ty::Generics {
106112
cache { key.is_local() }
107113
load_cached(tcx, id) {
108-
let generics: Option<ty::Generics> = tcx.queries.on_disk_cache
114+
let generics: Option<ty::Generics> = tcx.on_disk_cache()
109115
.try_load_query_result(tcx, id);
110116
generics.map(|x| tcx.alloc_generics(x))
111117
}
@@ -181,7 +187,7 @@ rustc_queries! {
181187
query optimized_mir(key: DefId) -> &'tcx mir::Mir<'tcx> {
182188
cache { key.is_local() }
183189
load_cached(tcx, id) {
184-
let mir: Option<crate::mir::Mir<'tcx>> = tcx.queries.on_disk_cache
190+
let mir: Option<crate::mir::Mir<'tcx>> = tcx.on_disk_cache()
185191
.try_load_query_result(tcx, id);
186192
mir.map(|x| tcx.alloc_mir(x))
187193
}
@@ -412,7 +418,7 @@ rustc_queries! {
412418
cache { key.is_local() }
413419
load_cached(tcx, id) {
414420
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
415-
.queries.on_disk_cache
421+
.on_disk_cache()
416422
.try_load_query_result(tcx, id);
417423

418424
typeck_tables.map(|tables| tcx.alloc_tables(tables))
@@ -475,7 +481,7 @@ rustc_queries! {
475481
}
476482
cache { true }
477483
load_cached(tcx, id) {
478-
tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok)
484+
tcx.on_disk_cache().try_load_query_result(tcx, id).map(Ok)
479485
}
480486
}
481487

@@ -490,7 +496,7 @@ rustc_queries! {
490496
}
491497
cache { true }
492498
load_cached(tcx, id) {
493-
tcx.queries.on_disk_cache.try_load_query_result(tcx, id).map(Ok)
499+
tcx.on_disk_cache().try_load_query_result(tcx, id).map(Ok)
494500
}
495501
}
496502
}

src/librustc/ty/context.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::ty::{InferConst, ParamConst};
3737
use crate::ty::GenericParamDefKind;
3838
use crate::ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
3939
use crate::ty::query;
40+
use crate::ty::query::OnDiskCache;
4041
use crate::ty::steal::Steal;
4142
use crate::ty::subst::{UserSubsts, UnpackedKind};
4243
use crate::ty::{BoundVar, BindingMode};
@@ -1033,6 +1034,8 @@ pub struct GlobalCtxt<'tcx> {
10331034

10341035
metadata_dep_nodes: Once<()>,
10351036

1037+
pub on_disk_cache_store: Once<OnDiskCache<'tcx>>,
1038+
10361039
pub queries: query::Queries<'tcx>,
10371040

10381041
// Internal cache for metadata decoding. No need to track deps on this.
@@ -1114,7 +1117,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
11141117
#[inline(always)]
11151118
pub fn hir(self) -> &'gcx hir_map::Map<'gcx> {
11161119
self.hir_map.get_or_init(|| {
1117-
// We can use `with_ignore` here because the hir map does its own tracking
1120+
// We can use `ignore_deps` here because the hir map does its own tracking
11181121
DepGraph::ignore_deps(|| self.hir_map(LOCAL_CRATE))
11191122
})
11201123
}
@@ -1220,7 +1223,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12201223
local_providers: ty::query::Providers<'tcx>,
12211224
extern_providers: ty::query::Providers<'tcx>,
12221225
arenas: &'tcx AllArenas<'tcx>,
1223-
on_disk_query_result_cache: query::OnDiskCache<'tcx>,
12241226
crate_name: Option<String>,
12251227
tx: mpsc::Sender<Box<dyn Any + Send>>,
12261228
io: InputsAndOutputs,
@@ -1247,10 +1249,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12471249
lowered_hir: AtomicOnce::new(),
12481250
hir_map: AtomicOnce::new(),
12491251
metadata_dep_nodes: Once::new(),
1252+
on_disk_cache_store: Once::new(),
12501253
queries: query::Queries::new(
12511254
providers,
12521255
extern_providers,
1253-
on_disk_query_result_cache,
12541256
),
12551257
rcache: Default::default(),
12561258
selection_cache: Default::default(),
@@ -1437,7 +1439,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
14371439
-> Result<(), E::Error>
14381440
where E: ty::codec::TyEncoder
14391441
{
1440-
self.queries.on_disk_cache.serialize(self.global_tcx(), encoder)
1442+
self.on_disk_cache().serialize(self.global_tcx(), encoder)
14411443
}
14421444

14431445
/// This checks whether one is allowed to have pattern bindings

src/librustc/ty/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use rustc_data_structures::bit_set::BitSet;
4848
use rustc_data_structures::indexed_vec::IndexVec;
4949
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5050
use rustc_data_structures::stable_hasher::StableVec;
51-
use rustc_data_structures::sync::Lrc;
51+
use rustc_data_structures::sync::{Lrc, AtomicOnce};
5252
use rustc_data_structures::fingerprint::Fingerprint;
5353
use rustc_target::spec::PanicStrategy;
5454

src/librustc_interface/passes.rs

Lines changed: 12 additions & 5 deletions
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;
@@ -899,6 +900,16 @@ fn load_dep_graph<'tcx>(
899900
tcx.dep_graph_store.get()
900901
}
901902

903+
fn load_query_result_cache<'tcx>(
904+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
905+
_: LocalCrate,
906+
) -> &'tcx OnDiskCache<'tcx> {
907+
time(tcx.sess, "load query result cache", || {
908+
tcx.on_disk_cache_store.set(rustc_incremental::load_query_result_cache(tcx.sess));
909+
tcx.on_disk_cache_store.get()
910+
})
911+
}
912+
902913
pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
903914
providers.analysis = analysis;
904915
providers.hir_map = hir_map;
@@ -910,6 +921,7 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) {
910921
providers.early_crate_name = early_crate_name;
911922
providers.dep_graph_future = dep_graph_future;
912923
providers.load_dep_graph = load_dep_graph;
924+
providers.load_query_result_cache = load_query_result_cache;
913925
proc_macro_decls::provide(providers);
914926
plugin::build::provide(providers);
915927
hir::provide(providers);
@@ -970,10 +982,6 @@ pub fn create_global_ctxt(
970982
let global_ctxt: Option<GlobalCtxt<'_>>;
971983
let arenas = AllArenas::new();
972984

973-
let query_result_on_disk_cache = time(sess, "load query result cache", || {
974-
rustc_incremental::load_query_result_cache(sess)
975-
});
976-
977985
let mut local_providers = ty::query::Providers::default();
978986
default_provide(&mut local_providers);
979987
codegen_backend.provide(&mut local_providers);
@@ -989,7 +997,6 @@ pub fn create_global_ctxt(
989997
local_providers,
990998
extern_providers,
991999
&arenas,
992-
query_result_on_disk_cache,
9931000
crate_name,
9941001
tx,
9951002
io,

0 commit comments

Comments
 (0)