From e29f8f1d3dab0dfac764771917f9c543372a0f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 22 Mar 2019 21:22:39 +0100 Subject: [PATCH] Load the query result cache with a query --- src/librustc/arena.rs | 1 + src/librustc/dep_graph/graph.rs | 6 ++---- src/librustc/query/mod.rs | 14 ++++++++++---- src/librustc/ty/context.rs | 6 ++---- src/librustc/ty/query/mod.rs | 2 +- src/librustc/ty/query/plumbing.rs | 4 ++-- src/librustc_interface/passes.rs | 16 +++++++++++----- 7 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index fe85463127cc5..4468ef5a9020c 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -31,6 +31,7 @@ macro_rules! arena_types { rustc::hir::def_id::DefId, rustc::ty::subst::SubstsRef<$tcx> )>, + [few] on_disk_cache: rustc::ty::query::OnDiskCache<$tcx>, [few] dep_graph: rustc::dep_graph::DepGraph, [few] lowered_hir: rustc::hir::LoweredHir, [few] hir_map: rustc::hir::map::Map<$tcx>, diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 1728c3604f0ca..1057fd62a1c3a 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -809,8 +809,7 @@ impl DepGraph { // ... emitting any stored diagnostic ... - let diagnostics = tcx.queries.on_disk_cache - .load_diagnostics(tcx, prev_dep_node_index); + let diagnostics = tcx.on_disk_cache().load_diagnostics(tcx, prev_dep_node_index); if unlikely!(diagnostics.len() > 0) { self.emit_diagnostics( @@ -852,8 +851,7 @@ impl DepGraph { let handle = tcx.sess.diagnostic(); // Promote the previous diagnostics to the current session. - tcx.queries.on_disk_cache - .store_diagnostics(dep_node_index, diagnostics.clone().into()); + tcx.on_disk_cache().store_diagnostics(dep_node_index, diagnostics.clone().into()); for diagnostic in diagnostics { DiagnosticBuilder::new_diagnostic(handle, diagnostic).emit(); diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs index 968bb41e21bf4..31f032b61177a 100644 --- a/src/librustc/query/mod.rs +++ b/src/librustc/query/mod.rs @@ -43,6 +43,12 @@ rustc_queries! { desc { "loading the dependency graph" } } + query load_query_result_cache(_: ()) -> &'tcx OnDiskCache<'tcx> { + no_hash + eval_always + desc { "loading the query result cache" } + } + query parse(_: ()) -> Result>, ErrorReported> { no_hash eval_always @@ -106,7 +112,7 @@ rustc_queries! { query generics_of(key: DefId) -> &'tcx ty::Generics { cache_on_disk_if { key.is_local() } load_cached(tcx, id) { - let generics: Option = tcx.queries.on_disk_cache + let generics: Option = tcx.on_disk_cache() .try_load_query_result(tcx, id); generics.map(|x| &*tcx.arena.alloc(x)) } @@ -184,8 +190,8 @@ rustc_queries! { query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> { cache_on_disk_if { key.is_local() } load_cached(tcx, id) { - let mir: Option> = tcx.queries.on_disk_cache - .try_load_query_result(tcx, id); + let mir: Option> = tcx.on_disk_cache() + .try_load_query_result(tcx, id); mir.map(|x| &*tcx.arena.alloc(x)) } } @@ -420,7 +426,7 @@ rustc_queries! { cache_on_disk_if { key.is_local() } load_cached(tcx, id) { let typeck_tables: Option> = tcx - .queries.on_disk_cache + .on_disk_cache() .try_load_query_result(tcx, id); typeck_tables.map(|tables| &*tcx.arena.alloc(tables)) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 7689519c1eae5..020156591e472 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1100,7 +1100,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline(always)] pub fn hir(self) -> &'tcx hir_map::Map<'tcx> { self.hir_map.get_or_init(|| { - // We can use `with_ignore` here because the hir map does its own tracking + // We can use `ignore_deps` here because the hir map does its own tracking DepGraph::ignore_deps(|| self.hir_map(LOCAL_CRATE)) }) } @@ -1187,7 +1187,6 @@ impl<'tcx> TyCtxt<'tcx> { local_providers: ty::query::Providers<'tcx>, extern_providers: ty::query::Providers<'tcx>, arenas: &'tcx AllArenas, - on_disk_query_result_cache: query::OnDiskCache<'tcx>, crate_name: Option, tx: mpsc::Sender>, io: InputsAndOutputs, @@ -1227,7 +1226,6 @@ impl<'tcx> TyCtxt<'tcx> { queries: query::Queries::new( providers, extern_providers, - on_disk_query_result_cache, ), rcache: Default::default(), selection_cache: Default::default(), @@ -1424,7 +1422,7 @@ impl<'tcx> TyCtxt<'tcx> { -> Result<(), E::Error> where E: ty::codec::TyEncoder { - self.queries.on_disk_cache.serialize(self.global_tcx(), encoder) + self.on_disk_cache().serialize(self.global_tcx(), encoder) } /// If true, we should use the AST-based borrowck (we may *also* use diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 9f07e9ce495c4..60560f065a2ff 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -47,7 +47,7 @@ use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::fx::{FxIndexMap, FxHashMap, FxHashSet}; use rustc_data_structures::stable_hasher::StableVec; -use rustc_data_structures::sync::Lrc; +use rustc_data_structures::sync::{Lrc, AtomicOnce}; use rustc_data_structures::fingerprint::Fingerprint; use rustc_target::spec::PanicStrategy; diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 8dee31c1c6d24..bf5acc64d8fd8 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -249,10 +249,10 @@ pub(super) enum TryGetJob<'a, 'tcx, D: QueryDescription<'tcx>> { impl<'tcx> TyCtxt<'tcx> { #[inline(always)] - pub fn on_disk_cache(self) -> &'gcx OnDiskCache<'gcx> { + pub fn on_disk_cache(self) -> &'tcx OnDiskCache<'tcx> { self.queries.on_disk_cache.get_or_init(|| { // Don't track the loading of the query result cache - self.dep_graph().with_ignore(|| self.load_query_result_cache(LocalCrate)) + self.dep_graph().with_ignore(|| self.load_query_result_cache(())) }) } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 4da9c4f68f815..05d3f67d2b5ea 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -12,6 +12,7 @@ use rustc::middle::{self, reachable, resolve_lifetime, stability}; use rustc::middle::privacy::AccessLevels; use rustc::ty::{self, AllArenas, Resolutions, TyCtxt, GlobalCtxt}; use rustc::ty::steal::Steal; +use rustc::ty::query::OnDiskCache; use rustc::traits; use rustc::util::common::{time, ErrorReported}; use rustc::util::profiling::ProfileCategory; @@ -895,6 +896,15 @@ fn load_dep_graph<'tcx>( }) } +fn load_query_result_cache<'tcx>( + tcx: TyCtxt<'tcx>, + _: (), +) -> &'tcx OnDiskCache<'tcx> { + time(tcx.sess, "load query result cache", || { + tcx.arena.alloc(rustc_incremental::load_query_result_cache(tcx.sess)) + }) +} + pub fn default_provide(providers: &mut ty::query::Providers<'_>) { providers.analysis = analysis; providers.hir_map = hir_map; @@ -906,6 +916,7 @@ pub fn default_provide(providers: &mut ty::query::Providers<'_>) { providers.early_crate_name = early_crate_name; providers.dep_graph_future = dep_graph_future; providers.load_dep_graph = load_dep_graph; + providers.load_query_result_cache = load_query_result_cache; proc_macro_decls::provide(providers); plugin::build::provide(providers); hir::provide(providers); @@ -966,10 +977,6 @@ pub fn create_global_ctxt( let global_ctxt: Option>; let arenas = AllArenas::new(); - let query_result_on_disk_cache = time(sess, "load query result cache", || { - rustc_incremental::load_query_result_cache(sess) - }); - let mut local_providers = ty::query::Providers::default(); default_provide(&mut local_providers); codegen_backend.provide(&mut local_providers); @@ -985,7 +992,6 @@ pub fn create_global_ctxt( local_providers, extern_providers, &arenas, - query_result_on_disk_cache, crate_name, tx, io,