diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-16 22:31:48 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-10-20 18:29:18 +0200 |
| commit | aa404c24ddafea428cb86de8f914b129be4a726b (patch) | |
| tree | 0e3dda9def1c7c8ec7655dce81201f51f0a6e818 /compiler/rustc_query_system/src/query | |
| parent | e53404cca68e8220a57339cb3e213fd0d8e99a5f (diff) | |
| download | rust-aa404c24ddafea428cb86de8f914b129be4a726b.tar.gz rust-aa404c24ddafea428cb86de8f914b129be4a726b.zip | |
Make hash_result an Option.
Diffstat (limited to 'compiler/rustc_query_system/src/query')
| -rw-r--r-- | compiler/rustc_query_system/src/query/config.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_query_system/src/query/plumbing.rs | 10 |
2 files changed, 10 insertions, 18 deletions
diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index 76a165ed8e6..22b0245236b 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -24,7 +24,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> { pub dep_kind: CTX::DepKind, 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 cache_on_disk: fn(CTX, &K, Option<&V>) -> bool, 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) } - 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 { (self.cache_on_disk)(tcx, key, value) } @@ -59,6 +51,9 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig { const ANON: bool; const EVAL_ALWAYS: bool; 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>; @@ -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 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; } @@ -107,7 +99,7 @@ where anon: Q::ANON, dep_kind: Q::DEP_KIND, eval_always: Q::EVAL_ALWAYS, - hash_result: Q::hash_result, + hash_result: Q::HASH_RESULT, handle_cycle_error: Q::handle_cycle_error, cache_on_disk: Q::cache_on_disk, try_load_from_disk: Q::try_load_from_disk, diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index d3c75635783..e3bfd81b851 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -577,12 +577,12 @@ fn incremental_verify_ich<CTX, K, V: Debug>( ); debug!("BEGIN verify_ich({:?})", dep_node); - let mut hcx = tcx.create_stable_hashing_context(); - - let new_hash = query.hash_result(&mut hcx, result).unwrap_or(Fingerprint::ZERO); - debug!("END verify_ich({:?})", dep_node); - + let new_hash = query.hash_result.map_or(Fingerprint::ZERO, |f| { + let mut hcx = tcx.create_stable_hashing_context(); + f(&mut hcx, result) + }); let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node); + debug!("END verify_ich({:?})", dep_node); if Some(new_hash) != old_hash { let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name { |
