Skip to content

Commit 330259a

Browse files
committed
(EXPERIMENT) Expand to a series of named function calls
1 parent 50d4b2d commit 330259a

4 files changed

Lines changed: 51 additions & 37 deletions

File tree

compiler/rustc_query_impl/src/execution.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ pub fn collect_active_jobs_from_all_queries<'tcx>(
4747
let mut job_map_out = QueryJobMap::default();
4848
let mut complete = true;
4949

50-
for_each_query_vtable!(ALL, tcx, |query| {
51-
let res = gather_active_jobs(query, tcx, require_complete, &mut job_map_out);
52-
if res.is_none() {
53-
complete = false;
54-
}
55-
});
50+
for_each_query_vtable!(
51+
gather_active_jobs,
52+
tcx,
53+
ALL_QUERIES,
54+
require_complete,
55+
&mut job_map_out,
56+
&mut complete,
57+
);
5658

5759
if complete { Ok(job_map_out) } else { Err(job_map_out) }
5860
}
@@ -65,12 +67,12 @@ pub fn collect_active_jobs_from_all_queries<'tcx>(
6567
/// each individual query, so that we have distinct function names to
6668
/// grep for.)
6769
fn gather_active_jobs<'tcx, C>(
68-
query: &'tcx QueryVTable<'tcx, C>,
6970
tcx: TyCtxt<'tcx>,
71+
query: &'tcx QueryVTable<'tcx, C>,
7072
require_complete: bool,
7173
job_map_out: &mut QueryJobMap<'tcx>, // Out-param; job info is gathered into this map
72-
) -> Option<()>
73-
where
74+
complete: &mut bool, // Out-param; set to false if `try_lock` fails for any shard
75+
) where
7476
C: QueryCache<Key: QueryKey + DynSend + DynSync>,
7577
QueryVTable<'tcx, C>: DynSync,
7678
{
@@ -103,7 +105,8 @@ where
103105
"Failed to collect active jobs for query with name `{}`!",
104106
query.name
105107
);
106-
return None;
108+
*complete = false;
109+
return;
107110
}
108111
Some(shard) => gather_shard_jobs(&shard),
109112
}
@@ -116,8 +119,6 @@ where
116119
let frame = crate::plumbing::create_deferred_query_stack_frame(tcx, query, key);
117120
job_map_out.insert(job.id, QueryJobInfo { frame, job });
118121
}
119-
120-
Some(())
121122
}
122123

123124
#[cold]

compiler/rustc_query_impl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// tidy-alphabetical-start
44
#![allow(internal_features)]
55
#![feature(core_intrinsics)]
6+
#![feature(macro_metavar_expr)]
67
#![feature(min_specialization)]
78
#![feature(rustc_attrs)]
89
#![feature(try_blocks)]

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,13 @@ pub(crate) fn encode_all_query_results<'tcx>(
151151
encoder: &mut CacheEncoder<'_, 'tcx>,
152152
query_result_index: &mut EncodedDepNodeIndex,
153153
) {
154-
for_each_query_vtable!(CACHE_ON_DISK, tcx, |query| {
155-
encode_query_results(tcx, query, encoder, query_result_index)
156-
});
154+
for_each_query_vtable!(
155+
encode_query_results,
156+
tcx,
157+
CACHE_ON_DISK_QUERIES,
158+
encoder,
159+
query_result_index,
160+
);
157161
}
158162

159163
fn encode_query_results<'a, 'tcx, C, V>(
@@ -185,16 +189,14 @@ fn encode_query_results<'a, 'tcx, C, V>(
185189
pub(crate) fn query_key_hash_verify_all<'tcx>(tcx: TyCtxt<'tcx>) {
186190
if tcx.sess.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions) {
187191
tcx.sess.time("query_key_hash_verify_all", || {
188-
for_each_query_vtable!(ALL, tcx, |query| {
189-
query_key_hash_verify(query, tcx);
190-
});
192+
for_each_query_vtable!(query_key_hash_verify, tcx, ALL_QUERIES)
191193
});
192194
}
193195
}
194196

