]> git.proxmox.com Git - rustc.git/blob - src/librustc/dep_graph/dep_node.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / librustc / dep_graph / dep_node.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 std::fmt::Debug;
12
13 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
14 pub enum DepNode<D: Clone + Debug> {
15 // The `D` type is "how definitions are identified".
16 // During compilation, it is always `DefId`, but when serializing
17 // it is mapped to `DefPath`.
18
19 // Represents the `Krate` as a whole (the `hir::Krate` value) (as
20 // distinct from the krate module). This is basically a hash of
21 // the entire krate, so if you read from `Krate` (e.g., by calling
22 // `tcx.map.krate()`), we will have to assume that any change
23 // means that you need to be recompiled. This is because the
24 // `Krate` value gives you access to all other items. To avoid
25 // this fate, do not call `tcx.map.krate()`; instead, prefer
26 // wrappers like `tcx.visit_all_items_in_krate()`. If there is no
27 // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain
28 // access to the krate, but you must remember to add suitable
29 // edges yourself for the individual items that you read.
30 Krate,
31
32 // Represents the HIR node with the given node-id
33 Hir(D),
34
35 // Represents different phases in the compiler.
36 CrateReader,
37 CollectLanguageItems,
38 CheckStaticRecursion,
39 ResolveLifetimes,
40 RegionResolveCrate,
41 CheckLoops,
42 PluginRegistrar,
43 StabilityIndex,
44 CollectItem(D),
45 Coherence,
46 EffectCheck,
47 Liveness,
48 Resolve,
49 EntryPoint,
50 CheckEntryFn,
51 CoherenceCheckImpl(D),
52 CoherenceOverlapCheck(D),
53 CoherenceOverlapCheckSpecial(D),
54 CoherenceOverlapInherentCheck(D),
55 CoherenceOrphanCheck(D),
56 Variance,
57 WfCheck(D),
58 TypeckItemType(D),
59 TypeckItemBody(D),
60 Dropck,
61 DropckImpl(D),
62 CheckConst(D),
63 Privacy,
64 IntrinsicCheck(D),
65 MatchCheck(D),
66 MirMapConstruction(D),
67 MirTypeck(D),
68 BorrowCheck(D),
69 RvalueCheck(D),
70 Reachability,
71 DeadCheck,
72 StabilityCheck,
73 LateLintCheck,
74 TransCrate,
75 TransCrateItem(D),
76 TransInlinedItem(D),
77 TransWriteMetadata,
78
79 // Nodes representing bits of computed IR in the tcx. Each shared
80 // table in the tcx (or elsewhere) maps to one of these
81 // nodes. Often we map multiple tables to the same node if there
82 // is no point in distinguishing them (e.g., both the type and
83 // predicates for an item wind up in `ItemSignature`). Other
84 // times, such as `ImplItems` vs `TraitItemDefIds`, tables which
85 // might be mergable are kept distinct because the sets of def-ids
86 // to which they apply are disjoint, and hence we might as well
87 // have distinct labels for easier debugging.
88 ImplOrTraitItems(D),
89 ItemSignature(D),
90 FieldTy(D),
91 TraitItemDefIds(D),
92 InherentImpls(D),
93 ImplItems(D),
94
95 // The set of impls for a given trait. Ultimately, it would be
96 // nice to get more fine-grained here (e.g., to include a
97 // simplified type), but we can't do that until we restructure the
98 // HIR to distinguish the *header* of an impl from its body. This
99 // is because changes to the header may change the self-type of
100 // the impl and hence would require us to be more conservative
101 // than changes in the impl body.
102 TraitImpls(D),
103
104 // Nodes representing caches. To properly handle a true cache, we
105 // don't use a DepTrackingMap, but rather we push a task node.
106 // Otherwise the write into the map would be incorrectly
107 // attributed to the first task that happened to fill the cache,
108 // which would yield an overly conservative dep-graph.
109 TraitItems(D),
110 ReprHints(D),
111 TraitSelect(D),
112 }
113
114 impl<D: Clone + Debug> DepNode<D> {
115 /// Used in testing
116 pub fn from_label_string(label: &str, data: D) -> Result<DepNode<D>, ()> {
117 macro_rules! check {
118 ($($name:ident,)*) => {
119 match label {
120 $(stringify!($name) => Ok(DepNode::$name(data)),)*
121 _ => Err(())
122 }
123 }
124 }
125
126 check! {
127 CollectItem,
128 BorrowCheck,
129 TransCrateItem,
130 TypeckItemType,
131 TypeckItemBody,
132 ImplOrTraitItems,
133 ItemSignature,
134 FieldTy,
135 TraitItemDefIds,
136 InherentImpls,
137 ImplItems,
138 TraitImpls,
139 ReprHints,
140 }
141 }
142
143 pub fn map_def<E, OP>(&self, mut op: OP) -> Option<DepNode<E>>
144 where OP: FnMut(&D) -> Option<E>, E: Clone + Debug
145 {
146 use self::DepNode::*;
147
148 match *self {
149 Krate => Some(Krate),
150 CrateReader => Some(CrateReader),
151 CollectLanguageItems => Some(CollectLanguageItems),
152 CheckStaticRecursion => Some(CheckStaticRecursion),
153 ResolveLifetimes => Some(ResolveLifetimes),
154 RegionResolveCrate => Some(RegionResolveCrate),
155 CheckLoops => Some(CheckLoops),
156 PluginRegistrar => Some(PluginRegistrar),
157 StabilityIndex => Some(StabilityIndex),
158 Coherence => Some(Coherence),
159 EffectCheck => Some(EffectCheck),
160 Liveness => Some(Liveness),
161 Resolve => Some(Resolve),
162 EntryPoint => Some(EntryPoint),
163 CheckEntryFn => Some(CheckEntryFn),
164 Variance => Some(Variance),
165 Dropck => Some(Dropck),
166 Privacy => Some(Privacy),
167 Reachability => Some(Reachability),
168 DeadCheck => Some(DeadCheck),
169 StabilityCheck => Some(StabilityCheck),
170 LateLintCheck => Some(LateLintCheck),
171 TransCrate => Some(TransCrate),
172 TransWriteMetadata => Some(TransWriteMetadata),
173 Hir(ref d) => op(d).map(Hir),
174 CollectItem(ref d) => op(d).map(CollectItem),
175 CoherenceCheckImpl(ref d) => op(d).map(CoherenceCheckImpl),
176 CoherenceOverlapCheck(ref d) => op(d).map(CoherenceOverlapCheck),
177 CoherenceOverlapCheckSpecial(ref d) => op(d).map(CoherenceOverlapCheckSpecial),
178 CoherenceOverlapInherentCheck(ref d) => op(d).map(CoherenceOverlapInherentCheck),
179 CoherenceOrphanCheck(ref d) => op(d).map(CoherenceOrphanCheck),
180 WfCheck(ref d) => op(d).map(WfCheck),
181 TypeckItemType(ref d) => op(d).map(TypeckItemType),
182 TypeckItemBody(ref d) => op(d).map(TypeckItemBody),
183 DropckImpl(ref d) => op(d).map(DropckImpl),
184 CheckConst(ref d) => op(d).map(CheckConst),
185 IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck),
186 MatchCheck(ref d) => op(d).map(MatchCheck),
187 MirMapConstruction(ref d) => op(d).map(MirMapConstruction),
188 MirTypeck(ref d) => op(d).map(MirTypeck),
189 BorrowCheck(ref d) => op(d).map(BorrowCheck),
190 RvalueCheck(ref d) => op(d).map(RvalueCheck),
191 TransCrateItem(ref d) => op(d).map(TransCrateItem),
192 TransInlinedItem(ref d) => op(d).map(TransInlinedItem),
193 ImplOrTraitItems(ref d) => op(d).map(ImplOrTraitItems),
194 ItemSignature(ref d) => op(d).map(ItemSignature),
195 FieldTy(ref d) => op(d).map(FieldTy),
196 TraitItemDefIds(ref d) => op(d).map(TraitItemDefIds),
197 InherentImpls(ref d) => op(d).map(InherentImpls),
198 ImplItems(ref d) => op(d).map(ImplItems),
199 TraitImpls(ref d) => op(d).map(TraitImpls),
200 TraitItems(ref d) => op(d).map(TraitItems),
201 ReprHints(ref d) => op(d).map(ReprHints),
202 TraitSelect(ref d) => op(d).map(TraitSelect),
203 }
204 }
205 }