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