-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Extract most code from define_feedable!
#147393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Zalathar
wants to merge
3
commits into
rust-lang:master
Choose a base branch
from
Zalathar:feed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+71
−48
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
use std::fmt::Debug; | ||
use std::ops::Deref; | ||
|
||
use rustc_data_structures::fingerprint::Fingerprint; | ||
use rustc_data_structures::sync::{AtomicU64, WorkerLocal}; | ||
use rustc_hir::def_id::{DefId, LocalDefId}; | ||
use rustc_hir::hir_id::OwnerId; | ||
use rustc_macros::HashStable; | ||
use rustc_query_system::HandleCycleError; | ||
use rustc_query_system::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; | ||
use rustc_query_system::dep_graph::{DepNodeIndex, DepNodeParams, SerializedDepNodeIndex}; | ||
use rustc_query_system::ich::StableHashingContext; | ||
pub(crate) use rustc_query_system::query::QueryJobId; | ||
use rustc_query_system::query::*; | ||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; | ||
pub use sealed::IntoQueryParam; | ||
|
||
use super::erase::EraseType; | ||
use crate::dep_graph; | ||
use crate::dep_graph::DepKind; | ||
use crate::query::erase::{Erase, restore}; | ||
use crate::query::on_disk_cache::{CacheEncoder, EncodedDepNodeIndex, OnDiskCache}; | ||
use crate::query::{ | ||
DynamicQueries, ExternProviders, Providers, QueryArenas, QueryCaches, QueryEngine, QueryStates, | ||
|
@@ -565,53 +571,77 @@ macro_rules! define_feedable { | |
|
||
let tcx = self.tcx; | ||
let erased = queries::$name::provided_to_erased(tcx, value); | ||
let value = restore::<$V>(erased); | ||
let cache = &tcx.query_system.caches.$name; | ||
|
||
let name: &'static str = stringify!($name); | ||
let dep_kind: dep_graph::DepKind = dep_graph::dep_kinds::$name; | ||
let hasher: Option<fn(&mut StableHashingContext<'_>, &_) -> _> = hash_result!([$($modifiers)*]); | ||
match try_get_cached(tcx, cache, &key) { | ||
Some(old) => { | ||
let old = restore::<$V>(old); | ||
if let Some(hasher) = hasher { | ||
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx.with_stable_hashing_context(|mut hcx| | ||
(hasher(&mut hcx, &value), hasher(&mut hcx, &old)) | ||
); | ||
if old_hash != value_hash { | ||
// We have an inconsistency. This can happen if one of the two | ||
// results is tainted by errors. In this case, delay a bug to | ||
// ensure compilation is doomed, and keep the `old` value. | ||
tcx.dcx().delayed_bug(format!( | ||
"Trying to feed an already recorded value for query {} key={key:?}:\n\ | ||
old value: {old:?}\nnew value: {value:?}", | ||
stringify!($name), | ||
)); | ||
} | ||
} else { | ||
// The query is `no_hash`, so we have no way to perform a sanity check. | ||
// If feeding the same value multiple times needs to be supported, | ||
// the query should not be marked `no_hash`. | ||
bug!( | ||
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}", | ||
stringify!($name), | ||
) | ||
} | ||
} | ||
None => { | ||
let dep_node = dep_graph::DepNode::construct(tcx, dep_graph::dep_kinds::$name, &key); | ||
let dep_node_index = tcx.dep_graph.with_feed_task( | ||
dep_node, | ||
tcx, | ||
&value, | ||
hash_result!([$($modifiers)*]), | ||
); | ||
cache.complete(key, erased, dep_node_index); | ||
} | ||
} | ||
|
||
$crate::query::plumbing::query_feed_inner( | ||
tcx, | ||
name, | ||
dep_kind, | ||
hasher, | ||
cache, | ||
key, | ||
erased, | ||
); | ||
} | ||
})* | ||
} | ||
} | ||
|
||
/// Common implementation of query feeding, used by `define_feedable!`. | ||
pub(crate) fn query_feed_inner<'tcx, Cache, Value>( | ||
tcx: TyCtxt<'tcx>, | ||
name: &'static str, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be recoverable from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, via |
||
dep_kind: DepKind, | ||
hasher: Option<fn(&mut StableHashingContext<'_>, &Value) -> Fingerprint>, | ||
cache: &Cache, | ||
key: Cache::Key, | ||
erased: Erase<Value>, | ||
) where | ||
Cache: QueryCache<Value = Erase<Value>>, | ||
Cache::Key: DepNodeParams<TyCtxt<'tcx>>, | ||
Value: EraseType + Debug, | ||
{ | ||
let value = restore::<Value>(erased); | ||
|
||
match try_get_cached(tcx, cache, &key) { | ||
Some(old) => { | ||
let old = restore::<Value>(old); | ||
if let Some(hasher) = hasher { | ||
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx | ||
.with_stable_hashing_context(|mut hcx| { | ||
(hasher(&mut hcx, &value), hasher(&mut hcx, &old)) | ||
}); | ||
if old_hash != value_hash { | ||
// We have an inconsistency. This can happen if one of the two | ||
// results is tainted by errors. In this case, delay a bug to | ||
// ensure compilation is doomed, and keep the `old` value. | ||
tcx.dcx().delayed_bug(format!( | ||
"Trying to feed an already recorded value for query {name} key={key:?}:\n\ | ||
old value: {old:?}\nnew value: {value:?}", | ||
)); | ||
} | ||
} else { | ||
// The query is `no_hash`, so we have no way to perform a sanity check. | ||
// If feeding the same value multiple times needs to be supported, | ||
// the query should not be marked `no_hash`. | ||
bug!( | ||
"Trying to feed an already recorded value for query {name} key={key:?}:\n\ | ||
old value: {old:?}\nnew value: {value:?}", | ||
) | ||
} | ||
} | ||
None => { | ||
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key); | ||
let dep_node_index = tcx.dep_graph.with_feed_task(dep_node, tcx, &value, hasher); | ||
cache.complete(key, erased, dep_node_index); | ||
} | ||
} | ||
} | ||
|
||
// Each of these queries corresponds to a function pointer field in the | ||
// `Providers` struct for requesting a value of that type, and a method | ||
// on `tcx: TyCtxt` (and `tcx.at(span)`) for doing that request in a way | ||
|
@@ -694,10 +724,6 @@ mod sealed { | |
} | ||
} | ||
|
||
pub use sealed::IntoQueryParam; | ||
|
||
use super::erase::EraseType; | ||
|
||
#[derive(Copy, Clone, Debug, HashStable)] | ||
pub struct CyclePlaceholder(pub ErrorGuaranteed); | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put this closer to
query_get_at
and co? It serves a similar purpose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, the downside would be that it's no longer adjacent to the calling code in
define_feedable!
, so coordinated changes to both would be much less convenient.I can move it if you want, but to me it seems better off here.