Skip to content

Commit bee1fbb

Browse files
committed
Make try_load_from_on_disk_cache a function pointer.
1 parent 438c430 commit bee1fbb

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub struct DepKindStruct {
9494
// FIXME: Make this a simple boolean once DepNodeParams::can_reconstruct_query_key
9595
// can be made a specialized associated const.
9696
can_reconstruct_query_key: fn() -> bool,
97+
98+
/// Invoke a query to put the on-disk cached value in memory.
99+
pub(super) try_load_from_on_disk_cache: fn(TyCtxt<'_>, &DepNode),
97100
}
98101

99102
impl std::ops::Deref for DepKind {
@@ -152,7 +155,8 @@ macro_rules! contains_eval_always_attr {
152155
#[allow(non_upper_case_globals)]
153156
pub mod dep_kind {
154157
use super::*;
155-
use crate::ty::query::query_keys;
158+
use crate::ty::query::{queries, query_keys};
159+
use rustc_query_system::query::QueryDescription;
156160

157161
// We use this for most things when incr. comp. is turned off.
158162
pub const Null: DepKindStruct = DepKindStruct {
@@ -161,6 +165,7 @@ pub mod dep_kind {
161165
is_eval_always: false,
162166

163167
can_reconstruct_query_key: || true,
168+
try_load_from_on_disk_cache: |_, _| {},
164169
};
165170

166171
// Represents metadata from an extern crate.
@@ -170,6 +175,7 @@ pub mod dep_kind {
170175
is_eval_always: true,
171176

172177
can_reconstruct_query_key: || true,
178+
try_load_from_on_disk_cache: |_, _| {},
173179
};
174180

175181
pub const TraitSelect: DepKindStruct = DepKindStruct {
@@ -178,6 +184,7 @@ pub mod dep_kind {
178184
is_eval_always: false,
179185

180186
can_reconstruct_query_key: || false,
187+
try_load_from_on_disk_cache: |_, _| {},
181188
};
182189

183190
pub const CompileCodegenUnit: DepKindStruct = DepKindStruct {
@@ -186,6 +193,7 @@ pub mod dep_kind {
186193
is_eval_always: false,
187194

188195
can_reconstruct_query_key: || false,
196+
try_load_from_on_disk_cache: |_, _| {},
189197
};
190198

191199
macro_rules! define_query_dep_kinds {
@@ -205,11 +213,32 @@ pub mod dep_kind {
205213
::can_reconstruct_query_key()
206214
}
207215

216+
fn recover<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<query_keys::$variant<'tcx>> {
217+
<query_keys::$variant<'_> as DepNodeParams<TyCtxt<'_>>>::recover(tcx, dep_node)
218+
}
219+
220+
fn try_load_from_on_disk_cache(tcx: TyCtxt<'_>, dep_node: &DepNode) {
221+
if !can_reconstruct_query_key() {
222+
return
223+
}
224+
225+
debug_assert!(tcx.dep_graph
226+
.node_color(dep_node)
227+
.map(|c| c.is_green())
228+
.unwrap_or(false));
229+
230+
let key = recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
231+
if queries::$variant::cache_on_disk(tcx, &key, None) {
232+
let _ = tcx.$variant(key);
233+
}
234+
}
235+
208236
DepKindStruct {
209237
has_params,
210238
is_anon,
211239
is_eval_always,
212240
can_reconstruct_query_key,
241+
try_load_from_on_disk_cache,
213242
}
214243
};)*
215244
);

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::ich::StableHashingContext;
2-
use crate::ty::query::try_load_from_on_disk_cache;
32
use crate::ty::{self, TyCtxt};
43
use rustc_data_structures::profiling::SelfProfilerRef;
54
use rustc_data_structures::sync::Lock;
@@ -169,7 +168,7 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
169168

170169
// Interactions with on_disk_cache
171170
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) {
172-
try_load_from_on_disk_cache(*self, dep_node)
171+
(dep_node.kind.try_load_from_on_disk_cache)(*self, dep_node)
173172
}
174173

175174
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,32 +209,6 @@ pub fn force_from_dep_node<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> bool
209209
false
210210
}
211211

212-
pub(crate) fn try_load_from_on_disk_cache<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &DepNode) {
213-
macro_rules! try_load_from_on_disk_cache {
214-
($($name:ident,)*) => {
215-
match dep_node.kind {
216-
$(DepKind::$name => {
217-
if <query_keys::$name<'tcx> as DepNodeParams<TyCtxt<'_>>>::can_reconstruct_query_key() {
218-
debug_assert!(tcx.dep_graph
219-
.node_color(dep_node)
220-
.map(|c| c.is_green())
221-
.unwrap_or(false));
222-
223-
let key = <query_keys::$name<'tcx> as DepNodeParams<TyCtxt<'_>>>::recover(tcx, dep_node).unwrap_or_else(|| panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash));
224-
if queries::$name::cache_on_disk(tcx, &key, None) {
225-
let _ = tcx.$name(key);
226-
}
227-
}
228-
})*
229-
230-
_ => (),
231-
}
232-
}
233-
}
234-
235-
rustc_cached_queries!(try_load_from_on_disk_cache!);
236-
}
237-
238212
mod sealed {
239213
use super::{DefId, LocalDefId};
240214

0 commit comments

Comments
 (0)