Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Dec 4, 2018
1 parent 11ae3c9 commit 1d1b35a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl DepGraph {
let result = op(&task);
let dep_node_index = data.current
.borrow_mut()
.pop_anon_task(dep_kind, task);
.complete_anon_task(dep_kind, task);
(result, dep_node_index)
} else {
(op(&OpenTask::Ignore), DepNodeIndex::INVALID)
Expand Down Expand Up @@ -994,6 +994,7 @@ impl CurrentDepGraph {
}
}

#[inline(always)]
fn complete_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
if let OpenTask::Regular(task) = task {
let RegularOpenTask {
Expand Down Expand Up @@ -1031,7 +1032,8 @@ impl CurrentDepGraph {
}
}

fn pop_anon_task(&mut self, kind: DepKind, task: OpenTask) -> DepNodeIndex {
#[inline(always)]
fn complete_anon_task(&mut self, kind: DepKind, task: OpenTask) -> DepNodeIndex {
if let OpenTask::Anon(task) = task {
let AnonOpenTask {
read_set: _,
Expand Down Expand Up @@ -1070,6 +1072,7 @@ impl CurrentDepGraph {
}
}

#[inline(always)]
fn complete_eval_always_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
if let OpenTask::EvalAlways {
node,
Expand Down
12 changes: 11 additions & 1 deletion src/librustc/ty/query/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,17 @@ pub(super) trait QueryAccessors<'tcx>: QueryConfig<'tcx> {
fn to_dep_node(tcx: TyCtxt<'_, 'tcx, '_>, key: &Self::Key) -> DepNode;

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value;
#[inline(always)]
fn compute(tcx: TyCtxt<'_, 'tcx, 'tcx>, key: Self::Key) -> Self::Value {
let provider = Self::provider(tcx, &key);
provider(tcx, key)
}

// Don't use this method to compute query results, instead use the methods on TyCtxt
fn provider(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
key: &Self::Key
) -> fn(TyCtxt<'_, 'tcx, 'tcx>, Self::Key) -> Self::Value;

fn handle_cycle_error(tcx: TyCtxt<'_, 'tcx, '_>) -> Self::Value;
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/query/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ impl<'tcx> QueryJob<'tcx> {
}

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

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,21 +706,21 @@ impl<'a, 'tcx, 'lcx> TyCtxt<'a, 'tcx, 'lcx> {
span: Span,
key: DefId,
) -> Result<&'tcx [Ty<'tcx>], Box<DiagnosticBuilder<'a>>> {
self.try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
self.global_tcx().try_get_query::<queries::adt_sized_constraint<'_>>(span, key)
}
pub fn try_needs_drop_raw(
self,
span: Span,
key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
) -> Result<bool, Box<DiagnosticBuilder<'a>>> {
self.try_get_query::<queries::needs_drop_raw<'_>>(span, key)
self.global_tcx().try_get_query::<queries::needs_drop_raw<'_>>(span, key)
}
pub fn try_optimized_mir(
self,
span: Span,
key: DefId,
) -> Result<&'tcx mir::Mir<'tcx>, Box<DiagnosticBuilder<'a>>> {
self.try_get_query::<queries::optimized_mir<'_>>(span, key)
self.global_tcx().try_get_query::<queries::optimized_mir<'_>>(span, key)
}
}

Expand Down
24 changes: 16 additions & 8 deletions src/librustc/ty/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,15 @@ impl<'a, 'gcx> TyCtxt<'a, 'gcx, 'gcx> {
p.record_query(Q::CATEGORY);
});

let provider = Q::provider(self, &key);

let res = if dep_node.kind.is_eval_always() {
self.dep_graph.with_eval_always_task(self, dep_node, |task| {
job.with_context(self, task, |tcx| Q::compute(tcx, key))
job.with_context(self, task, |tcx| provider(tcx, key))
})
} else {
self.dep_graph.with_query_task(self, dep_node, |task| {
job.with_context(self, task, |tcx| Q::compute(tcx, key))
job.with_context(self, task, |tcx| provider(tcx, key))
})
};

Expand Down Expand Up @@ -841,9 +843,11 @@ macro_rules! define_queries_inner {
DepNode::new_inlined(tcx, $node(*key))
}

// FIXME: Change back to inline
#[inline(never)]
fn compute(tcx: TyCtxt<'_, 'tcx, '_>, key: Self::Key) -> Self::Value {
#[inline(always)]
fn provider(
tcx: TyCtxt<'_, 'tcx, 'tcx>,
key: &Self::Key
) -> fn(TyCtxt<'_, 'tcx, 'tcx>, Self::Key) -> Self::Value {
__query_compute::$name(move || {
let provider = tcx.queries.providers.get(key.query_crate())
// HACK(eddyb) it's possible crates may be loaded after
Expand All @@ -852,7 +856,7 @@ macro_rules! define_queries_inner {
// would be be missing appropriate entries in `providers`.
.unwrap_or(&tcx.queries.fallback_extern_providers)
.$name;
provider(tcx.global_tcx(), key)
provider
})
}

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

Expand Down Expand Up @@ -1048,7 +1052,11 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
macro_rules! force {
($query:ident, $key:expr) => {
{
tcx.force_query::<::ty::query::queries::$query<'_>>($key, DUMMY_SP, *dep_node);
tcx.global_tcx().force_query::<::ty::query::queries::$query<'_>>(
$key,
DUMMY_SP,
*dep_node
);
}
}
};
Expand Down

0 comments on commit 1d1b35a

Please sign in to comment.