|
| 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 | + IntrinsicUseCheck, |
| 75 | + TransCrate, |
| 76 | + TransCrateItem(D), |
| 77 | + TransInlinedItem(D), |
| 78 | + TransWriteMetadata, |
| 79 | + |
| 80 | + // Nodes representing bits of computed IR in the tcx. Each shared |
| 81 | + // table in the tcx (or elsewhere) maps to one of these |
| 82 | + // nodes. Often we map multiple tables to the same node if there |
| 83 | + // is no point in distinguishing them (e.g., both the type and |
| 84 | + // predicates for an item wind up in `ItemSignature`). Other |
| 85 | + // times, such as `ImplItems` vs `TraitItemDefIds`, tables which |
| 86 | + // might be mergable are kept distinct because the sets of def-ids |
| 87 | + // to which they apply are disjoint, and hence we might as well |
| 88 | + // have distinct labels for easier debugging. |
| 89 | + ImplOrTraitItems(D), |
| 90 | + ItemSignature(D), |
| 91 | + FieldTy(D), |
| 92 | + TraitItemDefIds(D), |
| 93 | + InherentImpls(D), |
| 94 | + ImplItems(D), |
| 95 | + |
| 96 | + // The set of impls for a given trait. Ultimately, it would be |
| 97 | + // nice to get more fine-grained here (e.g., to include a |
| 98 | + // simplified type), but we can't do that until we restructure the |
| 99 | + // HIR to distinguish the *header* of an impl from its body. This |
| 100 | + // is because changes to the header may change the self-type of |
| 101 | + // the impl and hence would require us to be more conservative |
| 102 | + // than changes in the impl body. |
| 103 | + TraitImpls(D), |
| 104 | + |
| 105 | + // Nodes representing caches. To properly handle a true cache, we |
| 106 | + // don't use a DepTrackingMap, but rather we push a task node. |
| 107 | + // Otherwise the write into the map would be incorrectly |
| 108 | + // attributed to the first task that happened to fill the cache, |
| 109 | + // which would yield an overly conservative dep-graph. |
| 110 | + TraitItems(D), |
| 111 | + ReprHints(D), |
| 112 | + TraitSelect(D), |
| 113 | +} |
| 114 | + |
| 115 | +impl<D: Clone + Debug> DepNode<D> { |
| 116 | + /// Used in testing |
| 117 | + pub fn from_label_string(label: &str, data: D) -> Result<DepNode<D>, ()> { |
| 118 | + macro_rules! check { |
| 119 | + ($($name:ident,)*) => { |
| 120 | + match label { |
| 121 | + $(stringify!($name) => Ok(DepNode::$name(data)),)* |
| 122 | + _ => Err(()) |
| 123 | + } |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + check! { |
| 128 | + CollectItem, |
| 129 | + BorrowCheck, |
| 130 | + TransCrateItem, |
| 131 | + TypeckItemType, |
| 132 | + TypeckItemBody, |
| 133 | + ImplOrTraitItems, |
| 134 | + ItemSignature, |
| 135 | + FieldTy, |
| 136 | + TraitItemDefIds, |
| 137 | + InherentImpls, |
| 138 | + ImplItems, |
| 139 | + TraitImpls, |
| 140 | + ReprHints, |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + pub fn map_def<E, OP>(&self, mut op: OP) -> Option<DepNode<E>> |
| 145 | + where OP: FnMut(&D) -> Option<E>, E: Clone + Debug |
| 146 | + { |
| 147 | + use self::DepNode::*; |
| 148 | + |
| 149 | + match *self { |
| 150 | + Krate => Some(Krate), |
| 151 | + CrateReader => Some(CrateReader), |
| 152 | + CollectLanguageItems => Some(CollectLanguageItems), |
| 153 | + CheckStaticRecursion => Some(CheckStaticRecursion), |
| 154 | + ResolveLifetimes => Some(ResolveLifetimes), |
| 155 | + RegionResolveCrate => Some(RegionResolveCrate), |
| 156 | + CheckLoops => Some(CheckLoops), |
| 157 | + PluginRegistrar => Some(PluginRegistrar), |
| 158 | + StabilityIndex => Some(StabilityIndex), |
| 159 | + Coherence => Some(Coherence), |
| 160 | + EffectCheck => Some(EffectCheck), |
| 161 | + Liveness => Some(Liveness), |
| 162 | + Resolve => Some(Resolve), |
| 163 | + EntryPoint => Some(EntryPoint), |
| 164 | + CheckEntryFn => Some(CheckEntryFn), |
| 165 | + Variance => Some(Variance), |
| 166 | + Dropck => Some(Dropck), |
| 167 | + Privacy => Some(Privacy), |
| 168 | + Reachability => Some(Reachability), |
| 169 | + DeadCheck => Some(DeadCheck), |
| 170 | + StabilityCheck => Some(StabilityCheck), |
| 171 | + LateLintCheck => Some(LateLintCheck), |
| 172 | + IntrinsicUseCheck => Some(IntrinsicUseCheck), |
| 173 | + TransCrate => Some(TransCrate), |
| 174 | + TransWriteMetadata => Some(TransWriteMetadata), |
| 175 | + Hir(ref d) => op(d).map(Hir), |
| 176 | + CollectItem(ref d) => op(d).map(CollectItem), |
| 177 | + CoherenceCheckImpl(ref d) => op(d).map(CoherenceCheckImpl), |
| 178 | + CoherenceOverlapCheck(ref d) => op(d).map(CoherenceOverlapCheck), |
| 179 | + CoherenceOverlapCheckSpecial(ref d) => op(d).map(CoherenceOverlapCheckSpecial), |
| 180 | + CoherenceOverlapInherentCheck(ref d) => op(d).map(CoherenceOverlapInherentCheck), |
| 181 | + CoherenceOrphanCheck(ref d) => op(d).map(CoherenceOrphanCheck), |
| 182 | + WfCheck(ref d) => op(d).map(WfCheck), |
| 183 | + TypeckItemType(ref d) => op(d).map(TypeckItemType), |
| 184 | + TypeckItemBody(ref d) => op(d).map(TypeckItemBody), |
| 185 | + DropckImpl(ref d) => op(d).map(DropckImpl), |
| 186 | + CheckConst(ref d) => op(d).map(CheckConst), |
| 187 | + IntrinsicCheck(ref d) => op(d).map(IntrinsicCheck), |
| 188 | + MatchCheck(ref d) => op(d).map(MatchCheck), |
| 189 | + MirMapConstruction(ref d) => op(d).map(MirMapConstruction), |
| 190 | + MirTypeck(ref d) => op(d).map(MirTypeck), |
| 191 | + BorrowCheck(ref d) => op(d).map(BorrowCheck), |
| 192 | + RvalueCheck(ref d) => op(d).map(RvalueCheck), |
| 193 | + TransCrateItem(ref d) => op(d).map(TransCrateItem), |
| 194 | + TransInlinedItem(ref d) => op(d).map(TransInlinedItem), |
| 195 | + ImplOrTraitItems(ref d) => op(d).map(ImplOrTraitItems), |
| 196 | + ItemSignature(ref d) => op(d).map(ItemSignature), |
| 197 | + FieldTy(ref d) => op(d).map(FieldTy), |
| 198 | + TraitItemDefIds(ref d) => op(d).map(TraitItemDefIds), |
| 199 | + InherentImpls(ref d) => op(d).map(InherentImpls), |
| 200 | + ImplItems(ref d) => op(d).map(ImplItems), |
| 201 | + TraitImpls(ref d) => op(d).map(TraitImpls), |
| 202 | + TraitItems(ref d) => op(d).map(TraitItems), |
| 203 | + ReprHints(ref d) => op(d).map(ReprHints), |
| 204 | + TraitSelect(ref d) => op(d).map(TraitSelect), |
| 205 | + } |
| 206 | + } |
| 207 | +} |
0 commit comments