coverage: Encapsulate local-to-global file mappings
This commit is contained in:
parent
e985ae5a45
commit
88159cafa7
@ -194,6 +194,29 @@ impl GlobalFileTable {
|
||||
}
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
// Tell the newtype macro to not generate `Encode`/`Decode` impls.
|
||||
#[custom_encodable]
|
||||
struct LocalFileId {}
|
||||
}
|
||||
|
||||
/// Holds a mapping from "local" (per-function) file IDs to "global" (per-CGU)
|
||||
/// file IDs.
|
||||
#[derive(Default)]
|
||||
struct VirtualFileMapping {
|
||||
local_to_global: IndexVec<LocalFileId, u32>,
|
||||
}
|
||||
|
||||
impl VirtualFileMapping {
|
||||
fn push_global_id(&mut self, global_file_id: u32) -> LocalFileId {
|
||||
self.local_to_global.push(global_file_id)
|
||||
}
|
||||
|
||||
fn into_vec(self) -> Vec<u32> {
|
||||
self.local_to_global.raw
|
||||
}
|
||||
}
|
||||
|
||||
/// Using the expressions and counter regions collected for a single function,
|
||||
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
|
||||
/// entry. The payload is returned as a vector of bytes.
|
||||
@ -210,7 +233,7 @@ fn encode_mappings_for_function(
|
||||
|
||||
let expressions = function_coverage.counter_expressions().collect::<Vec<_>>();
|
||||
|
||||
let mut virtual_file_mapping = IndexVec::<u32, u32>::new();
|
||||
let mut virtual_file_mapping = VirtualFileMapping::default();
|
||||
let mut mapping_regions = Vec::with_capacity(counter_regions.len());
|
||||
|
||||
// Sort and group the list of (counter, region) mapping pairs by filename.
|
||||
@ -226,8 +249,8 @@ fn encode_mappings_for_function(
|
||||
let global_file_id = global_file_table.global_file_id_for_file_name(file_name);
|
||||
|
||||
// Associate that global file ID with a local file ID for this function.
|
||||
let local_file_id: u32 = virtual_file_mapping.push(global_file_id);
|
||||
debug!(" file id: local {local_file_id} => global {global_file_id} = '{file_name:?}'");
|
||||
let local_file_id = virtual_file_mapping.push_global_id(global_file_id);
|
||||
debug!(" file id: {local_file_id:?} => global {global_file_id} = '{file_name:?}'");
|
||||
|
||||
// For each counter/region pair in this function+file, convert it to a
|
||||
// form suitable for FFI.
|
||||
@ -237,7 +260,7 @@ fn encode_mappings_for_function(
|
||||
debug!("Adding counter {counter:?} to map for {region:?}");
|
||||
mapping_regions.push(CounterMappingRegion::code_region(
|
||||
counter,
|
||||
local_file_id,
|
||||
local_file_id.as_u32(),
|
||||
start_line,
|
||||
start_col,
|
||||
end_line,
|
||||
@ -249,7 +272,7 @@ fn encode_mappings_for_function(
|
||||
// Encode the function's coverage mappings into a buffer.
|
||||
llvm::build_byte_buffer(|buffer| {
|
||||
coverageinfo::write_mapping_to_buffer(
|
||||
virtual_file_mapping.raw,
|
||||
virtual_file_mapping.into_vec(),
|
||||
expressions,
|
||||
mapping_regions,
|
||||
buffer,
|
||||
|
@ -12,6 +12,7 @@
|
||||
#![feature(hash_raw_entry)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(let_chains)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(slice_group_by)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
|
Loading…
x
Reference in New Issue
Block a user