Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
06fe278
Fix unindent behavior between different doc comments
GuillaumeGomez Oct 26, 2020
b4c3536
Add test for doc comments unindent fix
GuillaumeGomez Oct 26, 2020
f3e6d88
Fix typos and replace static vector with slice
bugadani Oct 28, 2020
a21f3a7
Clean up encode_dep_graph
bugadani Oct 28, 2020
5248b20
Reuse memory
bugadani Oct 28, 2020
2fa3598
Avoid reallocating cgu_path_components
bugadani Oct 28, 2020
a8803d3
Delete files immediately, instead of collecting into vector
bugadani Oct 28, 2020
6bbb7fd
Change a bit how the first doc comment lines are handled
GuillaumeGomez Oct 29, 2020
fcee70f
Update tests
GuillaumeGomez Oct 29, 2020
ad27894
Move compiletest meta tests to a separate directory
tmiasko Oct 30, 2020
affb47f
Add a test for compiletest rustc-env & unset-rustc-env directives
tmiasko Oct 30, 2020
289c0d8
Retagging: do not retag 'raw reborrows'
RalfJung Oct 31, 2020
fef9c63
Rust coverage before splitting instrument_coverage.rs
richkadel Oct 5, 2020
0bb09c1
Splitting transform/instrument_coverage.rs into transform/coverage/...
richkadel Oct 23, 2020
7b87ae4
Implemented CoverageGraph of BasicCoverageBlocks
richkadel Oct 23, 2020
af0c84c
Adds coverage graphviz
richkadel Oct 23, 2020
868de57
Injecting expressions in place of counters where helpful
richkadel Oct 22, 2020
da20b67
Added comments on remapping expression IDs, and URL to spanviews
richkadel Oct 25, 2020
0edf4a5
Addressed all feedback to date
richkadel Oct 25, 2020
3685689
Responded to all feedback as of 2020-10-30
richkadel Oct 30, 2020
87f2897
Improve code in unindent_comment a bit more
GuillaumeGomez Nov 1, 2020
c0cbf63
inliner: Remove redundant loop
tmiasko Nov 2, 2020
a8dfb26
Document -Zinstrument-coverage
richkadel Oct 31, 2020
c83c635
Fix intrinsic size_of stable link
pickfire Nov 2, 2020
e78e9d4
Treat trailing semicolon as a statement in macro call
Aaron1011 Oct 25, 2020
6d94911
addressed feedback
richkadel Nov 2, 2020
3d7baee
fix cross-platform test bugs
richkadel Nov 2, 2020
974c03d
Rollup merge of #78267 - richkadel:llvm-coverage-counters-2.0.3r1, r=…
Dylan-DPC Nov 3, 2020
3a110ef
Rollup merge of #78376 - Aaron1011:feature/consistent-empty-expr, r=p…
Dylan-DPC Nov 3, 2020
1425ac0
Rollup merge of #78400 - GuillaumeGomez:fix-unindent, r=jyn514
Dylan-DPC Nov 3, 2020
01e7c01
Rollup merge of #78489 - bugadani:array, r=estebank
Dylan-DPC Nov 3, 2020
5f0c9c1
Rollup merge of #78575 - tmiasko:compiletest-rustc-env, r=Aaron1011
Dylan-DPC Nov 3, 2020
8088713
Rollup merge of #78597 - RalfJung:raw-retag, r=oli-obk
Dylan-DPC Nov 3, 2020
d56e305
Rollup merge of #78616 - richkadel:unstable-book-instr-cov, r=tmandry
Dylan-DPC Nov 3, 2020
bb3ef75
Rollup merge of #78664 - pickfire:patch-4, r=jonas-schievink
Dylan-DPC Nov 3, 2020
04245d1
Rollup merge of #78668 - tmiasko:inline, r=oli-obk
Dylan-DPC Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Addressed all feedback to date
  • Loading branch information
