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

Move the Lock into OpenTask

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