@@ -6,49 +6,25 @@ use rustc_session::Session;
6
6
#[ macro_use]
7
7
mod dep_node;
8
8
9
+ pub use rustc_query_system:: dep_graph:: debug:: EdgeFilter ;
10
+ use rustc_query_system:: dep_graph:: dep_node:: default_dep_kind_debug;
9
11
pub use rustc_query_system:: dep_graph:: {
10
- debug:: DepNodeFilter , hash_result, DepContext , DepNodeColor , DepNodeIndex ,
11
- SerializedDepNodeIndex , WorkProduct , WorkProductId , WorkProductMap ,
12
+ debug:: DepNodeFilter , hash_result, DepContext , DepGraphQuery , DepNodeColor , DepNodeIndex , Deps ,
13
+ SerializedDepGraph , SerializedDepNodeIndex , TaskDeps , TaskDepsRef , WorkProduct , WorkProductId ,
14
+ WorkProductMap ,
12
15
} ;
13
16
14
- pub use dep_node:: { label_strs, DepKind , DepNode , DepNodeExt } ;
17
+ pub use dep_node:: { dep_kinds , label_strs, DepKind , DepNode , DepNodeExt } ;
15
18
pub ( crate ) use dep_node:: { make_compile_codegen_unit, make_compile_mono_item} ;
16
19
17
- pub type DepGraph = rustc_query_system:: dep_graph:: DepGraph < DepKind > ;
20
+ pub type DepGraph = rustc_query_system:: dep_graph:: DepGraph < DepsType > ;
18
21
19
- pub type TaskDeps = rustc_query_system:: dep_graph:: TaskDeps < DepKind > ;
20
- pub type TaskDepsRef < ' a > = rustc_query_system:: dep_graph:: TaskDepsRef < ' a , DepKind > ;
21
- pub type DepGraphQuery = rustc_query_system:: dep_graph:: DepGraphQuery < DepKind > ;
22
- pub type SerializedDepGraph = rustc_query_system:: dep_graph:: SerializedDepGraph < DepKind > ;
23
- pub type EdgeFilter = rustc_query_system:: dep_graph:: debug:: EdgeFilter < DepKind > ;
24
22
pub type DepKindStruct < ' tcx > = rustc_query_system:: dep_graph:: DepKindStruct < TyCtxt < ' tcx > > ;
25
23
26
- impl rustc_query_system:: dep_graph:: DepKind for DepKind {
27
- const NULL : Self = DepKind :: Null ;
28
- const RED : Self = DepKind :: Red ;
29
- const MAX : u16 = DepKind :: VARIANTS - 1 ;
30
-
31
- fn debug_node ( node : & DepNode , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
32
- write ! ( f, "{:?}(" , node. kind) ?;
33
-
34
- ty:: tls:: with_opt ( |opt_tcx| {
35
- if let Some ( tcx) = opt_tcx {
36
- if let Some ( def_id) = node. extract_def_id ( tcx) {
37
- write ! ( f, "{}" , tcx. def_path_debug_str( def_id) ) ?;
38
- } else if let Some ( ref s) = tcx. dep_graph . dep_node_debug_str ( * node) {
39
- write ! ( f, "{s}" ) ?;
40
- } else {
41
- write ! ( f, "{}" , node. hash) ?;
42
- }
43
- } else {
44
- write ! ( f, "{}" , node. hash) ?;
45
- }
46
- Ok ( ( ) )
47
- } ) ?;
48
-
49
- write ! ( f, ")" )
50
- }
24
+ #[ derive( Clone ) ]
25
+ pub struct DepsType ;
51
26
27
+ impl Deps for DepsType {
52
28
fn with_deps < OP , R > ( task_deps : TaskDepsRef < ' _ > , op : OP ) -> R
53
29
where
54
30
OP : FnOnce ( ) -> R ,
@@ -70,24 +46,13 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
70
46
} )
71
47
}
72
48
73
- #[ track_caller]
74
- #[ inline]
75
- fn from_u16 ( u : u16 ) -> Self {
76
- if u > Self :: MAX {
77
- panic ! ( "Invalid DepKind {u}" ) ;
78
- }
79
- // SAFETY: See comment on DepKind::VARIANTS
80
- unsafe { std:: mem:: transmute ( u) }
81
- }
82
-
83
- #[ inline]
84
- fn to_u16 ( self ) -> u16 {
85
- self as u16
86
- }
49
+ const DEP_KIND_NULL : DepKind = dep_kinds:: Null ;
50
+ const DEP_KIND_RED : DepKind = dep_kinds:: Red ;
51
+ const DEP_KIND_MAX : u16 = dep_node:: DEP_KIND_VARIANTS - 1 ;
87
52
}
88
53
89
54
impl < ' tcx > DepContext for TyCtxt < ' tcx > {
90
- type DepKind = DepKind ;
55
+ type Deps = DepsType ;
91
56
92
57
#[ inline]
93
58
fn with_stable_hashing_context < R > ( self , f : impl FnOnce ( StableHashingContext < ' _ > ) -> R ) -> R {
@@ -111,6 +76,37 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
111
76
112
77
#[ inline]
113
78
fn dep_kind_info ( & self , dk : DepKind ) -> & DepKindStruct < ' tcx > {
114
- & self . query_kinds [ dk as usize ]
79
+ & self . query_kinds [ dk. as_usize ( ) ]
115
80
}
116
81
}
82
+
83
+ pub fn dep_kind_debug ( kind : DepKind , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
84
+ ty:: tls:: with_opt ( |opt_tcx| {
85
+ if let Some ( tcx) = opt_tcx {
86
+ write ! ( f, "{}" , tcx. dep_kind_info( kind) . name)
87
+ } else {
88
+ default_dep_kind_debug ( kind, f)
89
+ }
90
+ } )
91
+ }
92
+
93
+ pub fn dep_node_debug ( node : DepNode , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
94
+ write ! ( f, "{:?}(" , node. kind) ?;
95
+
96
+ ty:: tls:: with_opt ( |opt_tcx| {
97
+ if let Some ( tcx) = opt_tcx {
98
+ if let Some ( def_id) = node. extract_def_id ( tcx) {
99
+ write ! ( f, "{}" , tcx. def_path_debug_str( def_id) ) ?;
100
+ } else if let Some ( ref s) = tcx. dep_graph . dep_node_debug_str ( node) {
101
+ write ! ( f, "{s}" ) ?;
102
+ } else {
103
+ write ! ( f, "{}" , node. hash) ?;
104
+ }
105
+ } else {
106
+ write ! ( f, "{}" , node. hash) ?;
107
+ }
108
+ Ok ( ( ) )
109
+ } ) ?;
110
+
111
+ write ! ( f, ")" )
112
+ }
0 commit comments