Skip to content

Commit 43ee4d1

Browse files
committed
Auto merge of #108375 - Zoxc:query-inline, r=cjgillot
Add inlining attributes for query system functions These only have a single caller, but don't always get inlined.
2 parents 70fd012 + dd73080 commit 43ee4d1

File tree

4 files changed

+24
-22
lines changed

4 files changed

+24
-22
lines changed

compiler/rustc_middle/src/ty/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,7 @@ impl<'tcx> TyCtxt<'tcx> {
10121012

10131013
/// Note that this is *untracked* and should only be used within the query
10141014
/// system if the result is otherwise tracked through queries
1015+
#[inline]
10151016
pub fn cstore_untracked(self) -> MappedReadGuard<'tcx, CrateStoreDyn> {
10161017
ReadGuard::map(self.untracked.cstore.read(), |c| &**c)
10171018
}

compiler/rustc_query_impl/src/plumbing.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,7 @@ impl QueryContext for QueryCtxt<'_> {
124124
};
125125

126126
// Use the `ImplicitCtxt` while we execute the query.
127-
tls::enter_context(&new_icx, || {
128-
rustc_data_structures::stack::ensure_sufficient_stack(compute)
129-
})
127+
tls::enter_context(&new_icx, compute)
130128
})
131129
}
132130

compiler/rustc_query_system/src/dep_graph/graph.rs

+5
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ impl<K: DepKind> DepGraph<K> {
279279
/// `arg` parameter.
280280
///
281281
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
282+
#[inline(always)]
282283
pub fn with_task<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
283284
&self,
284285
key: DepNode<K>,
@@ -298,6 +299,7 @@ impl<K: DepKind> DepGraph<K> {
298299
}
299300
}
300301

