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 } ;
22use crate :: hir:: map:: definitions:: DefPathData ;
33use crate :: ty:: context:: TyCtxt ;
44use crate :: ty:: query:: config:: QueryConfig ;
55use crate :: ty:: query:: plumbing:: QueryCache ;
6- use measureme:: { StringId , StringComponent } ;
6+ use measureme:: { StringComponent , StringId } ;
77use rustc_data_structures:: fx:: FxHashMap ;
88use rustc_data_structures:: profiling:: SelfProfiler ;
99use rustc_data_structures:: sharded:: Sharded ;
@@ -16,9 +16,7 @@ pub struct QueryKeyStringCache {
1616
1717impl QueryKeyStringCache {
1818 pub fn new ( ) -> QueryKeyStringCache {
19- QueryKeyStringCache {
20- def_id_cache : Default :: default ( ) ,
21- }
19+ QueryKeyStringCache { def_id_cache : Default :: default ( ) }
2220 }
2321}
2422
@@ -29,24 +27,18 @@ pub struct QueryKeyStringBuilder<'p, 'c, 'tcx> {
2927}
3028
3129impl < ' p , ' c , ' tcx > QueryKeyStringBuilder < ' p , ' c , ' tcx > {
32-
3330 pub fn new (
3431 profiler : & ' p SelfProfiler ,
3532 tcx : TyCtxt < ' tcx > ,
3633 string_cache : & ' c mut QueryKeyStringCache ,
3734 ) -> QueryKeyStringBuilder < ' p , ' c , ' tcx > {
38- QueryKeyStringBuilder {
39- profiler,
40- tcx,
41- string_cache,
42- }
35+ QueryKeyStringBuilder { profiler, tcx, string_cache }
4336 }
4437
4538 // The current implementation is rather crude. In the future it might be a
4639 // good idea to base this on `ty::print` in order to get nicer and more
4740 // efficient query keys.
4841 fn def_id_to_string_id ( & mut self , def_id : DefId ) -> StringId {
49-
5042 if let Some ( & string_id) = self . string_cache . def_id_cache . get ( & def_id) {
5143 return string_id;
5244 }
@@ -55,16 +47,11 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
5547
5648 let ( parent_string_id, start_index) = match def_key. parent {
5749 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 } ;
6251
6352 ( self . def_id_to_string_id ( parent_def_id) , 0 )
6453 }
65- None => {
66- ( StringId :: INVALID , 2 )
67- }
54+ None => ( StringId :: INVALID , 2 ) ,
6855 } ;
6956
7057 let dis_buffer = & mut [ 0u8 ; 16 ] ;
@@ -84,12 +71,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
8471 dis = "" ;
8572 end_index = 3 ;
8673 } 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 ( ) ;
9176 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 ( ) ;
9378 end_index = 4 ;
9479 }
9580 }
@@ -99,12 +84,10 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
9984 StringComponent :: Ref ( parent_string_id) ,
10085 StringComponent :: Value ( "::" ) ,
10186 StringComponent :: Value ( & name[ ..] ) ,
102- StringComponent :: Value ( dis)
87+ StringComponent :: Value ( dis) ,
10388 ] ;
10489
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] ) ;
10891
10992 self . string_cache . def_id_cache . insert ( def_id, string_id) ;
11093
@@ -113,72 +96,50 @@ impl<'p, 'c, 'tcx> QueryKeyStringBuilder<'p, 'c, 'tcx> {
11396}
11497
11598pub 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 ;
120100}
121101
122102// The default implementation of `IntoSelfProfilingString` just uses `Debug`
123103// which is slow and causes lots of duplication of string data.
124104// The specialized impls below take care of making the `DefId` case more
125105// efficient.
126106impl < T : Debug > IntoSelfProfilingString for T {
127-
128107 default fn to_self_profile_string (
129108 & self ,
130- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
109+ builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ,
131110 ) -> StringId {
132111 let s = format ! ( "{:?}" , self ) ;
133112 builder. profiler . alloc_string ( & s[ ..] )
134113 }
135114}
136115
137116impl 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 {
143118 builder. def_id_to_string_id ( * self )
144119 }
145120}
146121
147122impl 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 } )
157125 }
158126}
159127
160128impl 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 } )
170131 }
171132}
172133
173134impl < 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 ,
176138{
177139 default fn to_self_profile_string (
178140 & self ,
179- builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ >
141+ builder : & mut QueryKeyStringBuilder < ' _ , ' _ , ' _ > ,
180142 ) -> StringId {
181-
182143 let val0 = self . 0 . to_self_profile_string ( builder) ;
183144 let val1 = self . 1 . to_self_profile_string ( builder) ;
184145
@@ -202,16 +163,17 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
202163 query_name : & ' static str ,
203164 query_cache : & Sharded < QueryCache < ' tcx , Q > > ,
204165 string_cache : & mut QueryKeyStringCache ,
205- ) where Q : QueryConfig < ' tcx > {
166+ ) where
167+ Q : QueryConfig < ' tcx > ,
168+ {
206169 tcx. prof . with_profiler ( |profiler| {
207170 let event_id_builder = profiler. event_id_builder ( ) ;
208171
209172 // Walk the entire query cache and allocate the appropriate
210173 // string representations. Each cache entry is uniquely
211174 // identified by its dep_node_index.
212175 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) ;
215177
216178 let query_name = profiler. get_or_alloc_cached_string ( query_name) ;
217179
@@ -226,9 +188,9 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
226188 let mut query_keys_and_indices = Vec :: with_capacity ( len) ;
227189
228190 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+ ) ;
232194 }
233195
234196 query_keys_and_indices
@@ -265,10 +227,8 @@ pub(super) fn alloc_self_profile_query_strings_for_query_cache<'tcx, Q>(
265227 . map ( |v| v. index )
266228 . map ( |dep_node_index| dep_node_index. into ( ) ) ;
267229
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) ;
272232 }
273233 }
274234 } ) ;
0 commit comments