richkadel committed Nov 1, 2020
commit 0edf4a594717b716186983460fdfd7e29a2d9e6f
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,19 @@ impl CoverageInfoBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
fn add_coverage_counter(
&mut self,
instance: Instance<'tcx>,
function_source_hash: u64,
id: CounterValueReference,
region: CodeRegion,
) -> bool {
if let Some(coverage_context) = self.coverage_context() {
debug!(
"adding counter to coverage_map: instance={:?}, function_source_hash={}, id={:?}, \
at {:?}",
instance, function_source_hash, id, region,
"adding counter to coverage_map: instance={:?}, id={:?}, region={:?}",
instance, id, region,
);
let mut coverage_map = coverage_context.function_coverage_map.borrow_mut();
coverage_map
.entry(instance)
.or_insert_with(|| FunctionCoverage::new(self.tcx, instance))
.add_counter(function_source_hash, id, region);
.add_counter(id, region);
true
} else {
false
Expand Down
16 changes: 3 additions & 13 deletions compiler/rustc_codegen_ssa/src/coverageinfo/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,8 @@ impl<'tcx> FunctionCoverage<'tcx> {
}
}

/// Although every function should have at least one `Counter`, the `Counter` isn't required to
/// have a `CodeRegion`. (The `CodeRegion` may be associated only with `Expressions`.) This
/// method supports the ability to ensure the `function_source_hash` is set from `Counters` that
/// do not trigger the call to `add_counter()` because they don't have an associated
/// `CodeRegion` to add.
/// Sets the function source hash value. If called multiple times for the same function, all
/// calls should have the same hash value.
pub fn set_function_source_hash(&mut self, source_hash: u64) {
if self.source_hash == 0 {
self.source_hash = source_hash;
Expand All @@ -66,14 +63,7 @@ impl<'tcx> FunctionCoverage<'tcx> {
}

/// Adds a code region to be counted by an injected counter intrinsic.
/// The source_hash (computed during coverage instrumentation) should also be provided, and
/// should be the same for all counters in a given function.
pub fn add_counter(&mut self, source_hash: u64, id: CounterValueReference, region: CodeRegion) {
if self.source_hash == 0 {
self.source_hash = source_hash;
} else {
debug_assert_eq!(source_hash, self.source_hash);
}
pub fn add_counter(&mut self, id: CounterValueReference, region: CodeRegion) {
self.counters[id].replace(region).expect_none("add_counter called with duplicate `id`");
}

Expand Down
17 changes: 9 additions & 8 deletions compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let Coverage { kind, code_region } = coverage;
match kind {
CoverageKind::Counter { function_source_hash, id } => {
let covmap_updated = if let Some(code_region) = code_region {
// Note: Some counters do not have code regions, but may still be referenced from
// expressions.
bx.add_coverage_counter(self.instance, function_source_hash, id, code_region)
} else {
bx.set_function_source_hash(self.instance, function_source_hash)
};
if bx.set_function_source_hash(self.instance, function_source_hash) {
// If `set_function_source_hash()` returned true, the coverage map is enabled,
// so continue adding the counter.
if let Some(code_region) = code_region {
// Note: Some counters do not have code regions, but may still be referenced
// from expressions. In that case, don't add the counter to the coverage map,
// but do inject the counter intrinsic.
bx.add_coverage_counter(self.instance, id, code_region);
}

if covmap_updated {
let coverageinfo = bx.tcx().coverageinfo(self.instance.def_id());

let fn_name = bx.create_pgo_func_name_var(self.instance);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/traits/coverageinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pub trait CoverageInfoMethods: BackendTypes {
pub trait CoverageInfoBuilderMethods<'tcx>: BackendTypes {
fn create_pgo_func_name_var(&self, instance: Instance<'tcx>) -> Self::Value;

/// Returns true if the function source hash was added to the coverage map; false if
/// `-Z instrument-coverage` is not enabled (a coverage map is not being generated).
/// Returns true if the function source hash was added to the coverage map (even if it had
/// already been added, for this instance). Returns false *only* if `-Z instrument-coverage` is
/// not enabled (a coverage map is not being generated).
fn set_function_source_hash(
&mut self,
instance: Instance<'tcx>,
Expand All @@ -22,7 +23,6 @@ pub trait CoverageInfoBuilderMethods<'tcx>: BackendTypes {
fn add_coverage_counter(
&mut self,
instance: Instance<'tcx>,
function_source_hash: u64,
index: CounterValueReference,
region: CodeRegion,
) -> bool;
Expand Down
14 changes: 0 additions & 14 deletions compiler/rustc_middle/src/mir/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,13 @@ impl From<CounterValueReference> for ExpressionOperandId {
}
}

impl From<&mut CounterValueReference> for ExpressionOperandId {
#[inline]
fn from(v: &mut CounterValueReference) -> ExpressionOperandId {
ExpressionOperandId::from(v.as_u32())
}
}

impl From<InjectedExpressionId> for ExpressionOperandId {
#[inline]
fn from(v: InjectedExpressionId) -> ExpressionOperandId {
ExpressionOperandId::from(v.as_u32())
}
}

impl From<&mut InjectedExpressionId> for ExpressionOperandId {
#[inline]
fn from(v: &mut InjectedExpressionId) -> ExpressionOperandId {
ExpressionOperandId::from(v.as_u32())
}
}

#[derive(Clone, PartialEq, TyEncodable, TyDecodable, HashStable, TypeFoldable)]
pub enum CoverageKind {
Counter {
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_mir/src/transform/coverage/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ use rustc_data_structures::graph::WithNumNodes;
use rustc_index::bit_set::BitSet;
use rustc_middle::mir::coverage::*;

// When evaluating an expression operand to determine if it references a `Counter` or an
// `Expression`, the range of counter or expression IDs must be known in order to answer the
// question: "Does this ID fall inside the range of counters," for example. If "yes," the ID refers
// to a counter, otherwise the ID refers to an expression.
//
// But in situations where the range is not currently known, the only fallback is to assume a
// specific range limit. `MAX_COUNTER_GUARD` enforces a limit on the number of counters, and
// therefore a limit on the range of counter IDs.
pub(crate) const MAX_COUNTER_GUARD: u32 = (u32::MAX / 2) + 1;

/// Manages the counter and expression indexes/IDs to generate `CoverageKind` components for MIR
/// `Coverage` statements.
pub(crate) struct CoverageCounters {
Expand Down Expand Up @@ -95,6 +105,7 @@ impl CoverageCounters {
/// Counter IDs start from one and go up.
fn next_counter(&mut self) -> CounterValueReference {
assert!(self.next_counter_id < u32::MAX - self.num_expressions);
assert!(self.next_counter_id <= MAX_COUNTER_GUARD);
let next = self.next_counter_id;
self.next_counter_id += 1;
CounterValueReference::from(next)
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_mir/src/transform/coverage/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use super::counters;

use rustc_middle::mir::coverage::*;
use rustc_middle::mir::visit::Visitor;
use rustc_middle::mir::{Coverage, CoverageInfo, Location};
Expand Down Expand Up @@ -32,21 +34,16 @@ pub(crate) fn provide(providers: &mut Providers) {
/// safeguard, with `add_missing_operands` set to `true`, to find any other counter or expression
/// IDs referenced by expression operands, if not already seen.
///
/// Ideally, every expression operand in the MIR will have a corresponding Counter or Expression,
/// but since current or future MIR optimizations can theoretically optimize out segments of a
/// MIR, it may not be possible to guarantee this, so the second pass ensures the `CoverageInfo`
/// counts include all referenced IDs.
/// Ideally, each operand ID in a MIR `CoverageKind::Expression` will have a separate MIR `Coverage`
/// statement for the `Counter` or `Expression` with the referenced ID. but since current or future
/// MIR optimizations can theoretically optimize out segments of a MIR, it may not be possible to
/// guarantee this, so the second pass ensures the `CoverageInfo` counts include all referenced IDs.
struct CoverageVisitor {
info: CoverageInfo,
add_missing_operands: bool,
}

impl CoverageVisitor {
// If an expression operand is encountered with an ID outside the range of known counters and
// expressions, the only way to determine if the ID is a counter ID or an expression ID is to
// assume a maximum possible counter ID value.
const MAX_COUNTER_GUARD: u32 = (u32::MAX / 2) + 1;

#[inline(always)]
fn update_num_counters(&mut self, counter_id: u32) {
self.info.num_counters = std::cmp::max(self.info.num_counters, counter_id + 1);
Expand All @@ -62,7 +59,10 @@ impl CoverageVisitor {
if operand_id >= self.info.num_counters {
let operand_as_expression_index = u32::MAX - operand_id;
if operand_as_expression_index >= self.info.num_expressions {
if operand_id <= Self::MAX_COUNTER_GUARD {
if operand_id <= counters::MAX_COUNTER_GUARD {
// Since the complete range of counter and expression IDs is not known here, the
// only way to determine if the ID is a counter ID or an expression ID is to
// assume a maximum possible counter ID value.
self.update_num_counters(operand_id)
} else {
self.update_num_expressions(operand_id)
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir/src/transform/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
bcb_data
.basic_blocks
.iter()
.map(|bbref| {
let bb = *bbref;
.flat_map(|&bb| {
let data = &self.mir_body[bb];
data.statements
.iter()
Expand All @@ -404,7 +403,6 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
.map(|span| CoverageSpan::for_terminator(span, bcb, bb)),
)
})
.flatten()
.collect()
}

Expand Down Expand Up @@ -733,7 +731,7 @@ fn filtered_terminator_span(terminator: &'a Terminator<'tcx>, body_span: Span) -
// However, in other cases, a visible `CoverageSpan` is not wanted, but the `Goto`
// block must still be counted (for example, to contribute its count to an `Expression`
// that reports the execution count for some other block). In these cases, the code region
// is set to `None`.
// is set to `None`. (See `Instrumentor::is_code_region_redundant()`.)
TerminatorKind::Goto { .. } => {
Some(function_source_span(terminator.source_info.span.shrink_to_hi(), body_span))
}
Expand Down