@@ -207,6 +207,29 @@ impl GlobalFileTable {
207
207
}
208
208
}
209
209
210
+ rustc_index:: newtype_index! {
211
+ // Tell the newtype macro to not generate `Encode`/`Decode` impls.
212
+ #[ custom_encodable]
213
+ struct LocalFileId { }
214
+ }
215
+
216
+ /// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
217
+ /// file IDs.
218
+ #[ derive( Default ) ]
219
+ struct VirtualFileMapping {
220
+ local_to_global : IndexVec < LocalFileId , u32 > ,
221
+ }
222
+
223
+ impl VirtualFileMapping {
224
+ fn push_global_id ( & mut self , global_file_id : u32 ) -> LocalFileId {
225
+ self . local_to_global . push ( global_file_id)
226
+ }
227
+
228
+ fn into_vec ( self ) -> Vec < u32 > {
229
+ self . local_to_global . raw
230
+ }
231
+ }
232
+
210
233
/// Using the expressions and counter regions collected for a single function,
211
234
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
212
235
/// entry. The payload is returned as a vector of bytes.
@@ -223,7 +246,7 @@ fn encode_mappings_for_function(
223
246
224
247
let expressions = function_coverage. counter_expressions ( ) . collect :: < Vec < _ > > ( ) ;
225
248
226
- let mut virtual_file_mapping = IndexVec :: < u32 , u32 > :: new ( ) ;
249
+ let mut virtual_file_mapping = VirtualFileMapping :: default ( ) ;
227
250
let mut mapping_regions = Vec :: with_capacity ( counter_regions. len ( ) ) ;
228
251
229
252
// Sort and group the list of (counter, region) mapping pairs by filename.
@@ -239,8 +262,8 @@ fn encode_mappings_for_function(
239
262
let global_file_id = global_file_table. global_file_id_for_file_name ( file_name) ;
240
263
241
264
// Associate that global file ID with a local file ID for this function.
242
- let local_file_id: u32 = virtual_file_mapping. push ( global_file_id) ;
243
- debug ! ( " file id: local {local_file_id} => global {global_file_id} = '{file_name:?}'" ) ;
265
+ let local_file_id = virtual_file_mapping. push_global_id ( global_file_id) ;
266
+ debug ! ( " file id: {local_file_id:? } => global {global_file_id} = '{file_name:?}'" ) ;
244
267
245
268
// For each counter/region pair in this function+file, convert it to a
246
269
// form suitable for FFI.
@@ -250,7 +273,7 @@ fn encode_mappings_for_function(
250
273
debug ! ( "Adding counter {counter:?} to map for {region:?}" ) ;
251
274
mapping_regions. push ( CounterMappingRegion :: code_region (
252
275
counter,
253
- local_file_id,
276
+ local_file_id. as_u32 ( ) ,
254
277
start_line,
255
278
start_col,
256
279
end_line,
@@ -262,7 +285,7 @@ fn encode_mappings_for_function(
262
285
// Encode the function's coverage mappings into a buffer.
263
286
llvm:: build_byte_buffer ( |buffer| {
264
287
coverageinfo:: write_mapping_to_buffer (
265
- virtual_file_mapping. raw ,
288
+ virtual_file_mapping. into_vec ( ) ,
266
289
expressions,
267
290
mapping_regions,
268
291
buffer,
0 commit comments