Skip to content

Commit 1d1b35a

Browse files
committed
wip
1 parent 11ae3c9 commit 1d1b35a

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

src/librustc/dep_graph/graph.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl DepGraph {
417417
let result = op(&task);
418418
let dep_node_index = data.current
419419
.borrow_mut()
420-
.pop_anon_task(dep_kind, task);
420+
.complete_anon_task(dep_kind, task);
421421
(result, dep_node_index)
422422
} else {
423423
(op(&OpenTask::Ignore), DepNodeIndex::INVALID)
@@ -994,6 +994,7 @@ impl CurrentDepGraph {
994994
}
995995
}
996996

997+
#[inline(always)]
997998
fn complete_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
998999
if let OpenTask::Regular(task) = task {
9991000
let RegularOpenTask {
@@ -1031,7 +1032,8 @@ impl CurrentDepGraph {
10311032
}
10321033
}
10331034

1034-
fn pop_anon_task(&mut self, kind: DepKind, task: OpenTask) -> DepNodeIndex {
1035+
#[inline(always)]
1036+
fn complete_anon_task(&mut self, kind: DepKind, task: OpenTask) -> DepNodeIndex {
10351037
if let OpenTask::Anon(task) = task {
10361038
let AnonOpenTask {
10371039
read_set: _,
@@ -1070,6 +1072,7 @@ impl CurrentDepGraph {
10701072
}
10711073
}
10721074

1075+
#[inline(always)]
10731076
fn complete_eval_always_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
10741077
if let OpenTask::EvalAlways {
10751078
node,

src/librustc/ty/query/config.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
5252
fn to_dep_node(tcx: TyCtxt<'_, 'tcx, '_>, key: &Self::Key) -> DepNode;
5353

5454
// Don't use this method to compute query results, instead use the methods on TyCtxt
55-
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value;
55+
#[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;
5666

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

src/librustc/ty/query/job.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ impl<'tcx> QueryJob<'tcx> {
8585
}
8686

8787
pub fn extract_diagnostics(&self) -> Vec<Diagnostic> {
88+
// FIXME: Find a way to remove this lock access since we should have
89+
// ownership of the content back now. Other crates may free the Lrc though
90+
// and the, but only after we replace this.
8891
mem::replace(&mut *self.diagnostics.lock(), Vec::new())
8992
}
9093

src/librustc/ty/query/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,21 +706,21 @@ impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
706706
span: Span,
707707
key: DefId,
708708
) -> Result<&'tcx [Ty<'tcx>], Box<DiagnosticBuilder<'a>>> {
709-
self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
709+
self.global_tcx().try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
710710
}
711711
pub fn try_needs_drop_raw(
712712
self,
713713
span: Span,
714714
key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
715715
) -> Result<bool, Box<DiagnosticBuilder<'a>>> {
716-
self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
716+
self.global_tcx().try_get_query::<queries::needs_drop_raw<'_>>(span, key)
717717
}
718718
pub fn try_optimized_mir(
719719
self,
720720
span: Span,
721721
key: DefId,
722722
) -> Result<&'tcx mir::Mir<'tcx>, Box<DiagnosticBuilder<'a>>> {
723-
self.try_get_query::<queries::optimized_mir<'_>>(span, key)
723+
self.global_tcx().try_get_query::<queries::optimized_mir<'_>>(span, key)
724724
}
725725
}
726726

src/librustc/ty/query/plumbing.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,15 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
543543
p.record_query(Q::CATEGORY);
544544
});
545545

546+
let provider = Q::provider(self, &key);
547+
546548
let res = if dep_node.kind.is_eval_always() {
547549
self.dep_graph.with_eval_always_task(self, dep_node, |task| {
548-
job.with_context(self, task, |tcx| Q::compute(tcx, key))
550+
job.with_context(self, task, |tcx| provider(tcx, key))
549551
})
550552
} else {
551553
self.dep_graph.with_query_task(self, dep_node, |task| {
552-
job.with_context(self, task, |tcx| Q::compute(tcx, key))
554+
job.with_context(self, task, |tcx| provider(tcx, key))
553555
})
554556
};
555557

@@ -841,9 +843,11 @@ macro_rules! define_queries_inner {
841843
DepNode::new_inlined(tcx, $node(*key))
842844
}
843845

844-
// FIXME: Change back to inline
845-
#[inline(never)]
846-
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value {
846+
#[inline(always)]
847+
fn provider(
848+
tcx: TyCtxt<'_, 'tcx, 'tcx>,
849+
key: &Self::Key
850+
) -> fn(TyCtxt<'_, 'tcx, 'tcx>, Self::Key) -> Self::Value {
847851
__query_compute::$name(move || {
848852
let provider = tcx.queries.providers.get(key.query_crate())
849853
// HACK(eddyb) it's possible crates may be loaded after
@@ -852,7 +856,7 @@ macro_rules! define_queries_inner {
852856
// would be be missing appropriate entries in `providers`.
853857
.unwrap_or(&tcx.queries.fallback_extern_providers)
854858
.$name;
855-
provider(tcx.global_tcx(), key)
859+
provider
856860
})
857861
}
858862

@@ -870,7 +874,7 @@ macro_rules! define_queries_inner {
870874
///
871875
/// Note: The optimization is only available during incr. comp.
872876
pub fn ensure(tcx: TyCtxt<'a, $tcx, 'lcx>, key: $K) -> () {
873-
tcx.ensure_query::<queries::$name<'_>>(key);
877+
tcx.global_tcx().ensure_query::<queries::$name<'_>>(key);
874878
}
875879
})*
876880

@@ -1048,7 +1052,11 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
10481052
macro_rules! force {
10491053
($query:ident, $key:expr) => {
10501054
{
1051-
tcx.force_query::<::ty::query::queries::$query<'_>>($key, DUMMY_SP, *dep_node);
1055+
tcx.global_tcx().force_query::<::ty::query::queries::$query<'_>>(
1056+
$key,
1057+
DUMMY_SP,
1058+
*dep_node
1059+
);
10521060
}
10531061
}
10541062
};

0 commit comments

Comments
 (0)