@@ -13,58 +13,51 @@ use hir::def_id::DefId;
13
13
use syntax:: ast:: NodeId ;
14
14
use ty:: TyCtxt ;
15
15
16
- use super :: graph:: DepGraph ;
17
-
18
- /// The `DepGraphSafe` auto trait is used to specify what kinds of
19
- /// values are safe to "leak" into a task. The idea is that this
20
- /// should be only be implemented for things like the tcx, which will
21
- /// create reads in the dep-graph whenever the trait loads anything
22
- /// that might depend on the input program.
16
+ /// The `DepGraphSafe` trait is used to specify what kinds of values
17
+ /// are safe to "leak" into a task. The idea is that this should be
18
+ /// only be implemented for things like the tcx as well as various id
19
+ /// types, which will create reads in the dep-graph whenever the trait
20
+ /// loads anything that might depend on the input program.
23
21
pub trait DepGraphSafe {
24
- fn read ( & self , graph : & DepGraph ) ;
25
22
}
26
23
24
+ /// A `BodyId` on its own doesn't give access to any particular state.
25
+ /// You must fetch the state from the various maps or generate
26
+ /// on-demand queries, all of which create reads.
27
27
impl DepGraphSafe for BodyId {
28
- fn read ( & self , _graph : & DepGraph ) {
29
- // a BodyId on its own doesn't give access to any particular state
30
- }
31
28
}
32
29
30
+ /// A `NodeId` on its own doesn't give access to any particular state.
31
+ /// You must fetch the state from the various maps or generate
32
+ /// on-demand queries, all of which create reads.
33
33
impl DepGraphSafe for NodeId {
34
- fn read ( & self , _graph : & DepGraph ) {
35
- // a DefId doesn't give any particular state
36
- }
37
34
}
38
35
36
+ /// A `DefId` on its own doesn't give access to any particular state.
37
+ /// You must fetch the state from the various maps or generate
38
+ /// on-demand queries, all of which create reads.
39
39
impl DepGraphSafe for DefId {
40
- fn read ( & self , _graph : & DepGraph ) {
41
- // a DefId doesn't give any particular state
42
- }
43
40
}
44
41
42
+ /// The type context itself can be used to access all kinds of tracked
43
+ /// state, but those accesses should always generate read events.
45
44
impl < ' a , ' gcx , ' tcx > DepGraphSafe for TyCtxt < ' a , ' gcx , ' tcx > {
46
- fn read ( & self , _graph : & DepGraph ) {
47
- }
48
45
}
49
46
47
+ /// Tuples make it easy to build up state.
50
48
impl < A , B > DepGraphSafe for ( A , B )
51
49
where A : DepGraphSafe , B : DepGraphSafe
52
50
{
53
- fn read ( & self , graph : & DepGraph ) {
54
- self . 0 . read ( graph) ;
55
- self . 1 . read ( graph) ;
56
- }
57
51
}
58
52
53
+ /// No data here! :)
59
54
impl DepGraphSafe for ( ) {
60
- fn read ( & self , _graph : & DepGraph ) {
61
- }
62
55
}
63
56
64
- /// A convenient override. We should phase out usage of this over
65
- /// time.
57
+ /// A convenient override that lets you pass arbitrary state into a
58
+ /// task. Every use should be accompanied by a comment explaining why
59
+ /// it makes sense (or how it could be refactored away in the future).
66
60
pub struct AssertDepGraphSafe < T > ( pub T ) ;
61
+
67
62
impl < T > DepGraphSafe for AssertDepGraphSafe < T > {
68
- fn read ( & self , _graph : & DepGraph ) {
69
- }
70
63
}
0 commit comments