Skip to content

Commit b491e74

Browse files
committed
Use &C::Key less in queries.
Currently we use a mix of `C::Key` and `&C::Key` parameters. The former is more common and a bit nicer, so convert some of the latter. This results in less converting between the two types, and fewer sigils.
1 parent 69370dc commit b491e74

6 files changed

Lines changed: 22 additions & 24 deletions

File tree

compiler/rustc_macros/src/query.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,10 @@ fn make_helpers_for_query(query: &Query, streams: &mut HelperTokenStreams) {
342342

343343
// Generate a function to check whether we should cache the query to disk, for some key.
344344
if let Some(CacheOnDiskIf { block, .. }) = modifiers.cache_on_disk_if.as_ref() {
345-
// `disallowed_pass_by_ref` is needed because some keys are `rustc_pass_by_value`.
346345
streams.cache_on_disk_if_fns_stream.extend(quote! {
347-
#[cfg_attr(not(bootstrap), allow(unused_variables, rustc::disallowed_pass_by_ref))]
348-
#[cfg_attr(bootstrap, allow(unused_variables, rustc::pass_by_value))]
346+
#[allow(unused_variables)]
349347
#[inline]
350-
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: &#key_ty) -> bool
348+
pub fn #erased_name<'tcx>(tcx: TyCtxt<'tcx>, #key_pat: #key_ty) -> bool
351349
#block
352350
});
353351
}

compiler/rustc_middle/src/queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,7 @@ rustc_queries! {
24052405
/// sets of different crates do not intersect.
24062406
query exported_non_generic_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
24072407
desc { "collecting exported non-generic symbols for crate `{}`", cnum}
2408-
cache_on_disk_if { *cnum == LOCAL_CRATE }
2408+
cache_on_disk_if { cnum == LOCAL_CRATE }
24092409
separate_provide_extern
24102410
}
24112411

@@ -2418,7 +2418,7 @@ rustc_queries! {
24182418
/// sets of different crates do not intersect.
24192419
query exported_generic_symbols(cnum: CrateNum) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
24202420
desc { "collecting exported generic symbols for crate `{}`", cnum}
2421-
cache_on_disk_if { *cnum == LOCAL_CRATE }
2421+
cache_on_disk_if { cnum == LOCAL_CRATE }
24222422
separate_provide_extern
24232423
}
24242424

@@ -2786,7 +2786,7 @@ rustc_queries! {
27862786
query externally_implementable_items(cnum: CrateNum) -> &'tcx FxIndexMap<DefId, (EiiDecl, FxIndexMap<DefId, EiiImpl>)> {
27872787
arena_cache
27882788
desc { "looking up the externally implementable items of a crate" }
2789-
cache_on_disk_if { *cnum == LOCAL_CRATE }
2789+
cache_on_disk_if { cnum == LOCAL_CRATE }
27902790
separate_provide_extern
27912791
}
27922792

compiler/rustc_middle/src/query/inner.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use crate::ty::TyCtxt;
1616
///
1717
/// (Also performs some associated bookkeeping, if a value was found.)
1818
#[inline(always)]
19-
fn try_get_cached<'tcx, C>(tcx: TyCtxt<'tcx>, cache: &C, key: &C::Key) -> Option<C::Value>
19+
fn try_get_cached<'tcx, C>(tcx: TyCtxt<'tcx>, cache: &C, key: C::Key) -> Option<C::Value>
2020
where
2121
C: QueryCache,
2222
{
23-
match cache.lookup(key) {
23+
match cache.lookup(&key) {
2424
Some((value, index)) => {
2525
tcx.prof.query_cache_hit(index.into());
2626
tcx.dep_graph.read_index(index);
@@ -42,7 +42,7 @@ pub(crate) fn query_get_at<'tcx, C>(
4242
where
4343
C: QueryCache,
4444
{
45-
match try_get_cached(tcx, &query.cache, &key) {
45+
match try_get_cached(tcx, &query.cache, key) {
4646
Some(value) => value,
4747
None => (query.execute_query_fn)(tcx, span, key, QueryMode::Get).unwrap(),
4848
}
@@ -59,7 +59,7 @@ pub(crate) fn query_ensure<'tcx, C>(
5959
) where
6060
C: QueryCache,
6161
{
62-
if try_get_cached(tcx, &query.cache, &key).is_none() {
62+
if try_get_cached(tcx, &query.cache, key).is_none() {
6363
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode });
6464
}
6565
}
@@ -81,7 +81,7 @@ where
8181
{
8282
assert_matches!(ensure_mode, EnsureMode::Ok);
8383

84-
if let Some(res) = try_get_cached(tcx, &query.cache, &key) {
84+
if let Some(res) = try_get_cached(tcx, &query.cache, key) {
8585
erase::restore_val(res).map(drop)
8686
} else {
8787
(query.execute_query_fn)(tcx, DUMMY_SP, key, QueryMode::Ensure { ensure_mode })
@@ -111,7 +111,7 @@ pub(crate) fn query_feed<'tcx, C>(
111111
let format_value = query_vtable.format_value;
112112

113113
// Check whether the in-memory cache already has a value for this key.
114-
match try_get_cached(tcx, &query_vtable.cache, &key) {
114+
match try_get_cached(tcx, &query_vtable.cache, key) {
115115
Some(old) => {
116116
// The query already has a cached value for this key.
117117
// That's OK if both values are the same, i.e. they have the same hash,

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
128128
/// This should be the only code that calls the provider function.
129129
pub invoke_provider_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> C::Value,
130130

131-
pub will_cache_on_disk_for_key_fn: fn(tcx: TyCtxt<'tcx>, key: &C::Key) -> bool,
131+
pub will_cache_on_disk_for_key_fn: fn(tcx: TyCtxt<'tcx>, key: C::Key) -> bool,
132132

133133
pub try_load_from_disk_fn: fn(
134134
tcx: TyCtxt<'tcx>,
135-
key: &C::Key,
135+
key: C::Key,
136136
prev_index: SerializedDepNodeIndex,
137137
index: DepNodeIndex,
138138
) -> Option<C::Value>,
139139

140140
pub is_loadable_from_disk_fn:
141-
fn(tcx: TyCtxt<'tcx>, key: &C::Key, index: SerializedDepNodeIndex) -> bool,
141+
fn(tcx: TyCtxt<'tcx>, key: C::Key, index: SerializedDepNodeIndex) -> bool,
142142

143143
/// Function pointer that hashes this query's result values.
144144
///

compiler/rustc_query_impl/src/execution.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ fn execute_job_incr<'tcx, C: QueryCache>(
460460
tcx,
461461
dep_graph_data,
462462
query,
463-
&key,
463+
key,
464464
dep_node,
465465
prev_index,
466466
dep_node_index,
@@ -508,7 +508,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
508508
tcx: TyCtxt<'tcx>,
509509
dep_graph_data: &DepGraphData,
510510
query: &'tcx QueryVTable<'tcx, C>,
511-
key: &C::Key,
511+
key: C::Key,
512512
dep_node: &DepNode,
513513
prev_index: SerializedDepNodeIndex,
514514
dep_node_index: DepNodeIndex,
@@ -571,7 +571,7 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
571571

572572
// The dep-graph for this computation is already in-place.
573573
// Call the query provider.
574-
let value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, *key));
574+
let value = tcx.dep_graph.with_ignore(|| (query.invoke_provider_fn)(tcx, key));
575575

576576
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
577577

@@ -616,7 +616,7 @@ struct EnsureCanSkip {
616616
fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
617617
query: &'tcx QueryVTable<'tcx, C>,
618618
tcx: TyCtxt<'tcx>,
619-
key: &C::Key,
619+
key: C::Key,
620620
ensure_mode: EnsureMode,
621621
) -> EnsureCanSkip {
622622
// Queries with `eval_always` should never skip execution.
@@ -627,7 +627,7 @@ fn check_if_ensure_can_skip_execution<'tcx, C: QueryCache>(
627627
// Ensuring an anonymous query makes no sense
628628
assert!(!query.anon);
629629

630-
let dep_node = DepNode::construct(tcx, query.dep_kind, key);
630+
let dep_node = DepNode::construct(tcx, query.dep_kind, &key);
631631

632632
let dep_graph = &tcx.dep_graph;
633633
let serialized_dep_node_index = match dep_graph.try_mark_green(tcx, &dep_node) {
@@ -696,7 +696,7 @@ pub(super) fn execute_query_incr_inner<'tcx, C: QueryCache>(
696696
let dep_node: Option<DepNode> = match mode {
697697
QueryMode::Ensure { ensure_mode } => {
698698
let EnsureCanSkip { skip_execution, dep_node } =
699-
check_if_ensure_can_skip_execution(query, tcx, &key, ensure_mode);
699+
check_if_ensure_can_skip_execution(query, tcx, key, ensure_mode);
700700
if skip_execution {
701701
// Return early to skip execution.
702702
return None;

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, C, V>(
168168

169169
assert!(all_inactive(&query.state));
170170
query.cache.for_each(&mut |key, value, dep_node| {
171-
if (query.will_cache_on_disk_for_key_fn)(tcx, key) {
171+
if (query.will_cache_on_disk_for_key_fn)(tcx, *key) {
172172
let dep_node = SerializedDepNodeIndex::new(dep_node.index());
173173

174174
// Record position of the cache entry.
@@ -221,7 +221,7 @@ pub(crate) fn promote_from_disk_inner<'tcx, Q: GetQueryVTable<'tcx>>(
221221
dep_node.key_fingerprint
222222
)
223223
});
224-
if (query.will_cache_on_disk_for_key_fn)(tcx, &key) {
224+
if (query.will_cache_on_disk_for_key_fn)(tcx, key) {
225225
// Call `tcx.$query(key)` for its side-effect of loading the disk-cached
226226
// value into memory.
227227
(query.call_query_method_fn)(tcx, key);

0 commit comments

Comments
 (0)