@@ -65,9 +65,9 @@ use rustc_hir::definitions::DefPathHash;
65
65
use rustc_hir:: { HirId , ItemLocalId , OwnerId } ;
66
66
use rustc_query_system:: dep_graph:: FingerprintStyle ;
67
67
use rustc_span:: symbol:: Symbol ;
68
- use std:: hash:: Hash ;
69
68
70
- pub use rustc_query_system:: dep_graph:: { DepContext , DepNodeParams } ;
69
+ pub use rustc_query_system:: dep_graph:: dep_node:: DepKind ;
70
+ pub use rustc_query_system:: dep_graph:: { DepContext , DepNode , DepNodeParams } ;
71
71
72
72
macro_rules! define_dep_nodes {
73
73
(
@@ -84,55 +84,39 @@ macro_rules! define_dep_nodes {
84
84
// encoding. The derived Encodable/Decodable uses leb128 encoding which is
85
85
// dense when only considering this enum. But DepKind is encoded in a larger
86
86
// struct, and there we can take advantage of the unused bits in the u16.
87
- #[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
88
87
#[ allow( non_camel_case_types) ]
89
- #[ repr( u16 ) ]
90
- pub enum DepKind {
88
+ #[ repr( u16 ) ] // Must be kept in sync with the inner type of `DepKind`.
89
+ enum DepKindDefs {
91
90
$( $( #[ $attr] ) * $variant) ,*
92
91
}
93
92
94
- impl DepKind {
95
- // This const implements two things: A bounds check so that we can decode
96
- // a DepKind from a u16 with just one check, and a const check that the
97
- // discriminants of the variants have been assigned consecutively from 0
98
- // so that just the one comparison suffices to check that the u16 can be
99
- // transmuted to a DepKind.
100
- pub const VARIANTS : u16 = {
101
- let deps: & [ DepKind ] = & [ $( DepKind :: $variant, ) * ] ;
102
- let mut i = 0 ;
103
- while i < deps. len( ) {
104
- if i as u16 != deps[ i] as u16 {
105
- panic!( ) ;
106
- }
107
- i += 1 ;
108
- }
109
- deps. len( ) as u16
110
- } ;
111
- }
93
+ #[ allow( non_upper_case_globals) ]
94
+ pub mod dep_kinds {
95
+ use super :: * ;
112
96
113
- impl <S : rustc_serialize:: Encoder > rustc_serialize:: Encodable <S > for DepKind {
114
- #[ inline]
115
- fn encode( & self , s: & mut S ) {
116
- s. emit_u16( * self as u16 ) ;
117
- }
97
+ $(
98
+ // The `as u16` cast must be kept in sync with the inner type of `DepKind`.
99
+ pub const $variant: DepKind = DepKind :: new( DepKindDefs :: $variant as u16 ) ;
100
+ ) *
118
101
}
119
102
120
- impl <D : rustc_serialize:: Decoder > rustc_serialize:: Decodable <D > for DepKind {
121
- #[ inline]
122
- fn decode( d: & mut D ) -> DepKind {
123
- let discrim = d. read_u16( ) ;
124
- assert!( discrim < DepKind :: VARIANTS ) ;
125
- // SAFETY: DepKind::VARIANTS checks that the discriminant values permit
126
- // this one check to soundly guard the transmute.
127
- unsafe {
128
- std:: mem:: transmute:: <u16 , DepKind >( discrim)
103
+ // This checks that the discriminants of the variants have been assigned consecutively
104
+ // from 0 so that they can be used as a dense index.
105
+ pub const DEP_KIND_VARIANTS : u16 = {
106
+ let deps = & [ $( dep_kinds:: $variant, ) * ] ;
107
+ let mut i = 0 ;
108
+ while i < deps. len( ) {
109
+ if i != deps[ i] . as_usize( ) {
110
+ panic!( ) ;
129
111
}
112
+ i += 1 ;
130
113
}
131
- }
114
+ deps. len( ) as u16
115
+ } ;
132
116
133
117
pub ( super ) fn dep_kind_from_label_string( label: & str ) -> Result <DepKind , ( ) > {
134
118
match label {
135
- $( stringify!( $variant) => Ok ( DepKind :: $variant) , ) *
119
+ $( stringify!( $variant) => Ok ( dep_kinds :: $variant) , ) *
136
120
_ => Err ( ( ) ) ,
137
121
}
138
122
}
@@ -158,12 +142,10 @@ rustc_query_append!(define_dep_nodes![
158
142
[ ] fn CompileMonoItem ( ) -> ( ) ,
159
143
] ) ;
160
144
161
- static_assert_size ! ( DepKind , 2 ) ;
162
-
163
145
// WARNING: `construct` is generic and does not know that `CompileCodegenUnit` takes `Symbol`s as keys.
164
146
// Be very careful changing this type signature!
165
147
pub ( crate ) fn make_compile_codegen_unit ( tcx : TyCtxt < ' _ > , name : Symbol ) -> DepNode {
166
- DepNode :: construct ( tcx, DepKind :: CompileCodegenUnit , & name)
148
+ DepNode :: construct ( tcx, dep_kinds :: CompileCodegenUnit , & name)
167
149
}
168
150
169
151
// WARNING: `construct` is generic and does not know that `CompileMonoItem` takes `MonoItem`s as keys.
@@ -172,20 +154,9 @@ pub(crate) fn make_compile_mono_item<'tcx>(
172
154
tcx : TyCtxt < ' tcx > ,
173
155
mono_item : & MonoItem < ' tcx > ,
174
156
) -> DepNode {
175
- DepNode :: construct ( tcx, DepKind :: CompileMonoItem , mono_item)
157
+ DepNode :: construct ( tcx, dep_kinds :: CompileMonoItem , mono_item)
176
158
}
177
159
178
- pub type DepNode = rustc_query_system:: dep_graph:: DepNode < DepKind > ;
179
-
180
- // We keep a lot of `DepNode`s in memory during compilation. It's not
181
- // required that their size stay the same, but we don't want to change
182
- // it inadvertently. This assert just ensures we're aware of any change.
183
- #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
184
- static_assert_size ! ( DepNode , 18 ) ;
185
-
186
- #[ cfg( not( any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
187
- static_assert_size ! ( DepNode , 24 ) ;
188
-
189
160
pub trait DepNodeExt : Sized {
190
161
/// Extracts the DefId corresponding to this DepNode. This will work
191
162
/// if two conditions are met:
0 commit comments