1 //! The `DepGraphSafe` trait
5 use rustc_hir::def_id::DefId;
7 use syntax::ast::NodeId;
9 /// The `DepGraphSafe` trait is used to specify what kinds of values
10 /// are safe to "leak" into a task. The idea is that this should be
11 /// only be implemented for things like the tcx as well as various id
12 /// types, which will create reads in the dep-graph whenever the trait
13 /// loads anything that might depend on the input program.
14 pub trait DepGraphSafe {}
16 /// A `BodyId` on its own doesn't give access to any particular state.
17 /// You must fetch the state from the various maps or generate
18 /// on-demand queries, all of which create reads.
19 impl DepGraphSafe for BodyId {}
21 /// A `NodeId` on its own doesn't give access to any particular state.
22 /// You must fetch the state from the various maps or generate
23 /// on-demand queries, all of which create reads.
24 impl DepGraphSafe for NodeId {}
26 /// A `DefId` on its own doesn't give access to any particular state.
27 /// You must fetch the state from the various maps or generate
28 /// on-demand queries, all of which create reads.
29 impl DepGraphSafe for DefId {}
31 /// The type context itself can be used to access all kinds of tracked
32 /// state, but those accesses should always generate read events.
33 impl<'tcx> DepGraphSafe for TyCtxt<'tcx> {}
35 /// Tuples make it easy to build up state.
36 impl<A, B> DepGraphSafe for (A, B)
43 /// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
44 impl<'a, A> DepGraphSafe for &'a A where A: DepGraphSafe {}
46 /// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
47 impl<'a, A> DepGraphSafe for &'a mut A where A: DepGraphSafe {}
50 impl DepGraphSafe for () {}
52 /// A convenient override that lets you pass arbitrary state into a
53 /// task. Every use should be accompanied by a comment explaining why
54 /// it makes sense (or how it could be refactored away in the future).
55 pub struct AssertDepGraphSafe<T>(pub T);
57 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {}