Skip to content

Rollup of 6 pull requests #136804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 132 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
a8f5471
fix: upmap ranges in convert_tuple_struct_to_named_struct assist
vishruth-thimmaiah Jan 16, 2025
1f45995
manual: Convert to mdbook
Wilfred Jan 23, 2025
b46775a
Combine `pat_hyigene` and `expr_hygiene`
Veykril Jan 25, 2025
8e7a338
BodyCollector
Veykril Jan 25, 2025
d9c58c8
Cleanup body ast ptr defs
Veykril Jan 25, 2025
c679d56
Split out `ExpressionStore` from `Body`
Veykril Jan 25, 2025
bdebd86
Add GenericDefId::StaticId
Veykril Jan 26, 2025
1360b4c
In completion's expand, consider recursion stop condition (when we're…
ChayimFriedman2 Jan 26, 2025
5de2cd4
Support RFC 2396
ChayimFriedman2 Jan 26, 2025
9051647
Merge pull request #19038 from ChayimFriedman2/unused-unsafe
Veykril Jan 27, 2025
6db1411
Merge pull request #19037 from ChayimFriedman2/fix-other-test
Veykril Jan 27, 2025
1711a19
Merge pull request #19036 from Veykril/push-nprltlwvryxw
Veykril Jan 27, 2025
d18afd3
feat: Implement `default-field-values`
ShoyuVanilla Jan 22, 2025
5ca9f52
Handle missing fields diagnostics
ShoyuVanilla Jan 23, 2025
2622160
Merge record lit's ellipsis into pre-existing spread's variant
ShoyuVanilla Jan 26, 2025
faeaf4a
Compute diagnostics of a field body iff it has one
ShoyuVanilla Jan 26, 2025
c7463fe
Implement `HasResolver` and `HasModule` for `FieldId`
ShoyuVanilla Jan 26, 2025
ec89b7d
Add a test for field default value body as defining usage of TAIT
ShoyuVanilla Jan 26, 2025
e4e7c95
Fix a mistake in condition
ShoyuVanilla Jan 26, 2025
c093db0
Remove `has_default` from `FieldId`
ShoyuVanilla Jan 27, 2025
ad0aea4
Merge pull request #19001 from ShoyuVanilla/default-field-values
Veykril Jan 27, 2025
9a0504b
Fix #[rustc_deprecated_safe_2024]
ChayimFriedman2 Jan 27, 2025
86d5e29
Fix a missing standard token in semantic highlighting
ChayimFriedman2 Jan 27, 2025
238d7bd
Merge pull request #19045 from ChayimFriedman2/missing-token
Veykril Jan 27, 2025
0fe9d77
Merge pull request #19044 from ChayimFriedman2/deprecated-safe
Veykril Jan 27, 2025
5f2072c
Fix syntactic highlighting for renames
lnicola Jan 27, 2025
d60afec
Merge pull request #19047 from lnicola/rename-highlight
lnicola Jan 27, 2025
78feee8
Remove duplicate method from `hir::Type`
ChayimFriedman2 Jan 27, 2025
b4508dc
Don't suggest `into_iter().method()` on iterators
ChayimFriedman2 Jan 27, 2025
1ba8943
Report calling unsafe fn pointer as unsafe
ChayimFriedman2 Jan 27, 2025
26c5708
Prioritize formatting thread tasks in main_loop
Veykril Jan 27, 2025
30b6063
Merge pull request #19052 from Veykril/push-yqwutllwwyyp
Veykril Jan 27, 2025
8ed9227
Merge pull request #19049 from ChayimFriedman2/add-reference-ty
Veykril Jan 27, 2025
da33e7c
Merge pull request #19050 from ChayimFriedman2/iter-self
Veykril Jan 27, 2025
cadc468
Merge pull request #19051 from ChayimFriedman2/fn-ptr-unsafe
Veykril Jan 27, 2025
3dd95e3
Add FreeBSD as a target OS for TestDir to avoid warnings
vkrivopalov Jan 27, 2025
7268b3d
fix: Properly handle CRLF line endings in the syntax tree view
Giga-Bowser Jan 27, 2025
165f276
Merge pull request #19055 from vkrivopalov/fix-testdir-unused-variabl…
ChayimFriedman2 Jan 27, 2025
a9cd21f
Show status bar in RA output
darichey Jan 27, 2025
a4e6556
Back out "Remove `has_default` from `FieldId`"
davidbarsky Jan 27, 2025
ff2656d
Back out "Fix a mistake in condition"
davidbarsky Jan 27, 2025
f22e331
Back out "Add a test for field default value body as defining usage o…
davidbarsky Jan 27, 2025
9c1a7ab
Back out "Implement `HasResolver` and `HasModule` for `FieldId`"
davidbarsky Jan 27, 2025
6f723ee
Back out "Compute diagnostics of a field body iff it has one"
davidbarsky Jan 27, 2025
10089c2
Back out "Merge record lit's ellipsis into pre-existing spread's vari…
davidbarsky Jan 27, 2025
d039b10
Back out "Handle missing fields diagnostics"
davidbarsky Jan 27, 2025
0f9cdeb
Back out "feat: Implement `default-field-values`"
davidbarsky Jan 27, 2025
1eb9f5e
Fix scip inherent impl overflow
darichey Jan 28, 2025
8e68c3f
Disable `Receiver` based autoderef temporarily
Veykril Jan 28, 2025
82efe0f
Merge pull request #19061 from Veykril/push-rwyqqtqmnput
Veykril Jan 28, 2025
0a2221d
Fix scip `crate` symbol name
darichey Jan 28, 2025
f70ac25
Merge pull request #19057 from darichey/status-bar-in-output
Veykril Jan 28, 2025
8ecb754
Merge pull request #19056 from Giga-Bowser/fix-syntax-tree-crlf
Veykril Jan 28, 2025
d417284
Fix scip symbols for implicit modules
darichey Jan 28, 2025
a355626
Merge pull request #19015 from Wilfred/mdbook
Veykril Jan 28, 2025
f10b622
feat: Implement `default-field-values` only in parser
ShoyuVanilla Jan 28, 2025
19afce0
Update lsif_contains_generated_constant
darichey Jan 28, 2025
2386e95
Merge pull request #19063 from davidbarsky/davidbarsky/backout-struct…
davidbarsky Jan 28, 2025
db07adf
try to infer array type from slice pattern
alibektas Jan 28, 2025
fc6c6b4
add test, bless tests
alibektas Jan 28, 2025
14ab466
Equip infer_pat_* with declaration origin
alibektas Jan 28, 2025
437921f
call infer_pats from infer::expr with context
alibektas Jan 28, 2025
717d36a
Simplify Rc::as_ptr docs + typo fix
hkBst Jan 29, 2025
22b8339
Update TentHash to version 1.0
cessen Jan 29, 2025
ce8bace
Merge pull request #19067 from cessen/update_tenthash
lnicola Jan 29, 2025
0d9355e
Remove mutable syntax tree shenanigans from adjustment hints
Veykril Jan 29, 2025
9c30fec
Merge pull request #19070 from Veykril/push-wpqzmznymtrn
Veykril Jan 29, 2025
0cf275b
Fix #19071: ensure `completion_item_hash` serializes items uniquely
cessen Jan 29, 2025
6151865
Fix typo
cessen Jan 29, 2025
7ffccb0
Use `to_ne_bytes` instead of `to_le_bytes`
cessen Jan 29, 2025
da96fff
Merge pull request #19072 from cessen/concat_uniquely
lnicola Jan 30, 2025
e70b589
Stop running some release workflows on forks and update old URLs
lnicola Feb 1, 2025
bec452f
Merge pull request #19078 from lnicola/no-ci-forks
lnicola Feb 1, 2025
acb9544
More rustfmt hang investigations
Veykril Feb 2, 2025
3288929
Merge pull request #19080 from Veykril/push-wlqsvqsksupr
Veykril Feb 2, 2025
4d9be70
Split cache priming into distinct phases
Veykril Feb 3, 2025
3c83458
Merge pull request #19062 from darichey/scip-fix-module-names
Veykril Feb 3, 2025
806ec88
Revert tests::patterns::infer_pattern
alibektas Jan 28, 2025
5acbff8
Do not use make use of `InferenceResult::has_errors` flag for mir bui…
Veykril Feb 3, 2025
9c981b7
Merge pull request #19085 from Veykril/push-sknwykqmlott
Veykril Feb 3, 2025
a118b18
Fix some mir eval/lowerings
Veykril Feb 3, 2025
08d4b03
Merge pull request #19086 from Veykril/push-ponvylutpnww
Veykril Feb 3, 2025
93b72ce
Merge pull request #19066 from alibektas/slice_pattern_type_inference
Veykril Feb 3, 2025
4677d75
ci: stop mysql before removing it
marcoieni Feb 3, 2025
a373fb2
Expose symbol of `CrateName`
Veykril Feb 3, 2025
1ba7a38
Merge pull request #19084 from Veykril/push-muworpzpzqup
Veykril Feb 4, 2025
1ce2d7e
Prevent panics from tearing down worker threads
Veykril Feb 4, 2025
21ddcbb
Merge pull request #19093 from Veykril/push-lrvoookylnxp
Veykril Feb 4, 2025
9bf4fe4
line-index: don't try to use neon on big-endian aarch64.
he32 Feb 4, 2025
96f96a4
Merge pull request #19083 from he32/fix-arm64-be
lnicola Feb 4, 2025
5467091
Fix IDE resolution of `use` inside a body
ChayimFriedman2 Feb 4, 2025
9d81503
Fix a failing test
ChayimFriedman2 Feb 4, 2025
578ae16
Add a FIXME for feature(adt_const_params)
ChayimFriedman2 Feb 4, 2025
d958719
Merge pull request #19095 from ChayimFriedman2/fixme-adt_const_params
ChayimFriedman2 Feb 4, 2025
dfca140
Add Four Codegen Tests
veera-sivarajan Dec 21, 2024
4b1d83d
Merge pull request #19094 from ChayimFriedman2/use-body
lnicola Feb 5, 2025
f57caa1
Bump proc-macro2 in xtask
Veykril Feb 5, 2025
9c0af74
Merge pull request #19097 from Veykril/push-xmkmkwplqnlr
Veykril Feb 5, 2025
a7e9739
Merge pull request #18912 from vishruth-thimmaiah/fix_named_struct_as…
Veykril Feb 5, 2025
9bcb2b0
Use interior mutability for loaded `ProcMacrorv::expanders`
Veykril Feb 5, 2025
d18dd4d
Merge pull request #19099 from Veykril/push-qxylslwltsqy
Veykril Feb 5, 2025
ee7dc06
coverage: Store BCB node IDs in mappings, and resolve them in codegen
Zalathar Jan 20, 2025
20d051e
coverage: Defer part of counter-creation until codegen
Zalathar Jan 22, 2025
bf1f254
coverage: Don't create counters for code that was removed by MIR opts
Zalathar Jan 25, 2025
bd855b6
coverage: Remove the old code for simplifying counters after MIR opts
Zalathar Jan 25, 2025
98b16ea
closure parameter inlay hints
jnyfah Feb 6, 2025
57b2415
collapsing if statement
jnyfah Feb 6, 2025
e8955a8
fix: Don't emit empty scip occurrence for builtins
darichey Feb 6, 2025
bacc9df
fix: Resolve projection types before checking casts
ShoyuVanilla Feb 7, 2025
b27a0f4
Merge pull request #19105 from darichey/fix-scip-builtin-occurrences
Veykril Feb 7, 2025
cde8d92
Merge pull request #19106 from ShoyuVanilla/issue-18682
Veykril Feb 7, 2025
d3b80e1
minor changes
jnyfah Feb 7, 2025
8151886
Merge pull request #19104 from jnyfah/some-branch
Veykril Feb 7, 2025
2c22ae3
Update PRIVACY.md
BenjaminBrienen Feb 7, 2025
e7d5d30
Update README.md links for mdbook manual
Wilfred Feb 7, 2025
b6fd709
Organise chapters in mdbook sidebar
Wilfred Feb 7, 2025
236000b
Merge pull request #19114 from Wilfred/update_readme_for_mdbook
lnicola Feb 8, 2025
cac45e1
Merge pull request #19115 from Wilfred/sidebar_structure
lnicola Feb 8, 2025
4ac07f2
Merge pull request #19113 from BenjaminBrienen/patch-1
lnicola Feb 8, 2025
82162a7
doc: error url
ahaoboy Feb 9, 2025
d4f7c76
Merge pull request #19120 from ahaoboy/patch-1
ChayimFriedman2 Feb 9, 2025
9a73f5a
Git blame ignore recent formatting commit
ehuss Feb 9, 2025
879dc38
Preparing for merge from rust-lang/rust
lnicola Feb 10, 2025
15cd1f0
Merge from rust-lang/rust
lnicola Feb 10, 2025
24d7a14
Bump rustc crates
lnicola Feb 10, 2025
8fd713b
Merge pull request #19126 from lnicola/sync-from-rust
lnicola Feb 10, 2025
97e92e3
Rollup merge of #134626 - veera-sivarajan:five-codegen-tests, r=Mark-…
Zalathar Feb 10, 2025
7a88710
Rollup merge of #136053 - Zalathar:defer-counters, r=saethlin
Zalathar Feb 10, 2025
46c7e2c
Rollup merge of #136228 - hkBst:patch-28, r=Mark-Simulacrum
Zalathar Feb 10, 2025
fff8baa
Rollup merge of #136487 - marcoieni:disable-mysql-systemctl, r=Mark-S…
Zalathar Feb 10, 2025
ed94e34
Rollup merge of #136790 - ehuss:ignore-rustfmt-2024-again, r=compiler…
Zalathar Feb 10, 2025
1417031
Rollup merge of #136803 - lnicola:sync-from-ra, r=lnicola
Zalathar Feb 10, 2025
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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ec2cc761bc7067712ecc7734502f703fe3b024c8
99cb0c6bc399fb94a0ddde7e9b38e9c00d523bad
# reformat with rustfmt edition 2024
c682aa162b0d41e21cc6748f4fecfe01efb69d1f
# reformat with updated edition 2024
1fcae03369abb4c2cc180cd5a49e1f4440a81300
55 changes: 24 additions & 31 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use rustc_codegen_ssa::traits::{
BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods,
};
use rustc_middle::mir::coverage::{
CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping, MappingKind, Op,
BasicCoverageBlock, CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping,
MappingKind, Op,
};
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_span::Span;
Expand Down Expand Up @@ -53,7 +54,7 @@ pub(crate) fn prepare_covfun_record<'tcx>(
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
let ids_info = tcx.coverage_ids_info(instance.def)?;

