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