Skip to content

Commit

Permalink
Load the query result cache with a query
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jul 8, 2019
1 parent 9a80997 commit e29f8f1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lrc<Steal<ast::Crate>>, ErrorReported> {
no_hash
eval_always
Expand Down Expand Up @@ -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<ty::Generics> = tcx.queries.on_disk_cache
let generics: Option<ty::Generics> = tcx.on_disk_cache()
.try_load_query_result(tcx, id);
generics.map(|x| &*tcx.arena.alloc(x))
}
Expand Down Expand Up @@ -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<crate::mir::Body<'tcx>> = tcx.queries.on_disk_cache
.try_load_query_result(tcx, id);
let mir: Option<crate::mir::Body<'tcx>> = tcx.on_disk_cache()
.try_load_query_result(tcx, id);
mir.map(|x| &*tcx.arena.alloc(x))
}
}
Expand Down Expand Up @@ -420,7 +426,7 @@ rustc_queries! {
cache_on_disk_if { key.is_local() }
load_cached(tcx, id) {
let typeck_tables: Option<ty::TypeckTables<'tcx>> = tcx
.queries.on_disk_cache
.on_disk_cache()
.try_load_query_result(tcx, id);

typeck_tables.map(|tables| &*tcx.arena.alloc(tables))
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
Expand Down Expand Up @@ -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<String>,
tx: mpsc::Sender<Box<dyn Any + Send>>,
io: InputsAndOutputs,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(()))
})
}

Expand Down
16 changes: 11 additions & 5 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -966,10 +977,6 @@ pub fn create_global_ctxt(
let global_ctxt: Option<GlobalCtxt<'_>>;
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);
Expand All @@ -985,7 +992,6 @@ pub fn create_global_ctxt(
local_providers,
extern_providers,
&arenas,
query_result_on_disk_cache,
crate_name,
tx,
io,
Expand Down

0 comments on commit e29f8f1

Please sign in to comment.