Skip to content

Commit cb0c092

Browse files
committed
Prepare define_feedable! for code extraction
1 parent b97bdcb commit cb0c092

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ use std::sync::Arc;
7070
use rustc_abi::Align;
7171
use rustc_arena::TypedArena;
7272
use rustc_ast::expand::allocator::AllocatorKind;
73-
use rustc_data_structures::fingerprint::Fingerprint;
7473
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
7574
use rustc_data_structures::sorted_map::SortedMap;
7675
use rustc_data_structures::steal::Steal;
@@ -88,9 +87,7 @@ use rustc_index::IndexVec;
8887
use rustc_lint_defs::LintId;
8988
use rustc_macros::rustc_queries;
9089
use rustc_query_system::ich::StableHashingContext;
91-
use rustc_query_system::query::{
92-
QueryCache, QueryMode, QueryStackDeferred, QueryState, try_get_cached,
93-
};
90+
use rustc_query_system::query::{QueryMode, QueryStackDeferred, QueryState};
9491
use rustc_session::Limits;
9592
use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion};
9693
use rustc_session::cstore::{

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,22 @@ macro_rules! define_feedable {
501501
$(#[$attr])*
502502
#[inline(always)]
503503
pub fn $name(self, value: queries::$name::ProvidedValue<'tcx>) {
504+
#![allow(unused_imports)] // Removed later in this PR.
505+
use rustc_data_structures::fingerprint::Fingerprint;
506+
use rustc_query_system::query::{QueryCache, try_get_cached};
507+
504508
let key = self.key().into_query_param();
505509

506510
let tcx = self.tcx;
507511
let erased = queries::$name::provided_to_erased(tcx, value);
508-
let value = restore::<$V>(erased);
512+
let value = erase::restore::<$V>(erased);
509513
let cache = &tcx.query_system.caches.$name;
510514

515+
let dep_kind: dep_graph::DepKind = dep_graph::dep_kinds::$name;
511516
let hasher: Option<fn(&mut StableHashingContext<'_>, &_) -> _> = hash_result!([$($modifiers)*]);
512517
match try_get_cached(tcx, cache, &key) {
513518
Some(old) => {
514-
let old = restore::<$V>(old);
519+
let old = erase::restore::<$V>(old);
515520
if let Some(hasher) = hasher {
516521
let (value_hash, old_hash): (Fingerprint, Fingerprint) = tcx.with_stable_hashing_context(|mut hcx|
517522
(hasher(&mut hcx, &value), hasher(&mut hcx, &old))
@@ -521,28 +526,27 @@ macro_rules! define_feedable {
521526
// results is tainted by errors. In this case, delay a bug to
522527
// ensure compilation is doomed, and keep the `old` value.
523528
tcx.dcx().delayed_bug(format!(
524-
"Trying to feed an already recorded value for query {} key={key:?}:\n\
529+
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
525530
old value: {old:?}\nnew value: {value:?}",
526-
stringify!($name),
527531
));
528532
}
529533
} else {
530534
// The query is `no_hash`, so we have no way to perform a sanity check.
531535
// If feeding the same value multiple times needs to be supported,
532536
// the query should not be marked `no_hash`.
533537
bug!(
534-
"Trying to feed an already recorded value for query {} key={key:?}:\nold value: {old:?}\nnew value: {value:?}",
535-
stringify!($name),
538+
"Trying to feed an already recorded value for query {dep_kind:?} key={key:?}:\n\
539+
old value: {old:?}\nnew value: {value:?}",
536540
)
537541
}
538542
}
539543
None => {
540-
let dep_node = dep_graph::DepNode::construct(tcx, dep_graph::dep_kinds::$name, &key);
544+
let dep_node = dep_graph::DepNode::construct(tcx, dep_kind, &key);
541545
let dep_node_index = tcx.dep_graph.with_feed_task(
542546
dep_node,
543547
tcx,
544548
&value,
545-
hash_result!([$($modifiers)*]),
549+
hasher,
546550
);
547551
cache.complete(key, erased, dep_node_index);
548552
}

0 commit comments

Comments
 (0)