Skip to content

Commit 8871134

Browse files
committed
---
yaml --- r: 276932 b: refs/heads/try c: a9b6205 h: refs/heads/master
1 parent 646e153 commit 8871134

File tree

16 files changed

+412
-244
lines changed

16 files changed

+412
-244
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 6dbb0e86aec11050480beb76eade6fb805010ba7
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
4-
refs/heads/try: b1e68b9e2d75e66bc866a194b744ddf8502ca129
4+
refs/heads/try: a9b6205aff943d44820df53d63d14a06b319b9dd
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
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+
}

branches/try/src/librustc/dep_graph/dep_tracking_map.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use hir::def_id::DefId;
1112
use rustc_data_structures::fnv::FnvHashMap;
1213
use std::cell::RefCell;
1314
use std::ops::Index;
@@ -29,7 +30,7 @@ pub struct DepTrackingMap<M: DepTrackingMapConfig> {
2930
pub trait DepTrackingMapConfig {
3031
type Key: Eq + Hash + Clone;
3132
type Value: Clone;
32-
fn to_dep_node(key: &Self::Key) -> DepNode;
33+
fn to_dep_node(key: &Self::Key) -> DepNode<DefId>;
3334
}
3435

3536
impl<M: DepTrackingMapConfig> DepTrackingMap<M> {

branches/try/src/librustc/dep_graph/edges.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::fnv::{FnvHashMap, FnvHashSet};
12+
use std::fmt::Debug;
13+
use std::hash::Hash;
1214
use super::{DepGraphQuery, DepNode};
1315

14-
pub struct DepGraphEdges {
15-
nodes: Vec<DepNode>,
16-
indices: FnvHashMap<DepNode, IdIndex>,
16+
pub struct DepGraphEdges<D: Clone + Debug + Eq + Hash> {
17+
nodes: Vec<DepNode<D>>,
18+
indices: FnvHashMap<DepNode<D>, IdIndex>,
1719
edges: FnvHashSet<(IdIndex, IdIndex)>,
1820
open_nodes: Vec<OpenNode>,
1921
}
@@ -40,8 +42,8 @@ enum OpenNode {
4042
Ignore,
4143
}
4244

43-
impl DepGraphEdges {
44-
pub fn new() -> DepGraphEdges {
45+
impl<D: Clone + Debug + Eq + Hash> DepGraphEdges<D> {
46+
pub fn new() -> DepGraphEdges<D> {
4547
DepGraphEdges {
4648
nodes: vec![],
4749
indices: FnvHashMap(),
@@ -50,12 +52,12 @@ impl DepGraphEdges {
5052
}
5153
}
5254

53-
fn id(&self, index: IdIndex) -> DepNode {
54-
self.nodes[index.index()]
55+
fn id(&self, index: IdIndex) -> DepNode<D> {
56+
self.nodes[index.index()].clone()
5557
}
5658

5759
/// Creates a node for `id` in the graph.
58-
fn make_node(&mut self, id: DepNode) -> IdIndex {
60+
fn make_node(&mut self, id: DepNode<D>) -> IdIndex {
5961
if let Some(&i) = self.indices.get(&id) {
6062
return i;
6163
}
@@ -80,7 +82,7 @@ impl DepGraphEdges {
8082
assert_eq!(popped_node, OpenNode::Ignore);
8183
}
8284

83-
pub fn push_task(&mut self, key: DepNode) {
85+
pub fn push_task(&mut self, key: DepNode<D>) {
8486
let top_node = self.current_node();
8587

8688
let new_node = self.make_node(key);
@@ -93,23 +95,23 @@ impl DepGraphEdges {
9395
}
9496
}
9597

96-
pub fn pop_task(&mut self, key: DepNode) {
98+
pub fn pop_task(&mut self, key: DepNode<D>) {
9799
let popped_node = self.open_nodes.pop().unwrap();
98100
assert_eq!(OpenNode::Node(self.indices[&key]), popped_node);
99101
}
100102

101103
/// Indicates that the current task `C` reads `v` by adding an
102104
/// edge from `v` to `C`. If there is no current task, panics. If
103105
/// you want to suppress this edge, use `ignore`.
104-
pub fn read(&mut self, v: DepNode) {
106+
pub fn read(&mut self, v: DepNode<D>) {
105107
let source = self.make_node(v);
106108
self.add_edge_from_current_node(|current| (source, current))
107109
}
108110

109111
/// Indicates that the current task `C` writes `v` by adding an
110112
/// edge from `C` to `v`. If there is no current task, panics. If
111113
/// you want to suppress this edge, use `ignore`.
112-
pub fn write(&mut self, v: DepNode) {
114+
pub fn write(&mut self, v: DepNode<D>) {
113115
let target = self.make_node(v);
114116
self.add_edge_from_current_node(|current| (current, target))
115117
}
@@ -153,7 +155,7 @@ impl DepGraphEdges {
153155
}
154156
}
155157

156-
pub fn query(&self) -> DepGraphQuery {
158+
pub fn query(&self) -> DepGraphQuery<D> {
157159
let edges: Vec<_> = self.edges.iter()
158160
.map(|&(i, j)| (self.id(i), self.id(j)))
159161
.collect();
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

0 commit comments

Comments
 (0)