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<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> {
39 /// Tuples make it easy to build up state.
40 impl<A, B> DepGraphSafe for (A, B)
41 where A: DepGraphSafe, B: DepGraphSafe
45 /// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
46 impl<'a, A> DepGraphSafe for &'a A
47 where A: DepGraphSafe,
51 /// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
52 impl<'a, A> DepGraphSafe for &'a mut A
53 where A: DepGraphSafe,
59 impl DepGraphSafe for () {
62 /// A convenient override that lets you pass arbitrary state into a
63 /// task. Every use should be accompanied by a comment explaining why
64 /// it makes sense (or how it could be refactored away in the future).
65 pub struct AssertDepGraphSafe<T>(pub T);
67 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {