Make hash_result an Option.
This commit is contained in:
parent
e53404cca6
commit
aa404c24dd
7 changed files with 39 additions and 41 deletions
|
@ -224,7 +224,7 @@ pub(crate) fn run_aot(
|
||||||
tcx,
|
tcx,
|
||||||
(backend_config.clone(), cgu.name()),
|
(backend_config.clone(), cgu.name()),
|
||||||
module_codegen,
|
module_codegen,
|
||||||
rustc_middle::dep_graph::hash_result,
|
Some(rustc_middle::dep_graph::hash_result),
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((id, product)) = work_product {
|
if let Some((id, product)) = work_product {
|
||||||
|
|
|
@ -59,7 +59,13 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
|
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
|
||||||
let (module, _) = tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
|
let (module, _) = tcx.dep_graph.with_task(
|
||||||
|
dep_node,
|
||||||
|
tcx,
|
||||||
|
cgu_name,
|
||||||
|
module_codegen,
|
||||||
|
Some(dep_graph::hash_result),
|
||||||
|
);
|
||||||
let time_to_codegen = start_time.elapsed();
|
let time_to_codegen = start_time.elapsed();
|
||||||
drop(prof_timer);
|
drop(prof_timer);
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,13 @@ pub fn compile_codegen_unit(
|
||||||
let start_time = Instant::now();
|
let start_time = Instant::now();
|
||||||
|
|
||||||
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
|
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
|
||||||
let (module, _) =
|
let (module, _) = tcx.dep_graph.with_task(
|
||||||
tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
|
dep_node,
|
||||||
|
tcx,
|
||||||
|
cgu_name,
|
||||||
|
module_codegen,
|
||||||
|
Some(dep_graph::hash_result),
|
||||||
|
);
|
||||||
let time_to_codegen = start_time.elapsed();
|
let time_to_codegen = start_time.elapsed();
|
||||||
|
|
||||||
// We assume that the cost to run LLVM on a CGU is proportional to
|
// We assume that the cost to run LLVM on a CGU is proportional to
|
||||||
|
|
|
@ -291,14 +291,14 @@ macro_rules! is_eval_always {
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! hash_result {
|
macro_rules! hash_result {
|
||||||
([][$hcx:expr, $result:expr]) => {{
|
([]) => {{
|
||||||
dep_graph::hash_result($hcx, &$result)
|
Some(dep_graph::hash_result)
|
||||||
}};
|
}};
|
||||||
([(no_hash) $($rest:tt)*][$hcx:expr, $result:expr]) => {{
|
([(no_hash) $($rest:tt)*]) => {{
|
||||||
None
|
None
|
||||||
}};
|
}};
|
||||||
([$other:tt $($modifiers:tt)*][$($args:tt)*]) => {
|
([$other:tt $($modifiers:tt)*]) => {
|
||||||
hash_result!([$($modifiers)*][$($args)*])
|
hash_result!([$($modifiers)*])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,6 +378,7 @@ macro_rules! define_queries {
|
||||||
const ANON: bool = is_anon!([$($modifiers)*]);
|
const ANON: bool = is_anon!([$($modifiers)*]);
|
||||||
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
|
const EVAL_ALWAYS: bool = is_eval_always!([$($modifiers)*]);
|
||||||
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$name;
|
const DEP_KIND: dep_graph::DepKind = dep_graph::DepKind::$name;
|
||||||
|
const HASH_RESULT: Option<fn(&mut StableHashingContext<'_>, &Self::Value) -> Fingerprint> = hash_result!([$($modifiers)*]);
|
||||||
|
|
||||||
type Cache = query_storage::$name<$tcx>;
|
type Cache = query_storage::$name<$tcx>;
|
||||||
|
|
||||||
|
@ -406,13 +407,6 @@ macro_rules! define_queries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hash_result(
|
|
||||||
_hcx: &mut StableHashingContext<'_>,
|
|
||||||
_result: &Self::Value
|
|
||||||
) -> Option<Fingerprint> {
|
|
||||||
hash_result!([$($modifiers)*][_hcx, _result])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_cycle_error(
|
fn handle_cycle_error(
|
||||||
tcx: QueryCtxt<'tcx>,
|
tcx: QueryCtxt<'tcx>,
|
||||||
mut error: DiagnosticBuilder<'_>,
|
mut error: DiagnosticBuilder<'_>,
|
||||||
|
|
|
@ -96,14 +96,13 @@ struct DepGraphData<K: DepKind> {
|
||||||
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
|
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Option<Fingerprint>
|
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Fingerprint
|
||||||
where
|
where
|
||||||
R: for<'a> HashStable<StableHashingContext<'a>>,
|
R: for<'a> HashStable<StableHashingContext<'a>>,
|
||||||
{
|
{
|
||||||
let mut stable_hasher = StableHasher::new();
|
let mut stable_hasher = StableHasher::new();
|
||||||
result.hash_stable(hcx, &mut stable_hasher);
|
result.hash_stable(hcx, &mut stable_hasher);
|
||||||
|
stable_hasher.finish()
|
||||||
Some(stable_hasher.finish())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: DepKind> DepGraph<K> {
|
impl<K: DepKind> DepGraph<K> {
|
||||||
|
@ -215,7 +214,7 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
cx: Ctxt,
|
cx: Ctxt,
|
||||||
arg: A,
|
arg: A,
|
||||||
task: fn(Ctxt, A) -> R,
|
task: fn(Ctxt, A) -> R,
|
||||||
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
|
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
|
||||||
) -> (R, DepNodeIndex) {
|
) -> (R, DepNodeIndex) {
|
||||||
if self.is_fully_enabled() {
|
if self.is_fully_enabled() {
|
||||||
self.with_task_impl(key, cx, arg, task, hash_result)
|
self.with_task_impl(key, cx, arg, task, hash_result)
|
||||||
|
@ -234,7 +233,7 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
cx: Ctxt,
|
cx: Ctxt,
|
||||||
arg: A,
|
arg: A,
|
||||||
task: fn(Ctxt, A) -> R,
|
task: fn(Ctxt, A) -> R,
|
||||||
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
|
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
|
||||||
) -> (R, DepNodeIndex) {
|
) -> (R, DepNodeIndex) {
|
||||||
// This function is only called when the graph is enabled.
|
// This function is only called when the graph is enabled.
|
||||||
let data = self.data.as_ref().unwrap();
|
let data = self.data.as_ref().unwrap();
|
||||||
|
@ -268,9 +267,11 @@ impl<K: DepKind> DepGraph<K> {
|
||||||
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
|
let edges = task_deps.map_or_else(|| smallvec![], |lock| lock.into_inner().reads);
|
||||||
|
|
||||||
let dcx = cx.dep_context();
|
let dcx = cx.dep_context();
|
||||||
let mut hcx = dcx.create_stable_hashing_context();
|
|
||||||
let hashing_timer = dcx.profiler().incr_result_hashing();
|
let hashing_timer = dcx.profiler().incr_result_hashing();
|
||||||
let current_fingerprint = hash_result(&mut hcx, &result);
|
let current_fingerprint = hash_result.map(|f| {
|
||||||
|
let mut hcx = dcx.create_stable_hashing_context();
|
||||||
|
f(&mut hcx, &result)
|
||||||
|
});
|
||||||
|
|
||||||
let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
|
let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
|
||||||
pub dep_kind: CTX::DepKind,
|
pub dep_kind: CTX::DepKind,
|
||||||
pub eval_always: bool,
|
pub eval_always: bool,
|
||||||
|
|
||||||
pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
|
pub hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
|
||||||
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
|
||||||
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
|
||||||
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
|
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
|
||||||
|
@ -38,14 +38,6 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
|
||||||
DepNode::construct(tcx, self.dep_kind, key)
|
DepNode::construct(tcx, self.dep_kind, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn hash_result(
|
|
||||||
&self,
|
|
||||||
hcx: &mut StableHashingContext<'_>,
|
|
||||||
value: &V,
|
|
||||||
) -> Option<Fingerprint> {
|
|
||||||
(self.hash_result)(hcx, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
|
pub(crate) fn cache_on_disk(&self, tcx: CTX, key: &K, value: Option<&V>) -> bool {
|
||||||
(self.cache_on_disk)(tcx, key, value)
|
(self.cache_on_disk)(tcx, key, value)
|
||||||
}
|
}
|
||||||
|
@ -59,6 +51,9 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
|
||||||
const ANON: bool;
|
const ANON: bool;
|
||||||
const EVAL_ALWAYS: bool;
|
const EVAL_ALWAYS: bool;
|
||||||
const DEP_KIND: CTX::DepKind;
|
const DEP_KIND: CTX::DepKind;
|
||||||
|
const HASH_RESULT: Option<
|
||||||
|
fn(hcx: &mut StableHashingContext<'_>, result: &Self::Value) -> Fingerprint,
|
||||||
|
>;
|
||||||
|
|
||||||
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
|
type Cache: QueryCache<Key = Self::Key, Stored = Self::Stored, Value = Self::Value>;
|
||||||
|
|
||||||
|
@ -75,9 +70,6 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
|
||||||
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
// Don't use this method to compute query results, instead use the methods on TyCtxt
|
||||||
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
|
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
|
||||||
|
|
||||||
fn hash_result(hcx: &mut StableHashingContext<'_>, result: &Self::Value)
|
|
||||||
-> Option<Fingerprint>;
|
|
||||||
|
|
||||||
fn handle_cycle_error(tcx: CTX, diag: DiagnosticBuilder<'_>) -> Self::Value;
|
fn handle_cycle_error(tcx: CTX, diag: DiagnosticBuilder<'_>) -> Self::Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +99,7 @@ where
|
||||||
anon: Q::ANON,
|
anon: Q::ANON,
|
||||||
dep_kind: Q::DEP_KIND,
|
dep_kind: Q::DEP_KIND,
|
||||||
eval_always: Q::EVAL_ALWAYS,
|
eval_always: Q::EVAL_ALWAYS,
|
||||||
hash_result: Q::hash_result,
|
hash_result: Q::HASH_RESULT,
|
||||||
handle_cycle_error: Q::handle_cycle_error,
|
handle_cycle_error: Q::handle_cycle_error,
|
||||||
cache_on_disk: Q::cache_on_disk,
|
cache_on_disk: Q::cache_on_disk,
|
||||||
try_load_from_disk: Q::try_load_from_disk,
|
try_load_from_disk: Q::try_load_from_disk,
|
||||||
|
|
|
@ -577,12 +577,12 @@ fn incremental_verify_ich<CTX, K, V: Debug>(
|
||||||
);
|
);
|
||||||
|
|
||||||
debug!("BEGIN verify_ich({:?})", dep_node);
|
debug!("BEGIN verify_ich({:?})", dep_node);
|
||||||
let mut hcx = tcx.create_stable_hashing_context();
|
let new_hash = query.hash_result.map_or(Fingerprint::ZERO, |f| {
|
||||||
|
let mut hcx = tcx.create_stable_hashing_context();
|
||||||
let new_hash = query.hash_result(&mut hcx, result).unwrap_or(Fingerprint::ZERO);
|
f(&mut hcx, result)
|
||||||
debug!("END verify_ich({:?})", dep_node);
|
});
|
||||||
|
|
||||||
let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node);
|
let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node);
|
||||||
|
debug!("END verify_ich({:?})", dep_node);
|
||||||
|
|
||||||
if Some(new_hash) != old_hash {
|
if Some(new_hash) != old_hash {
|
||||||
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
|
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue