]> git.proxmox.com Git - rustc.git/blob - src/librustc/dep_graph/graph.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc / dep_graph / graph.rs
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.
4 //
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.
10
11 use hir::def_id::DefId;
12 use std::rc::Rc;
13
14 use super::dep_node::DepNode;
15 use super::query::DepGraphQuery;
16 use super::raii;
17 use super::thread::{DepGraphThreadData, DepMessage};
18
19 #[derive(Clone)]
20 pub struct DepGraph {
21 data: Rc<DepGraphThreadData>
22 }
23
24 impl DepGraph {
25 pub fn new(enabled: bool) -> DepGraph {
26 DepGraph {
27 data: Rc::new(DepGraphThreadData::new(enabled))
28 }
29 }
30
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.
33 #[inline]
34 pub fn enabled(&self) -> bool {
35 self.data.enabled()
36 }
37
38 pub fn query(&self) -> DepGraphQuery<DefId> {
39 self.data.query()
40 }
41
42 pub fn in_ignore<'graph>(&'graph self) -> raii::IgnoreTask<'graph> {
43 raii::IgnoreTask::new(&self.data)
44 }
45
46 pub fn in_task<'graph>(&'graph self, key: DepNode<DefId>) -> raii::DepTask<'graph> {
47 raii::DepTask::new(&self.data, key)
48 }
49
50 pub fn with_ignore<OP,R>(&self, op: OP) -> R
51 where OP: FnOnce() -> R
52 {
53 let _task = self.in_ignore();
54 op()
55 }
56
57 pub fn with_task<OP,R>(&self, key: DepNode<DefId>, op: OP) -> R
58 where OP: FnOnce() -> R
59 {
60 let _task = self.in_task(key);
61 op()
62 }
63
64 pub fn read(&self, v: DepNode<DefId>) {
65 self.data.enqueue(DepMessage::Read(v));
66 }
67
68 pub fn write(&self, v: DepNode<DefId>) {
69 self.data.enqueue(DepMessage::Write(v));
70 }
71 }