@@ -207,6 +207,29 @@ impl GlobalFileTable {
207207 }
208208}
209209
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+
210233/// Using the expressions and counter regions collected for a single function,
211234/// generate the variable-sized payload of its corresponding `__llvm_covfun`
212235/// entry. The payload is returned as a vector of bytes.
@@ -223,7 +246,7 @@ fn encode_mappings_for_function(
223246
224247 let expressions = function_coverage. counter_expressions ( ) . collect :: < Vec < _ > > ( ) ;
225248
226- let mut virtual_file_mapping = IndexVec :: < u32 , u32 > :: new ( ) ;
249+ let mut virtual_file_mapping = VirtualFileMapping :: default ( ) ;
227250 let mut mapping_regions = Vec :: with_capacity ( counter_regions. len ( ) ) ;
228251
229252 // Sort and group the list of (counter, region) mapping pairs by filename.
@@ -239,8 +262,8 @@ fn encode_mappings_for_function(
239262 let global_file_id = global_file_table. global_file_id_for_file_name ( file_name) ;
240263
241264 // 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:?}'" ) ;
244267
245268 // For each counter/region pair in this function+file, convert it to a
246269 // form suitable for FFI.
@@ -250,7 +273,7 @@ fn encode_mappings_for_function(
250273 debug ! ( "Adding counter {counter:?} to map for {region:?}" ) ;
251274 mapping_regions. push ( CounterMappingRegion :: code_region (
252275 counter,
253- local_file_id,
276+ local_file_id. as_u32 ( ) ,
254277 start_line,
255278 start_col,
256279 end_line,
@@ -262,7 +285,7 @@ fn encode_mappings_for_function(
262285 // Encode the function's coverage mappings into a buffer.
263286 llvm:: build_byte_buffer ( |buffer| {
264287 coverageinfo:: write_mapping_to_buffer (
265- virtual_file_mapping. raw ,
288+ virtual_file_mapping. into_vec ( ) ,
266289 expressions,
267290 mapping_regions,
268291 buffer,
0 commit comments