1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use hir
::def_id
::DefId
;
14 use super::dep_node
::DepNode
;
15 use super::query
::DepGraphQuery
;
17 use super::thread
::{DepGraphThreadData, DepMessage}
;
21 data
: Rc
<DepGraphThreadData
>
25 pub fn new(enabled
: bool
) -> DepGraph
{
27 data
: Rc
::new(DepGraphThreadData
::new(enabled
))
31 /// True if we are actually building a dep-graph. If this returns false,
32 /// then the other methods on this `DepGraph` will have no net effect.
34 pub fn enabled(&self) -> bool
{
38 pub fn query(&self) -> DepGraphQuery
<DefId
> {
42 pub fn in_ignore
<'graph
>(&'graph
self) -> raii
::IgnoreTask
<'graph
> {
43 raii
::IgnoreTask
::new(&self.data
)
46 pub fn in_task
<'graph
>(&'graph
self, key
: DepNode
<DefId
>) -> raii
::DepTask
<'graph
> {
47 raii
::DepTask
::new(&self.data
, key
)
50 pub fn with_ignore
<OP
,R
>(&self, op
: OP
) -> R
51 where OP
: FnOnce() -> R
53 let _task
= self.in_ignore();
57 pub fn with_task
<OP
,R
>(&self, key
: DepNode
<DefId
>, op
: OP
) -> R
58 where OP
: FnOnce() -> R
60 let _task
= self.in_task(key
);
64 pub fn read(&self, v
: DepNode
<DefId
>) {
65 self.data
.enqueue(DepMessage
::Read(v
));
68 pub fn write(&self, v
: DepNode
<DefId
>) {
69 self.data
.enqueue(DepMessage
::Write(v
));