1
- use crate :: hir:: def_id:: { CRATE_DEF_INDEX , CrateNum , DefId , DefIndex , LOCAL_CRATE } ;
1
+ use crate :: hir:: def_id:: { CrateNum , DefId , DefIndex , CRATE_DEF_INDEX , LOCAL_CRATE } ;
2
2
use crate :: hir:: map:: definitions:: DefPathData ;
3
3
use crate :: ty:: context:: TyCtxt ;
4
4
use crate :: ty:: query:: config:: QueryConfig ;
5
5
use crate :: ty:: query:: plumbing:: QueryCache ;
6
- use measureme:: { StringId , StringComponent } ;
6
+ use measureme:: { StringComponent , StringId } ;
7
7
use rustc_data_structures:: fx:: FxHashMap ;
8
8
use rustc_data_structures:: profiling:: SelfProfiler ;
9
9
use rustc_data_structures:: sharded:: Sharded ;
@@ -16,9 +16,7 @@ pub struct QueryKeyStringCache {
16
16
17
17
impl QueryKeyStringCache {
18
18
pub fn new ( ) -> QueryKeyStringCache {
19
- QueryKeyStringCache {
20
- def_id_cache : Default :: default ( ) ,
21
- }
19
+ QueryKeyStringCache { def_id_cache : Default :: default ( ) }
22
20
}
23
21
}
24
22
@@ -29,24 +27,18 @@ pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
29
27
}
30
28
31
29
impl < ' p , ' c , ' tcx > QueryKeyStringBuilder < ' p , ' c , ' tcx > {
32
-
33
30
pub fn new (
34
31
profiler : & ' p SelfProfiler ,
35
32
tcx : TyCtxt < ' tcx > ,
36
33
string_cache : & ' c mut QueryKeyStringCache ,
37
34
) -> QueryKeyStringBuilder < ' p , ' c , ' tcx > {
38
- QueryKeyStringBuilder {
39
- profiler,
40
- tcx,
41
- string_cache,
42
- }
35
+ QueryKeyStringBuilder { profiler, tcx, string_cache }
43
36
}
44
37
45
38
// The current implementation is rather crude. In the future it might be a
46
39
// good idea to base this on `ty::print` in order to get nicer and more
47
40
// efficient query keys.
48
41
fn def_id_to_string_id ( & mut self , def_id : DefId ) -> StringId {
49
-
50
42
if let Some ( & string_id) = self . string_cache . def_id_cache . get ( & def_id) {
51
43
return string_id;
52
44
}
@@ -55,16 +47,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
55
47
56
48
let ( parent_string_id, start_index) = match def_key. parent {
57
49
Some ( parent_index) => {
58
- let parent_def_id = DefId {
59
- index : parent_index,
60
- krate : def_id. krate ,
61
- } ;
50
+ let parent_def_id = DefId { index : parent_index, krate : def_id. krate } ;
62
51
63
52
( self . def_id_to_string_id ( parent_def_id) , 0 )
64
53
}
65
- None => {
66
- ( StringId :: INVALID , 2 )
67
- }
54
+ None => ( StringId :: INVALID , 2 ) ,
68
55
} ;
69
56
70
57
let dis_buffer = & mut [ 0u8 ; 16 ] ;
@@ -84,12 +71,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
84
71
dis = "" ;
85
72
end_index = 3 ;
86
73
} else {
87
- write ! ( & mut dis_buffer[ ..] ,
88
- "[{}]" ,
89
- def_key. disambiguated_data. disambiguator
90
- ) . unwrap ( ) ;
74
+ write ! ( & mut dis_buffer[ ..] , "[{}]" , def_key. disambiguated_data. disambiguator)
75
+ . unwrap ( ) ;
91
76
let end_of_dis = dis_buffer. iter ( ) . position ( |& c| c == b']' ) . unwrap ( ) ;
92
- dis = std:: str:: from_utf8 ( & dis_buffer[ .. end_of_dis + 1 ] ) . unwrap ( ) ;
77
+ dis = std:: str:: from_utf8 ( & dis_buffer[ ..end_of_dis + 1 ] ) . unwrap ( ) ;
93
78
end_index = 4 ;
94
79
}
95
80
}
@@ -99,12 +84,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
99
84
StringComponent :: Ref ( parent_string_id) ,
100
85
StringComponent :: Value ( "::" ) ,
101
86
StringComponent :: Value ( & name[ ..] ) ,
102
- StringComponent :: Value ( dis)
87
+ StringComponent :: Value ( dis) ,
103
88
] ;
104
89
105
- let string_id = self . profiler . alloc_string (
106
- & components[ start_index .. end_index]
107
- ) ;
90
+ let string_id = self . profiler . alloc_string ( & components[ start_index..end_index] ) ;
108
91
109
92
self . string_cache . def_id_cache . insert ( def_id, string_id) ;
110
93
@@ -113,72 +96,50 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
113
96
}
114
97
115
98
pub trait IntoSelfProfilingString {
116
- fn to_self_profile_string (
117
- & self ,
118
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
119
- ) -> StringId ;
99
+ fn to_self_profile_string ( & self , builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ) -> StringId ;
120
100
}
121
101
122
102
// The default implementation of `IntoSelfProfilingString` just uses `Debug`
123
103
// which is slow and causes lots of duplication of string data.
124
104
// The specialized impls below take care of making the `DefId` case more
125
105
// efficient.
126
106
impl < T : Debug > IntoSelfProfilingString for T {
127
-
128
107
default fn to_self_profile_string (
129
108
& self ,
130
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
109
+ builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ,
131
110
) -> StringId {
132
111
let s = format ! ( "{:?}" , self ) ;
133
112
builder. profiler . alloc_string ( & s[ ..] )
134
113
}
135
114
}
136
115
137
116
impl IntoSelfProfilingString for DefId {
138
-
139
- fn to_self_profile_string (
140
- & self ,
141
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
142
- ) -> StringId {
117
+ fn to_self_profile_string ( & self , builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ) -> StringId {
143
118
builder. def_id_to_string_id ( * self )
144
119
}
145
120
}
146
121
147
122
impl IntoSelfProfilingString for CrateNum {
148
-
149
- fn to_self_profile_string (
150
- & self ,
151
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
152
- ) -> StringId {
153
- builder. def_id_to_string_id ( DefId {
154
- krate : * self ,
155
- index : CRATE_DEF_INDEX ,
156
- } )
123
+ fn to_self_profile_string ( & self , builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ) -> StringId {
124
+ builder. def_id_to_string_id ( DefId { krate : * self , index : CRATE_DEF_INDEX } )
157
125
}
158
126
}
159
127
160
128
impl IntoSelfProfilingString for DefIndex {
161
-
162
- fn to_self_profile_string (
163
- & self ,
164
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
165
- ) -> StringId {
166
- builder. def_id_to_string_id ( DefId {
167
- krate : LOCAL_CRATE ,
168
- index : * self ,
169
- } )
129
+ fn to_self_profile_string ( & self , builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ) -> StringId {
130
+ builder. def_id_to_string_id ( DefId { krate : LOCAL_CRATE , index : * self } )
170
131
}
171
132
}
172
133
173
134
impl < T0 , T1 > IntoSelfProfilingString for ( T0 , T1 )
174
- where T0 : IntoSelfProfilingString +Debug ,
175
- T1 : IntoSelfProfilingString +Debug ,
135
+ where
136
+ T0 : IntoSelfProfilingString + Debug ,
137
+ T1 : IntoSelfProfilingString + Debug ,
176
138
{
177
139
default fn to_self_profile_string (
178
140
& self ,
179
- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
141
+ builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ,
180
142
) -> StringId {
181
-
182
143
let val0 = self . 0 . to_self_profile_string ( builder) ;
183
144
let val1 = self . 1 . to_self_profile_string ( builder) ;
184
145
@@ -202,16 +163,17 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
202
163
query_name : & ' static str ,
203
164
query_cache : & Sharded < QueryCache < ' tcx , Q > > ,
204
165
string_cache : & mut QueryKeyStringCache ,
205
- ) where Q : QueryConfig < ' tcx > {
166
+ ) where
167
+ Q : QueryConfig < ' tcx > ,
168
+ {
206
169
tcx. prof . with_profiler ( |profiler| {
207
170
let event_id_builder = profiler. event_id_builder ( ) ;
208
171
209
172
// Walk the entire query cache and allocate the appropriate
210
173
// string representations. Each cache entry is uniquely
211
174
// identified by its dep_node_index.
212
175
if profiler. query_key_recording_enabled ( ) {
213
- let mut query_string_builder =
214
- QueryKeyStringBuilder :: new ( profiler, tcx, string_cache) ;
176
+ let mut query_string_builder = QueryKeyStringBuilder :: new ( profiler, tcx, string_cache) ;
215
177
216
178
let query_name = profiler. get_or_alloc_cached_string ( query_name) ;
217
179
@@ -226,9 +188,9 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
226
188
let mut query_keys_and_indices = Vec :: with_capacity ( len) ;
227
189
228
190
for shard in & shards {
229
- query_keys_and_indices. extend ( shard . results . iter ( ) . map ( | ( q_key , q_val ) | {
230
- ( q_key. clone ( ) , q_val. index )
231
- } ) ) ;
191
+ query_keys_and_indices. extend (
192
+ shard . results . iter ( ) . map ( | ( q_key, q_val ) | ( q_key . clone ( ) , q_val. index ) ) ,
193
+ ) ;
232
194
}
233
195
234
196
query_keys_and_indices
@@ -265,10 +227,8 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
265
227
. map ( |v| v. index )
266
228
. map ( |dep_node_index| dep_node_index. into ( ) ) ;
267
229
268
- profiler. bulk_map_query_invocation_id_to_single_string (
269
- query_invocation_ids,
270
- event_id,
271
- ) ;
230
+ profiler
231
+ . bulk_map_query_invocation_id_to_single_string ( query_invocation_ids, event_id) ;
272
232
}
273
233
}
274
234
} ) ;
0 commit comments