]> git.lizzy.rs Git - rust.git/blob - src/librustc/dep_graph/safe.rs
Rollup merge of #68033 - ollie27:win_f32, r=dtolnay
[rust.git] / src / librustc / dep_graph / safe.rs
1 //! The `DepGraphSafe` trait
2
3 use crate::ty::TyCtxt;
4
5 use rustc_hir::def_id::DefId;
6 use rustc_hir::BodyId;
7 use syntax::ast::NodeId;
8
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 {}
15
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 {}
20
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 {}
25
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 {}
30
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> {}
34
35 /// Tuples make it easy to build up state.
36 impl<A, B> DepGraphSafe for (A, B)
37 where
38     A: DepGraphSafe,
39     B: DepGraphSafe,
40 {
41 }
42
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 {}
45
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 {}
48
49 /// No data here! :)
50 impl DepGraphSafe for () {}
51
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);
56
57 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {}