提交 3f802ee8 编写于 作者: J John Kåre Alsaker

Move the Lock into OpenTask

上级 8ec629b3
......@@ -145,7 +145,7 @@ pub fn assert_ignored(&self)
if let Some(..) = self.data {
ty::tls::with_context_opt(|icx| {
let icx = if let Some(icx) = icx { icx } else { return };
match *icx.task.lock() {
match *icx.task {
OpenTask::Ignore => {
// ignored
}
......@@ -160,7 +160,7 @@ pub fn with_ignore<OP,R>(&self, op: OP) -> R
{
ty::tls::with_context(|icx| {
let icx = ty::tls::ImplicitCtxt {
task: &Lock::new(OpenTask::Ignore),
task: &OpenTask::Ignore,
..icx.clone()
};
......@@ -207,11 +207,11 @@ pub fn with_task<'gcx, C, A, R>(&self,
R: HashStable<StableHashingContext<'gcx>>,
{
self.with_task_impl(key, cx, arg, false, task,
|key| OpenTask::Regular {
|key| OpenTask::Regular(Lock::new(RegularOpenTask {
node: key,
reads: Vec::new(),
read_set: FxHashSet(),
},
})),
|data, key, task| data.borrow_mut().complete_task(key, task))
}
......@@ -263,13 +263,10 @@ fn with_task_impl<'gcx, C, A, R>(
profq_msg(hcx.sess(), ProfileQueriesMsg::TaskBegin(key.clone()))
};
let (result, open_task) = if no_tcx {
(task(cx, arg), open_task)
let result = if no_tcx {
task(cx, arg)
} else {
ty::tls::with_context(|icx| {
let open_task = Lock::new(open_task);
let r = {
let icx = ty::tls::ImplicitCtxt {
task: &open_task,
..icx.clone()
......@@ -278,9 +275,6 @@ fn with_task_impl<'gcx, C, A, R>(
ty::tls::enter_context(&icx, |_| {
task(cx, arg)
})
};
(r, open_task.into_inner())
})
};
......@@ -358,10 +352,10 @@ pub fn with_anon_task<OP,R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeInde
{
if let Some(ref data) = self.data {
let (result, open_task) = ty::tls::with_context(|icx| {
let task = Lock::new(OpenTask::Anon {
let task = OpenTask::Anon(Lock::new(AnonOpenTask {
reads: Vec::new(),
read_set: FxHashSet(),
});
}));
let r = {
let icx = ty::tls::ImplicitCtxt {
......@@ -374,7 +368,7 @@ pub fn with_anon_task<OP,R>(&self, dep_kind: DepKind, op: OP) -> (R, DepNodeInde
})
};
(r, task.into_inner())
(r, task)
});
let dep_node_index = data.current
.borrow_mut()
......@@ -986,11 +980,12 @@ fn new() -> CurrentDepGraph {
}
fn complete_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
if let OpenTask::Regular {
if let OpenTask::Regular(task) = task {
let RegularOpenTask {
node,
read_set: _,
reads
} = task {
} = task.into_inner();
assert_eq!(node, key);
// If this is an input node, we expect that it either has no
......@@ -1022,10 +1017,11 @@ fn complete_task(&mut self, key: DepNode, task: OpenTask) -> DepNodeIndex {
}
fn pop_anon_task(&mut self, kind: DepKind, task: OpenTask) -> DepNodeIndex {
if let OpenTask::Anon {
if let OpenTask::Anon(task) = task {
let AnonOpenTask {
read_set: _,
reads
} = task {
} = task.into_inner();
debug_assert!(!kind.is_input());
let mut fingerprint = self.anon_id_seed;
......@@ -1074,18 +1070,16 @@ fn complete_eval_always_task(&mut self, key: DepNode, task: OpenTask) -> DepNode
fn read_index(&mut self, source: DepNodeIndex) {
ty::tls::with_context_opt(|icx| {
let icx = if let Some(icx) = icx { icx } else { return };
match *icx.task.lock() {
OpenTask::Regular {
ref mut reads,
ref mut read_set,
node: ref target,
} => {
match *icx.task {
OpenTask::Regular(ref task) => {
let mut task = task.lock();
self.total_read_count += 1;
if read_set.insert(source) {
reads.push(source);
if task.read_set.insert(source) {
task.reads.push(source);
if cfg!(debug_assertions) {
if let Some(ref forbidden_edge) = self.forbidden_edge {
let target = &task.node;
let source = self.nodes[source];
if forbidden_edge.test(&source, &target) {
bug!("forbidden edge {:?} -> {:?} created",
......@@ -1098,12 +1092,10 @@ fn read_index(&mut self, source: DepNodeIndex) {
self.total_duplicate_read_count += 1;
}
}
OpenTask::Anon {
ref mut reads,
ref mut read_set,
} => {
if read_set.insert(source) {
reads.push(source);
OpenTask::Anon(ref task) => {
let mut task = task.lock();
if task.read_set.insert(source) {
task.reads.push(source);
}
}
OpenTask::Ignore | OpenTask::EvalAlways { .. } => {
......@@ -1128,17 +1120,20 @@ fn alloc_node(&mut self,
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum OpenTask {
Regular {
pub struct RegularOpenTask {
node: DepNode,
reads: Vec<DepNodeIndex>,
read_set: FxHashSet<DepNodeIndex>,
},
Anon {
}
pub struct AnonOpenTask {
reads: Vec<DepNodeIndex>,
read_set: FxHashSet<DepNodeIndex>,
},
}
pub enum OpenTask {
Regular(Lock<RegularOpenTask>),
Anon(Lock<AnonOpenTask>),
Ignore,
EvalAlways {
node: DepNode,
......
......@@ -1741,7 +1741,7 @@ pub mod tls {
use ty::maps;
use errors::{Diagnostic, TRACK_DIAGNOSTICS};
use rustc_data_structures::OnDrop;
use rustc_data_structures::sync::{Lrc, Lock};
use rustc_data_structures::sync::Lrc;
use dep_graph::OpenTask;
/// This is the implicit state of rustc. It contains the current
......@@ -1764,7 +1764,7 @@ pub struct ImplicitCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
/// The current dep graph task. This is used to add dependencies to queries
/// when executing them
pub task: &'a Lock<OpenTask>,
pub task: &'a OpenTask,
}
// A thread local value which stores a pointer to the current ImplicitCtxt
......@@ -1851,7 +1851,7 @@ pub fn enter_global<'gcx, F, R>(gcx: &GlobalCtxt<'gcx>, f: F) -> R
tcx,
query: None,
layout_depth: 0,
task: &Lock::new(OpenTask::Ignore),
task: &OpenTask::Ignore,
};
enter_context(&icx, |_| {
f(tcx)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册