@@ -163,13 +163,13 @@ impl GlobalFileTable {
163
163
Self { raw_file_table }
164
164
}
165
165
166
- fn global_file_id_for_file_name ( & self , file_name : Symbol ) -> u32 {
166
+ fn global_file_id_for_file_name ( & self , file_name : Symbol ) -> GlobalFileId {
167
167
let raw_id = self . raw_file_table . get_index_of ( & file_name) . unwrap_or_else ( || {
168
168
bug ! ( "file name not found in prepared global file table: {file_name}" ) ;
169
169
} ) ;
170
170
// The raw file table doesn't include an entry for the working dir
171
171
// (which has ID 0), so add 1 to get the correct ID.
172
- ( raw_id + 1 ) as u32
172
+ GlobalFileId :: from_usize ( raw_id + 1 )
173
173
}
174
174
175
175
fn make_filenames_buffer ( & self , tcx : TyCtxt < ' _ > ) -> Vec < u8 > {
@@ -198,27 +198,37 @@ impl GlobalFileTable {
198
198
}
199
199
200
200
rustc_index:: newtype_index! {
201
+ /// An index into the CGU's overall list of file paths. The underlying paths
202
+ /// will be embedded in the `__llvm_covmap` linker section.
203
+ struct GlobalFileId { }
204
+ }
205
+ rustc_index:: newtype_index! {
206
+ /// An index into a function's list of global file IDs. That underlying list
207
+ /// of local-to-global mappings will be embedded in the function's record in
208
+ /// the `__llvm_covfun` linker section.
201
209
struct LocalFileId { }
202
210
}
203
211
204
212
/// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
205
213
/// file IDs.
206
214
#[ derive( Default ) ]
207
215
struct VirtualFileMapping {
208
- local_to_global : IndexVec < LocalFileId , u32 > ,
209
- global_to_local : FxIndexMap < u32 , LocalFileId > ,
216
+ local_to_global : IndexVec < LocalFileId , GlobalFileId > ,
217
+ global_to_local : FxIndexMap < GlobalFileId , LocalFileId > ,
210
218
}
211
219
212
220
impl VirtualFileMapping {
213
- fn local_id_for_global ( & mut self , global_file_id : u32 ) -> LocalFileId {
221
+ fn local_id_for_global ( & mut self , global_file_id : GlobalFileId ) -> LocalFileId {
214
222
* self
215
223
. global_to_local
216
224
. entry ( global_file_id)
217
225
. or_insert_with ( || self . local_to_global . push ( global_file_id) )
218
226
}
219
227
220
228
fn into_vec ( self ) -> Vec < u32 > {
221
- self . local_to_global . raw
229
+ // This conversion should hopefully optimized away to ~zero overhead.
230
+ // Even if it doesn't, it's probably not hot enough to worry about.
231
+ self . local_to_global . into_iter ( ) . map ( |global| global. as_u32 ( ) ) . collect ( )
222
232
}
223
233
}
224
234
@@ -256,7 +266,7 @@ fn encode_mappings_for_function(
256
266
257
267
// Associate that global file ID with a local file ID for this function.
258
268
let local_file_id = virtual_file_mapping. local_id_for_global ( global_file_id) ;
259
- debug ! ( " file id: {local_file_id:?} => global {global_file_id} = '{file_name:?}'" ) ;
269
+ debug ! ( " file id: {local_file_id:?} => {global_file_id:? } = '{file_name:?}'" ) ;
260
270
261
271
// For each counter/region pair in this function+file, convert it to a
262
272
// form suitable for FFI.
0 commit comments