@@ -13,58 +13,51 @@ use hir::def_id::DefId;
1313use syntax:: ast:: NodeId ;
1414use ty:: TyCtxt ;
1515
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.
2321pub trait DepGraphSafe {
24- fn read ( & self , graph : & DepGraph ) ;
2522}
2623
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.
2727impl DepGraphSafe for BodyId {
28- fn read ( & self , _graph : & DepGraph ) {
29- // a BodyId on its own doesn't give access to any particular state
30- }
3128}
3229
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.
3333impl DepGraphSafe for NodeId {
34- fn read ( & self , _graph : & DepGraph ) {
35- // a DefId doesn't give any particular state
36- }
3734}
3835
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.
3939impl DepGraphSafe for DefId {
40- fn read ( & self , _graph : & DepGraph ) {
41- // a DefId doesn't give any particular state
42- }
4340}
4441
42+ /// The type context itself can be used to access all kinds of tracked
43+ /// state, but those accesses should always generate read events.
4544impl < ' a , ' gcx , ' tcx > DepGraphSafe for TyCtxt < ' a , ' gcx , ' tcx > {
46- fn read ( & self , _graph : & DepGraph ) {
47- }
4845}
4946
47+ /// Tuples make it easy to build up state.
5048impl < A , B > DepGraphSafe for ( A , B )
5149 where A : DepGraphSafe , B : DepGraphSafe
5250{
53- fn read ( & self , graph : & DepGraph ) {
54- self . 0 . read ( graph) ;
55- self . 1 . read ( graph) ;
56- }
5751}
5852
53+ /// No data here! :)
5954impl DepGraphSafe for ( ) {
60- fn read ( & self , _graph : & DepGraph ) {
61- }
6255}
6356
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).
6660pub struct AssertDepGraphSafe < T > ( pub T ) ;
61+
6762impl < T > DepGraphSafe for AssertDepGraphSafe < T > {
68- fn read ( & self , _graph : & DepGraph ) {
69- }
7063}
0 commit comments