195197
fn query_key_hash_verify<'tcx, C: QueryCache>(
196-
query: &'tcx QueryVTable<'tcx, C>,
197198
tcx: TyCtxt<'tcx>,
199+
query: &'tcx QueryVTable<'tcx, C>,
198200
) {
199201
let _timer = tcx.prof.generic_activity_with_arg("query_key_hash_verify_for", query.name);
200202

@@ -532,10 +534,15 @@ macro_rules! define_queries {
532534
}
533535
}
534536

535-
/// Given a filter condition (e.g. `ALL` or `CACHE_ON_DISK`), a `tcx`,
536-
/// and a closure expression that accepts `&QueryVTable`, this macro
537-
/// calls that closure with each query vtable that satisfies the filter
538-
/// condition.
537+
/// Given a function name, a `tcx`, and a filter condition
538+
/// (e.g. `ALL_QUERIES` or `CACHE_ON_DISK_QUERIES`),
539+
/// this macro calls that function with each query vtable that satisfies
540+
/// the filter condition.
541+
///
542+
/// The arguments passed to each function call are:
543+
/// - `tcx`
544+
/// - A query vtable that satisfies the filter condition
545+
/// - All other arguments given after the filter condition
539546
///
540547
/// This needs to be a macro, because the vtables can have different
541548
/// key/value/cache types for different queries.
@@ -548,30 +555,32 @@ macro_rules! define_queries {
548555
/// implemented by hand as needed.
549556
macro_rules! for_each_query_vtable {
550557
// Call with all queries.
551-
(ALL, $tcx:expr, $closure:expr) => {{
558+
($inner_fn:expr, $tcx:expr, ALL_QUERIES $$(,$args:expr)* $$(,)?) => {{
552559
let tcx: rustc_middle::ty::TyCtxt<'_> = $tcx;
553560
$(
554-
let query: &rustc_middle::query::plumbing::QueryVTable<'_, _> =
555-
&tcx.query_system.query_vtables.$name;
556-
$closure(query);
561+
$inner_fn(
562+
tcx,
563+
&tcx.query_system.query_vtables.$name,
564+
$$($args),*
565+
);
557566
)*
558567
}};
559568

560569
// Only call with queries that can potentially cache to disk.
561570
//
562571
// This allows the use of trait bounds that only need to be satisfied
563572
// by the subset of queries that actually cache to disk.
564-
(CACHE_ON_DISK, $tcx:expr, $closure:expr) => {{
573+
($inner_fn:expr, $tcx:expr, CACHE_ON_DISK_QUERIES $$(,$args:expr)* $$(,)?) => {{
565574
let tcx: rustc_middle::ty::TyCtxt<'_> = $tcx;
566575
$(
567576
#[cfg($cache_on_disk)]
568-
{
569-
let query: &rustc_middle::query::plumbing::QueryVTable<'_, _> =
570-
&tcx.query_system.query_vtables.$name;
571-
$closure(query);
572-
}
577+
$inner_fn(
578+
tcx,
579+
&tcx.query_system.query_vtables.$name,
580+
$$($args),*
581+
);
573582
)*
574-
}}
583+
}};
575584
}
576585

577586
pub(crate) use for_each_query_vtable;

compiler/rustc_query_impl/src/profiling_support.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ pub(crate) fn alloc_self_profile_query_strings(tcx: TyCtxt<'_>) {
191191

192192
let mut string_cache = QueryKeyStringCache::new();
193193

194-
for_each_query_vtable!(ALL, tcx, |query| {
195-
alloc_self_profile_query_strings_for_query_cache(tcx, query, &mut string_cache);
196-
});
194+
for_each_query_vtable!(
195+
alloc_self_profile_query_strings_for_query_cache,
196+
tcx,
197+
ALL_QUERIES,
198+
&mut string_cache,
199+
);
197200

198201
tcx.sess.prof.store_query_cache_hits();
199202
}

0 commit comments

Comments
 (0)