let expressions = prepare_expressions(fn_cov_info, ids_info, is_used);
let expressions = prepare_expressions(ids_info);

let mut covfun = CovfunRecord {
mangled_function_name: tcx.symbol_name(instance).name,
Expand All @@ -75,26 +76,14 @@ pub(crate) fn prepare_covfun_record<'tcx>(
}

/// Convert the function's coverage-counter expressions into a form suitable for FFI.
fn prepare_expressions(
fn_cov_info: &FunctionCoverageInfo,
ids_info: &CoverageIdsInfo,
is_used: bool,
) -> Vec<ffi::CounterExpression> {
// If any counters or expressions were removed by MIR opts, replace their
// terms with zero.
let counter_for_term = |term| {
if !is_used || ids_info.is_zero_term(term) {
ffi::Counter::ZERO
} else {
ffi::Counter::from_term(term)
}
};
fn prepare_expressions(ids_info: &CoverageIdsInfo) -> Vec<ffi::CounterExpression> {
let counter_for_term = ffi::Counter::from_term;

// We know that LLVM will optimize out any unused expressions before
// producing the final coverage map, so there's no need to do the same
// thing on the Rust side unless we're confident we can do much better.
// (See `CounterExpressionsMinimizer` in `CoverageMappingWriter.cpp`.)
fn_cov_info
ids_info
.expressions
.iter()
.map(move |&Expression { lhs, op, rhs }| ffi::CounterExpression {
Expand Down Expand Up @@ -136,11 +125,16 @@ fn fill_region_tables<'tcx>(

// For each counter/region pair in this function+file, convert it to a
// form suitable for FFI.
let is_zero_term = |term| !covfun.is_used || ids_info.is_zero_term(term);
for &Mapping { ref kind, span } in &fn_cov_info.mappings {
// If the mapping refers to counters/expressions that were removed by
// MIR opts, replace those occurrences with zero.
let kind = kind.map_terms(|term| if is_zero_term(term) { CovTerm::Zero } else { term });
// If this function is unused, replace all counters with zero.
let counter_for_bcb = |bcb: BasicCoverageBlock| -> ffi::Counter {
let term = if covfun.is_used {
ids_info.term_for_bcb[bcb].expect("every BCB in a mapping was given a term")
} else {
CovTerm::Zero
};
ffi::Counter::from_term(term)
};

// Convert the `Span` into coordinates that we can pass to LLVM, or
// discard the span if conversion fails. In rare, cases _all_ of a
Expand All @@ -154,23 +148,22 @@ fn fill_region_tables<'tcx>(
continue;
}

match kind {
MappingKind::Code(term) => {
code_regions
.push(ffi::CodeRegion { cov_span, counter: ffi::Counter::from_term(term) });
match *kind {
MappingKind::Code { bcb } => {
code_regions.push(ffi::CodeRegion { cov_span, counter: counter_for_bcb(bcb) });
}
MappingKind::Branch { true_term, false_term } => {
MappingKind::Branch { true_bcb, false_bcb } => {
branch_regions.push(ffi::BranchRegion {
cov_span,
true_counter: ffi::Counter::from_term(true_term),
false_counter: ffi::Counter::from_term(false_term),
true_counter: counter_for_bcb(true_bcb),
false_counter: counter_for_bcb(false_bcb),
});
}
MappingKind::MCDCBranch { true_term, false_term, mcdc_params } => {
MappingKind::MCDCBranch { true_bcb, false_bcb, mcdc_params } => {
mcdc_branch_regions.push(ffi::MCDCBranchRegion {
cov_span,
true_counter: ffi::Counter::from_term(true_term),
false_counter: ffi::Counter::from_term(false_term),
true_counter: counter_for_bcb(true_bcb),
false_counter: counter_for_bcb(false_bcb),
mcdc_branch_params: ffi::mcdc::BranchParameters::from(mcdc_params),
});
}
Expand Down
23 changes: 6 additions & 17 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,32 +160,21 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
CoverageKind::SpanMarker | CoverageKind::BlockMarker { .. } => unreachable!(
"marker statement {kind:?} should have been removed by CleanupPostBorrowck"
),
CoverageKind::CounterIncrement { id } => {
// The number of counters passed to `llvm.instrprof.increment` might
// be smaller than the number originally inserted by the instrumentor,
// if some high-numbered counters were removed by MIR optimizations.
// If so, LLVM's profiler runtime will use fewer physical counters.
let num_counters = ids_info.num_counters_after_mir_opts();
assert!(
num_counters as usize <= function_coverage_info.num_counters,
"num_counters disagreement: query says {num_counters} but function info only has {}",
function_coverage_info.num_counters
);

CoverageKind::VirtualCounter { bcb }
if let Some(&id) = ids_info.phys_counter_for_node.get(&bcb) =>
{
let fn_name = bx.get_pgo_func_name_var(instance);
let hash = bx.const_u64(function_coverage_info.function_source_hash);
let num_counters = bx.const_u32(num_counters);
let num_counters = bx.const_u32(ids_info.num_counters);
let index = bx.const_u32(id.as_u32());
debug!(
"codegen intrinsic instrprof.increment(fn_name={:?}, hash={:?}, num_counters={:?}, index={:?})",
fn_name, hash, num_counters, index,
);
bx.instrprof_increment(fn_name, hash, num_counters, index);
}
CoverageKind::ExpressionUsed { id: _ } => {
// Expression-used statements are markers that are handled by
// `coverage_ids_info`, so there's nothing to codegen here.
}
// If a BCB doesn't have an associated physical counter, there's nothing to codegen.
CoverageKind::VirtualCounter { .. } => {}
CoverageKind::CondBitmapUpdate { index, decision_depth } => {
let cond_bitmap = coverage_cx
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#![feature(extern_types)]
#![feature(file_buffered)]
#![feature(hash_raw_entry)]
#![feature(if_let_guard)]
#![feature(impl_trait_in_assoc_type)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
Expand Down
139 changes: 66 additions & 73 deletions compiler/rustc_middle/src/mir/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::fmt::{self, Debug, Formatter};

use rustc_index::IndexVec;
use rustc_index::bit_set::DenseBitSet;
use rustc_data_structures::fx::FxIndexMap;
use rustc_index::{Idx, IndexVec};
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use rustc_span::Span;

Expand Down Expand Up @@ -103,23 +103,12 @@ pub enum CoverageKind {
/// Should be erased before codegen (at some point after `InstrumentCoverage`).
BlockMarker { id: BlockMarkerId },

/// Marks the point in MIR control flow represented by a coverage counter.
/// Marks its enclosing basic block with the ID of the coverage graph node
/// that it was part of during the `InstrumentCoverage` MIR pass.
///
/// This is eventually lowered to `llvm.instrprof.increment` in LLVM IR.
///
/// If this statement does not survive MIR optimizations, any mappings that
/// refer to this counter can have those references simplified to zero.
CounterIncrement { id: CounterId },

/// Marks the point in MIR control-flow represented by a coverage expression.
///
/// If this statement does not survive MIR optimizations, any mappings that
/// refer to this expression can have those references simplified to zero.
///
/// (This is only inserted for expression IDs that are directly used by
/// mappings. Intermediate expressions with no direct mappings are
/// retained/zeroed based on whether they are transitively used.)
ExpressionUsed { id: ExpressionId },
/// During codegen, this might be lowered to `llvm.instrprof.increment` or
/// to a no-op, depending on the outcome of counter-creation.
VirtualCounter { bcb: BasicCoverageBlock },

/// Marks the point in MIR control flow represented by a evaluated condition.
///
Expand All @@ -138,8 +127,7 @@ impl Debug for CoverageKind {
match self {
SpanMarker => write!(fmt, "SpanMarker"),
BlockMarker { id } => write!(fmt, "BlockMarker({:?})", id.index()),
CounterIncrement { id } => write!(fmt, "CounterIncrement({:?})", id.index()),
ExpressionUsed { id } => write!(fmt, "ExpressionUsed({:?})", id.index()),
VirtualCounter { bcb } => write!(fmt, "VirtualCounter({bcb:?})"),
CondBitmapUpdate { index, decision_depth } => {
write!(fmt, "CondBitmapUpdate(index={:?}, depth={:?})", index, decision_depth)
}
Expand Down Expand Up @@ -179,34 +167,19 @@ pub struct Expression {
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
pub enum MappingKind {
/// Associates a normal region of code with a counter/expression/zero.
Code(CovTerm),
Code { bcb: BasicCoverageBlock },
/// Associates a branch region with separate counters for true and false.
Branch { true_term: CovTerm, false_term: CovTerm },
Branch { true_bcb: BasicCoverageBlock, false_bcb: BasicCoverageBlock },
/// Associates a branch region with separate counters for true and false.
MCDCBranch { true_term: CovTerm, false_term: CovTerm, mcdc_params: ConditionInfo },
MCDCBranch {
true_bcb: BasicCoverageBlock,
false_bcb: BasicCoverageBlock,
mcdc_params: ConditionInfo,
},
/// Associates a decision region with a bitmap and number of conditions.
MCDCDecision(DecisionInfo),
}

impl MappingKind {
/// Returns a copy of this mapping kind, in which all coverage terms have
/// been replaced with ones returned by the given function.
pub fn map_terms(&self, map_fn: impl Fn(CovTerm) -> CovTerm) -> Self {
match *self {
Self::Code(term) => Self::Code(map_fn(term)),
Self::Branch { true_term, false_term } => {
Self::Branch { true_term: map_fn(true_term), false_term: map_fn(false_term) }
}
Self::MCDCBranch { true_term, false_term, mcdc_params } => Self::MCDCBranch {
true_term: map_fn(true_term),
false_term: map_fn(false_term),
mcdc_params,
},
Self::MCDCDecision(param) => Self::MCDCDecision(param),
}
}
}

#[derive(Clone, Debug)]
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
pub struct Mapping {
Expand All @@ -222,10 +195,15 @@ pub struct Mapping {
pub struct FunctionCoverageInfo {
pub function_source_hash: u64,
pub body_span: Span,
pub num_counters: usize,
pub mcdc_bitmap_bits: usize,
pub expressions: IndexVec<ExpressionId, Expression>,

/// Used in conjunction with `priority_list` to create physical counters
/// and counter expressions, after MIR optimizations.
pub node_flow_data: NodeFlowData<BasicCoverageBlock>,
pub priority_list: Vec<BasicCoverageBlock>,

pub mappings: Vec<Mapping>,

pub mcdc_bitmap_bits: usize,
/// The depth of the deepest decision is used to know how many
/// temp condbitmaps should be allocated for the function.
pub mcdc_num_condition_bitmaps: usize,
Expand Down Expand Up @@ -292,40 +270,55 @@ pub struct MCDCDecisionSpan {
pub num_conditions: usize,
}

/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
/// have had a chance to potentially remove some of them.
/// Contains information needed during codegen, obtained by inspecting the
/// function's MIR after MIR optimizations.
///
/// Used by the `coverage_ids_info` query.
/// Returned by the `coverage_ids_info` query.
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable)]
pub struct CoverageIdsInfo {
pub counters_seen: DenseBitSet<CounterId>,
pub zero_expressions: DenseBitSet<ExpressionId>,
pub num_counters: u32,
pub phys_counter_for_node: FxIndexMap<BasicCoverageBlock, CounterId>,
pub term_for_bcb: IndexVec<BasicCoverageBlock, Option<CovTerm>>,
pub expressions: IndexVec<ExpressionId, Expression>,
}

impl CoverageIdsInfo {
/// Coverage codegen needs to know how many coverage counters are ever
/// incremented within a function, so that it can set the `num-counters`
/// argument of the `llvm.instrprof.increment` intrinsic.
rustc_index::newtype_index! {
/// During the `InstrumentCoverage` MIR pass, a BCB is a node in the
/// "coverage graph", which is a refinement of the MIR control-flow graph
/// that merges or omits some blocks that aren't relevant to coverage.
///
/// This may be less than the highest counter ID emitted by the
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
/// were removed by MIR optimizations.
pub fn num_counters_after_mir_opts(&self) -> u32 {
// FIXME(Zalathar): Currently this treats an unused counter as "used"
// if its ID is less than that of the highest counter that really is
// used. Fixing this would require adding a renumbering step somewhere.
self.counters_seen.last_set_in(..).map_or(0, |max| max.as_u32() + 1)
/// After that pass is complete, the coverage graph no longer exists, so a
/// BCB is effectively an opaque ID.
#[derive(HashStable)]
#[encodable]
#[orderable]
#[debug_format = "bcb{}"]
pub struct BasicCoverageBlock {
const START_BCB = 0;
}
}

/// Returns `true` if the given term is known to have a value of zero, taking
/// into account knowledge of which counters are unused and which expressions
/// are always zero.
pub fn is_zero_term(&self, term: CovTerm) -> bool {
match term {
CovTerm::Zero => true,
CovTerm::Counter(id) => !self.counters_seen.contains(id),
CovTerm::Expression(id) => self.zero_expressions.contains(id),
}
}
/// Data representing a view of some underlying graph, in which each node's
/// successors have been merged into a single "supernode".
///
/// The resulting supernodes have no obvious meaning on their own.
/// However, merging successor nodes means that a node's out-edges can all
/// be combined into a single out-edge, whose flow is the same as the flow
/// (execution count) of its corresponding node in the original graph.
///
/// With all node flows now in the original graph now represented as edge flows
/// in the merged graph, it becomes possible to analyze the original node flows
/// using techniques for analyzing edge flows.
#[derive(Clone, Debug)]
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
pub struct NodeFlowData<Node: Idx> {
/// Maps each node to the supernode that contains it, indicated by some
/// arbitrary "root" node that is part of that supernode.
pub supernodes: IndexVec<Node, Node>,
/// For each node, stores the single supernode that all of its successors
/// have been merged into.
///
/// (Note that each node in a supernode can potentially have a _different_
/// successor supernode from its peers.)
pub succ_supernodes: IndexVec<Node, Node>,
}
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,9 @@ fn write_function_coverage_info(
function_coverage_info: &coverage::FunctionCoverageInfo,
w: &mut dyn io::Write,
) -> io::Result<()> {
let coverage::FunctionCoverageInfo { body_span, expressions, mappings, .. } =
function_coverage_info;
let coverage::FunctionCoverageInfo { body_span, mappings, .. } = function_coverage_info;

writeln!(w, "{INDENT}coverage body span: {body_span:?}")?;
for (id, expression) in expressions.iter_enumerated() {
writeln!(w, "{INDENT}coverage {id:?} => {expression:?};")?;
}
for coverage::Mapping { kind, span } in mappings {
writeln!(w, "{INDENT}coverage {kind:?} => {span:?};")?;
}
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,16 @@ rustc_queries! {
feedable
}

/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
/// have had a chance to potentially remove some of them.
/// Scans through a function's MIR after MIR optimizations, to prepare the
/// information needed by codegen when `-Cinstrument-coverage` is active.
///
/// This includes the details of where to insert `llvm.instrprof.increment`
/// intrinsics, and the expression tables to be embedded in the function's
/// coverage metadata.
///
/// FIXME(Zalathar): This query's purpose has drifted a bit and should
/// probably be renamed, but that can wait until after the potential
/// follow-ups to #136053 have settled down.
///
/// Returns `None` for functions that were not instrumented.
query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> Option<&'tcx mir::coverage::CoverageIdsInfo> {
Expand Down
Loading
Loading