1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! The `DepGraphSafe` trait
14 use hir::def_id::DefId;
15 use syntax::ast::NodeId;
18 /// The `DepGraphSafe` trait is used to specify what kinds of values
19 /// are safe to "leak" into a task. The idea is that this should be
20 /// only be implemented for things like the tcx as well as various id
21 /// types, which will create reads in the dep-graph whenever the trait
22 /// loads anything that might depend on the input program.
23 pub trait DepGraphSafe {
26 /// A `BodyId` 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 BodyId {
32 /// A `NodeId` on its own doesn't give access to any particular state.
33 /// You must fetch the state from the various maps or generate
34 /// on-demand queries, all of which create reads.
35 impl DepGraphSafe for NodeId {
38 /// A `DefId` on its own doesn't give access to any particular state.
39 /// You must fetch the state from the various maps or generate
40 /// on-demand queries, all of which create reads.
41 impl DepGraphSafe for DefId {
44 /// The type context itself can be used to access all kinds of tracked
45 /// state, but those accesses should always generate read events.
46 impl<'a, 'gcx, 'tcx> DepGraphSafe for TyCtxt<'a, 'gcx, 'tcx> {
49 /// Tuples make it easy to build up state.
50 impl<A, B> DepGraphSafe for (A, B)
51 where A: DepGraphSafe, B: DepGraphSafe
55 /// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
56 impl<'a, A> DepGraphSafe for &'a A
57 where A: DepGraphSafe,
61 /// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
62 impl<'a, A> DepGraphSafe for &'a mut A
63 where A: DepGraphSafe,
69 impl DepGraphSafe for () {
72 /// A convenient override that lets you pass arbitrary state into a
73 /// task. Every use should be accompanied by a comment explaining why
74 /// it makes sense (or how it could be refactored away in the future).
75 pub struct AssertDepGraphSafe<T>(pub T);
77 impl<T> DepGraphSafe for AssertDepGraphSafe<T> {