302+
#[inline(always)]
301303
fn with_task_impl<Ctxt: HasDepContext<DepKind = K>, A: Debug, R>(
302304
&self,
303305
key: DepNode<K>,
@@ -598,6 +600,7 @@ impl<K: DepKind> DepGraph<K> {
598600
self.data.is_some() && self.dep_node_index_of_opt(dep_node).is_some()
599601
}
600602

603+
#[inline]
601604
pub fn prev_fingerprint_of(&self, dep_node: &DepNode<K>) -> Option<Fingerprint> {
602605
self.data.as_ref().unwrap().previous.fingerprint_of(dep_node)
603606
}
@@ -1127,6 +1130,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
11271130

11281131
/// Writes the node to the current dep-graph and allocates a `DepNodeIndex` for it.
11291132
/// Assumes that this is a node that has no equivalent in the previous dep-graph.
1133+
#[inline(always)]
11301134
fn intern_new_node(
11311135
&self,
11321136
profiler: &SelfProfilerRef,
@@ -1365,6 +1369,7 @@ impl DepNodeColorMap {
13651369
}
13661370
}
13671371

1372+
#[inline]
13681373
fn insert(&self, index: SerializedDepNodeIndex, color: DepNodeColor) {
13691374
self.values[index].store(
13701375
match color {

compiler/rustc_query_system/src/query/plumbing.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::profiling::TimingGuard;
1616
#[cfg(parallel_compiler)]
1717
use rustc_data_structures::sharded::Sharded;
18+
use rustc_data_structures::stack::ensure_sufficient_stack;
1819
use rustc_data_structures::sync::Lock;
1920
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed, FatalError};
2021
use rustc_session::Session;
@@ -188,12 +189,12 @@ where
188189
#[cfg(not(parallel_compiler))]
189190
let mut state_lock = state.active.lock();
190191
let lock = &mut *state_lock;
192+
let current_job_id = qcx.current_query_job();
191193

192194
match lock.entry(key) {
193195
Entry::Vacant(entry) => {
194196
let id = qcx.next_job_id();
195-
let job = qcx.current_query_job();
196-
let job = QueryJob::new(id, span, job);
197+
let job = QueryJob::new(id, span, current_job_id);
197198

198199
let key = *entry.key();
199200
entry.insert(QueryResult::Started(job));
@@ -212,7 +213,7 @@ where
212213
// so we just return the error.
213214
return TryGetJob::Cycle(id.find_cycle_in_stack(
214215
qcx.try_collect_active_jobs().unwrap(),
215-
&qcx.current_query_job(),
216+
&current_job_id,
216217
span,
217218
));
218219
}
@@ -230,7 +231,7 @@ where
230231

231232
// With parallel queries we might just have to wait on some other
232233
// thread.
233-
let result = latch.wait_on(qcx.current_query_job(), span);
234+
let result = latch.wait_on(current_job_id, span);
234235

235236
match result {
236237
Ok(()) => TryGetJob::JobCompleted(query_blocked_prof_timer),
@@ -346,10 +347,9 @@ where
346347
}
347348
}
348349

350+
#[inline(never)]
349351
fn try_execute_query<Q, Qcx>(
350352
qcx: Qcx,
351-
state: &QueryState<Q::Key, Qcx::DepKind>,
352-
cache: &Q::Cache,
353353
span: Span,
354354
key: Q::Key,
355355
dep_node: Option<DepNode<Qcx::DepKind>>,
@@ -358,9 +358,11 @@ where
358358
Q: QueryConfig<Qcx>,
359359
Qcx: QueryContext,
360360
{
361+
let state = Q::query_state(qcx);
361362
match JobOwner::<'_, Q::Key, Qcx::DepKind>::try_start(&qcx, state, span, key) {
362363
TryGetJob::NotYetStarted(job) => {
363364
let (result, dep_node_index) = execute_job::<Q, Qcx>(qcx, key, dep_node, job.id);
365+
let cache = Q::query_cache(qcx);
364366
if Q::FEEDABLE {
365367
// We should not compute queries that also got a value via feeding.
366368
// This can't happen, as query feeding adds the very dependencies to the fed query
@@ -381,7 +383,7 @@ where
381383
}
382384
#[cfg(parallel_compiler)]
383385
TryGetJob::JobCompleted(query_blocked_prof_timer) => {
384-
let Some((v, index)) = cache.lookup(&key) else {
386+
let Some((v, index)) = Q::query_cache(qcx).lookup(&key) else {
385387
panic!("value must be in cache after waiting")
386388
};
387389

@@ -393,6 +395,7 @@ where
393395
}
394396
}
395397

398+
#[inline(always)]
396399
fn execute_job<Q, Qcx>(
397400
qcx: Qcx,
398401
key: Q::Key,
@@ -478,6 +481,7 @@ where
478481
(result, dep_node_index)
479482
}
480483

484+
#[inline(always)]
481485
fn try_load_from_disk_and_cache_in_memory<Q, Qcx>(
482486
qcx: Qcx,
483487
key: &Q::Key,
@@ -568,6 +572,7 @@ where
568572
Some((result, dep_node_index))
569573
}
570574

575+
#[inline]
571576
#[instrument(skip(tcx, result, hash_result), level = "debug")]
572577
pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
573578
tcx: Tcx,
@@ -722,6 +727,7 @@ pub enum QueryMode {
722727
Ensure,
723728
}
724729

730+
#[inline(always)]
725731
pub fn get_query<Q, Qcx, D>(qcx: Qcx, span: Span, key: Q::Key, mode: QueryMode) -> Option<Q::Value>
726732
where
727733
D: DepKind,
@@ -739,14 +745,8 @@ where
739745
None
740746
};
741747

742-
let (result, dep_node_index) = try_execute_query::<Q, Qcx>(
743-
qcx,
744-
Q::query_state(qcx),
745-
Q::query_cache(qcx),
746-
span,
747-
key,
748-
dep_node,
749-
);
748+
let (result, dep_node_index) =
749+
ensure_sufficient_stack(|| try_execute_query::<Q, Qcx>(qcx, span, key, dep_node));
750750
if let Some(dep_node_index) = dep_node_index {
751751
qcx.dep_context().dep_graph().read_index(dep_node_index)
752752
}
@@ -762,14 +762,12 @@ where
762762
{
763763
// We may be concurrently trying both execute and force a query.
764764
// Ensure that only one of them runs the query.
765-
let cache = Q::query_cache(qcx);
766-
if let Some((_, index)) = cache.lookup(&key) {
765+
if let Some((_, index)) = Q::query_cache(qcx).lookup(&key) {
767766
qcx.dep_context().profiler().query_cache_hit(index.into());
768767
return;
769768
}
770769

771-
let state = Q::query_state(qcx);
772770
debug_assert!(!Q::ANON);
773771

774-
try_execute_query::<Q, _>(qcx, state, cache, DUMMY_SP, key, Some(dep_node));
772+
ensure_sufficient_stack(|| try_execute_query::<Q, _>(qcx, DUMMY_SP, key, Some(dep_node)));
775773
}

0 commit comments

Comments
 (0)