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,
|
/// Using the expressions and counter regions collected for a single function,
|
||||||
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
|
/// generate the variable-sized payload of its corresponding `__llvm_covfun`
|
||||||
/// entry. The payload is returned as a vector of bytes.
|
/// 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 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());
|
let mut mapping_regions = Vec::with_capacity(counter_regions.len());
|
||||||
|
|
||||||
// Sort and group the list of (counter, region) mapping pairs by filename.
|
// 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);
|
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.
|
// 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);
|
let local_file_id = virtual_file_mapping.push_global_id(global_file_id);
|
||||||
debug!(" file id: local {local_file_id} => global {global_file_id} = '{file_name:?}'");
|
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
|
// For each counter/region pair in this function+file, convert it to a
|
||||||
// form suitable for FFI.
|
// form suitable for FFI.
|
||||||
@ -237,7 +260,7 @@ fn encode_mappings_for_function(
|
|||||||
debug!("Adding counter {counter:?} to map for {region:?}");
|
debug!("Adding counter {counter:?} to map for {region:?}");
|
||||||
mapping_regions.push(CounterMappingRegion::code_region(
|
mapping_regions.push(CounterMappingRegion::code_region(
|
||||||
counter,
|
counter,
|
||||||
local_file_id,
|
local_file_id.as_u32(),
|
||||||
start_line,
|
start_line,
|
||||||
start_col,
|
start_col,
|
||||||
end_line,
|
end_line,
|
||||||
@ -249,7 +272,7 @@ fn encode_mappings_for_function(
|
|||||||
// Encode the function's coverage mappings into a buffer.
|
// Encode the function's coverage mappings into a buffer.
|
||||||
llvm::build_byte_buffer(|buffer| {
|
llvm::build_byte_buffer(|buffer| {
|
||||||
coverageinfo::write_mapping_to_buffer(
|
coverageinfo::write_mapping_to_buffer(
|
||||||
virtual_file_mapping.raw,
|
virtual_file_mapping.into_vec(),
|
||||||
expressions,
|
expressions,
|
||||||
mapping_regions,
|
mapping_regions,
|
||||||
buffer,
|
buffer,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#![feature(hash_raw_entry)]
|
#![feature(hash_raw_entry)]
|
||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
#![feature(let_chains)]
|
#![feature(let_chains)]
|
||||||
|
#![feature(min_specialization)]
|
||||||
#![feature(never_type)]
|
#![feature(never_type)]
|
||||||
#![feature(slice_group_by)]
|
#![feature(slice_group_by)]
|
||||||
#![feature(impl_trait_in_assoc_type)]
|
#![feature(impl_trait_in_assoc_type)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user