Skip to content

Commit 475cafe

Browse files
committed
wip
1 parent 1d1b35a commit 475cafe

File tree

2 files changed

+25
-52
lines changed

2 files changed

+25
-52
lines changed

src/librustc/ty/query/config.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,7 @@ pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
5353

5454
// Don't use this method to compute query results, instead use the methods on TyCtxt
5555
#[inline(always)]
56-
fn compute(tcx: TyCtxt<'_, 'tcx, 'tcx>, key: Self::Key) -> Self::Value {
57-
let provider = Self::provider(tcx, &key);
58-
provider(tcx, key)
59-
}
60-
61-
// Don't use this method to compute query results, instead use the methods on TyCtxt
62-
fn provider(
63-
tcx: TyCtxt<'_, 'tcx, 'tcx>,
64-
key: &Self::Key
65-
) -> fn(TyCtxt<'_, 'tcx, 'tcx>, Self::Key) -> Self::Value;
56+
fn compute(tcx: TyCtxt<'_, 'tcx, 'tcx>, key: Self::Key) -> Self::Value;
6657

6758
fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value;
6859
}

src/librustc/ty/query/plumbing.rs

+24-42
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,13 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
193193
/// Executes a job by changing the ImplicitCtxt to point to the
194194
/// new query job while it executes. It returns the diagnostics
195195
/// captured during execution and the actual result.
196-
// FIXME: Remove inline(never)
197-
#[inline(never)]
198-
pub(super) fn with_context<'lcx, F, R>(
196+
#[inline(always)]
197+
pub(super) fn compute(
199198
&self,
200-
tcx: TyCtxt<'_, 'tcx, 'lcx>,
199+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
201200
task: &OpenTask,
202-
compute: F)
203-
-> R
204-
where
205-
F: for<'b> FnOnce(TyCtxt<'b, 'tcx, 'lcx>) -> R
201+
key: Q::Key,
202+
) -> Q::Value
206203
{
207204
// Update the ImplicitCtxt to point to our new query job
208205
let new_icx = tls::ImplicitCtxt {
@@ -214,7 +211,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
214211

215212
// Use the ImplicitCtxt while we execute the query
216213
tls::enter_context(&new_icx, |_| {
217-
compute(tcx)
214+
Q::compute(tcx, key)
218215
})
219216
}
220217
}
@@ -398,7 +395,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
398395
self.sess.profiler(|p| p.start_activity(Q::CATEGORY));
399396

400397
let res = self.dep_graph.with_anon_open_task(dep_node.kind, |open_task| {
401-
job.with_context(self, open_task, |tcx | Q::compute(tcx.global_tcx(), key))
398+
job.compute(self, open_task, key)
402399
});
403400

404401
self.sess.profiler(|p| p.end_activity(Q::CATEGORY));
@@ -454,8 +451,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
454451
self.sess.opts.debugging_opts.incremental_queries {
455452
let prev_dep_node_index =
456453
self.dep_graph.prev_dep_node_index_of(dep_node);
457-
let result = Q::try_load_from_disk(self.global_tcx(),
458-
prev_dep_node_index);
454+
let result = Q::try_load_from_disk(self, prev_dep_node_index);
459455

460456
// We always expect to find a cached result for things that
461457
// can be forced from DepNode.
@@ -480,7 +476,7 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
480476
// try_mark_green(), so we can ignore them here.
481477
// The dep-graph for this computation is already in
482478
// place so we pass OpenTask::Ignore.
483-
job.with_context(self, &OpenTask::Ignore, |tcx| Q::compute(tcx, key))
479+
job.compute(self, &OpenTask::Ignore, key)
484480
};
485481

486482
// If -Zincremental-verify-ich is specified, re-hash results from
@@ -518,8 +514,8 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
518514
Ok(result)
519515
}
520516

521-
// FIXME: Inline this so LLVM can tell what kind of DepNode we are using
522-
#[inline(never)]
517+
// Inlined so LLVM can tell what kind of DepNode we are using
518+
#[inline(always)]
523519
fn force_query_with_job<Q: QueryDescription<'gcx>>(
524520
self,
525521
key: Q::Key,
@@ -543,15 +539,13 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
543539
p.record_query(Q::CATEGORY);
544540
});
545541

546-
let provider = Q::provider(self, &key);
547-
548542
let res = if dep_node.kind.is_eval_always() {
549543
self.dep_graph.with_eval_always_task(self, dep_node, |task| {
550-
job.with_context(self, task, |tcx| provider(tcx, key))
544+
job.compute(self, task, key)
551545
})
552546
} else {
553547
self.dep_graph.with_query_task(self, dep_node, |task| {
554-
job.with_context(self, task, |tcx| provider(tcx, key))
548+
job.compute(self, task, key)
555549
})
556550
};
557551

@@ -806,16 +800,6 @@ macro_rules! define_queries_inner {
806800
})*
807801
}
808802

809-
// This module and the functions in it exist only to provide a
810-
// predictable symbol name prefix for query providers. This is helpful
811-
// for analyzing queries in profilers.
812-
pub(super) mod __query_compute {
813-
$(#[inline(never)]
814-
pub fn $name<F: FnOnce() -> R, R>(f: F) -> R {
815-
f()
816-
})*
817-
}
818-
819803
$(impl<$tcx> QueryConfig<$tcx> for queries::$name<$tcx> {
820804
type Key = $K;
821805
type Value = $V;
@@ -844,20 +828,18 @@ macro_rules! define_queries_inner {
844828
}
845829

846830
#[inline(always)]
847-
fn provider(
831+
fn compute(
848832
tcx: TyCtxt<'_, 'tcx, 'tcx>,
849-
key: &Self::Key
850-
) -> fn(TyCtxt<'_, 'tcx, 'tcx>, Self::Key) -> Self::Value {
851-
__query_compute::$name(move || {
852-
let provider = tcx.queries.providers.get(key.query_crate())
853-
// HACK(eddyb) it's possible crates may be loaded after
854-
// the query engine is created, and because crate loading
855-
// is not yet integrated with the query engine, such crates
856-
// would be be missing appropriate entries in `providers`.
857-
.unwrap_or(&tcx.queries.fallback_extern_providers)
858-
.$name;
859-
provider
860-
})
833+
key: Self::Key
834+
) -> Self::Value {
835+
let provider = tcx.queries.providers.get(key.query_crate())
836+
// HACK(eddyb) it's possible crates may be loaded after
837+
// the query engine is created, and because crate loading
838+
// is not yet integrated with the query engine, such crates
839+
// would be be missing appropriate entries in `providers`.
840+
.unwrap_or(&tcx.queries.fallback_extern_providers)
841+
.$name;
842+
provider(tcx, key)
861843
}
862844

863845
fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value {

0 commit comments

Comments
 (0)