Skip to content
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

Rollup of 10 pull requests #122511

Merged
merged 33 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3a6af84
change std::process to drop supplementary groups based on CAP_SETGID
Elliot-Roberts Apr 12, 2022
aa692a5
[AIX] Remove AixLinker's debuginfo() implementation
Oct 24, 2023
e74e6e7
Rebased
Mar 5, 2024
b1c3909
Adjust wording
Mar 5, 2024
207fe38
copy byval argument to alloca if alignment is insufficient
erikdesjardins Mar 8, 2024
818f130
update make_indirect_byval comment about missing fix (this PR is the …
erikdesjardins Mar 11, 2024
89fab06
coverage: Add branch coverage tests (with branch coverage disabled)
Zalathar Dec 25, 2023
9751098
Allow `rustc_mir_transform` to register hook providers
Zalathar Feb 8, 2024
73475d0
coverage: Make `is_eligible_for_coverage` a hook method
Zalathar Feb 8, 2024
c921ab1
coverage: Add `CoverageKind::BlockMarker`
Zalathar Feb 8, 2024
12cd322
Make incremental sessions identity no longer depend on the crate name…
Zoxc Feb 28, 2024
f2ec0d3
Implement `Duration::as_millis_{f64,f32}`
GrigorenkoPV Mar 13, 2024
1a81a94
fixes #121331
surechen Mar 11, 2024
f9cdaeb
coverage: Data structures for recording branch info during MIR building
Zalathar Feb 8, 2024
c1bec0c
coverage: Record branch information during MIR building
Zalathar Nov 29, 2023
31d0b50
coverage: Include recorded branch info in coverage instrumentation
Zalathar Nov 16, 2023
5fb1f61
coverage: Enable branch coverage in the branch coverage tests
Zalathar Mar 10, 2024
060c7ce
coverage: `-Zcoverage-options=branch` is no longer a placeholder
Zalathar Mar 13, 2024
ca9f063
Rename `ast::StmtKind::Local` into `ast::StmtKind::Let`
GuillaumeGomez Mar 14, 2024
a4e0e50
Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`
GuillaumeGomez Mar 14, 2024
ac1b857
Update `tests/ui/stats/hir-stats.stderr` output
GuillaumeGomez Mar 14, 2024
2190431
Update version of cc crate
jfgoog Mar 14, 2024
6e4cd8b
Make `SubdiagMessageOp` well-formed
compiler-errors Mar 14, 2024
68ca795
Rollup merge of #117118 - bzEq:aix-linker, r=wesleywiser
matthiaskrgr Mar 14, 2024
eaa8daf
Rollup merge of #121650 - GrigorenkoPV:cap_setgid, r=Amanieu
matthiaskrgr Mar 14, 2024
4dff106
Rollup merge of #121764 - Zoxc:incr-sess-no-source, r=oli-obk
matthiaskrgr Mar 14, 2024
722514f
Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiser
matthiaskrgr Mar 14, 2024
54a5a49
Rollup merge of #122322 - Zalathar:branch, r=oli-obk
matthiaskrgr Mar 14, 2024
b200108
Rollup merge of #122373 - surechen:fix_121331, r=petrochenkov
matthiaskrgr Mar 14, 2024
5d41186
Rollup merge of #122479 - GrigorenkoPV:duration_millis_float, r=scottmcm
matthiaskrgr Mar 14, 2024
1f4aff7
Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli…
matthiaskrgr Mar 14, 2024
6366c64
Rollup merge of #122498 - jfgoog:update-cc-crate-version, r=workingju…
matthiaskrgr Mar 14, 2024
6ce3110
Rollup merge of #122503 - compiler-errors:trait-alias-wf, r=Nilstrieb
matthiaskrgr Mar 14, 2024
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
coverage: Make is_eligible_for_coverage a hook method
This will allow MIR building to check whether a function is eligible for
coverage instrumentation, and avoid collecting branch coverage info if it is
not.
  • Loading branch information
Zalathar committed Mar 13, 2024
commit 73475d0d597dfb42a0d2071b4369f5c3dc7281b1
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::mir;
use crate::query::TyCtxtAt;
use crate::ty::{Ty, TyCtxt};
use rustc_span::def_id::LocalDefId;
use rustc_span::DUMMY_SP;

macro_rules! declare_hooks {
Expand Down Expand Up @@ -70,4 +71,10 @@ declare_hooks! {

/// Getting a &core::panic::Location referring to a span.
hook const_caller_location(file: rustc_span::Symbol, line: u32, col: u32) -> mir::ConstValue<'tcx>;

/// Returns `true` if this def is a function-like thing that is eligible for
/// coverage instrumentation under `-Cinstrument-coverage`.
///
/// (Eligible functions might nevertheless be skipped for other reasons.)
hook is_eligible_for_coverage(key: LocalDefId) -> bool;
}
34 changes: 1 addition & 33 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use self::spans::{BcbMapping, BcbMappingKind, CoverageSpans};
use crate::MirPass;

use rustc_middle::hir;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{
self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator,
Expand Down Expand Up @@ -44,7 +43,7 @@ impl<'tcx> MirPass<'tcx> for InstrumentCoverage {

let def_id = mir_source.def_id().expect_local();

if !is_eligible_for_coverage(tcx, def_id) {
if !tcx.is_eligible_for_coverage(def_id) {
trace!("InstrumentCoverage skipped for {def_id:?} (not eligible)");
return;
}
Expand Down Expand Up @@ -349,37 +348,6 @@ fn check_code_region(code_region: CodeRegion) -> Option<CodeRegion> {
}
}

fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
// Only instrument functions, methods, and closures (not constants since they are evaluated
// at compile time by Miri).
// FIXME(#73156): Handle source code coverage in const eval, but note, if and when const
// expressions get coverage spans, we will probably have to "carve out" space for const
// expressions from coverage spans in enclosing MIR's, like we do for closures. (That might
// be tricky if const expressions have no corresponding statements in the enclosing MIR.
// Closures are carved out by their initial `Assign` statement.)
if !tcx.def_kind(def_id).is_fn_like() {
trace!("InstrumentCoverage skipped for {def_id:?} (not an fn-like)");
return false;
}

// Don't instrument functions with `#[automatically_derived]` on their
// enclosing impl block, on the assumption that most users won't care about
// coverage for derived impls.
if let Some(impl_of) = tcx.impl_of_method(def_id.to_def_id())
&& tcx.is_automatically_derived(impl_of)
{
trace!("InstrumentCoverage skipped for {def_id:?} (automatically derived)");
return false;
}

if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
trace!("InstrumentCoverage skipped for {def_id:?} (`#[coverage(off)]`)");
return false;
}

true
}

/// Function information extracted from HIR by the coverage instrumentor.
#[derive(Debug)]
struct ExtractedHirInfo {
Expand Down
45 changes: 40 additions & 5 deletions compiler/rustc_mir_transform/src/coverage/query.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
use super::*;

use rustc_data_structures::captures::Captures;
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{Body, CoverageIdsInfo};
use rustc_middle::ty::{self};
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::{CounterId, CoverageKind};
use rustc_middle::mir::{Body, Coverage, CoverageIdsInfo, Statement, StatementKind};
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::util::Providers;
use rustc_span::def_id::LocalDefId;

/// Registers query/hook implementations related to coverage.
pub(crate) fn provide(providers: &mut Providers) {
providers.hooks.is_eligible_for_coverage =
|TyCtxtAt { tcx, .. }, def_id| is_eligible_for_coverage(tcx, def_id);
providers.queries.coverage_ids_info = coverage_ids_info;
}

/// Hook implementation for [`TyCtxt::is_eligible_for_coverage`].
fn is_eligible_for_coverage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
// Only instrument functions, methods, and closures (not constants since they are evaluated
// at compile time by Miri).
// FIXME(#73156): Handle source code coverage in const eval, but note, if and when const
// expressions get coverage spans, we will probably have to "carve out" space for const
// expressions from coverage spans in enclosing MIR's, like we do for closures. (That might
// be tricky if const expressions have no corresponding statements in the enclosing MIR.
// Closures are carved out by their initial `Assign` statement.)
if !tcx.def_kind(def_id).is_fn_like() {
trace!("InstrumentCoverage skipped for {def_id:?} (not an fn-like)");
return false;
}

// Don't instrument functions with `#[automatically_derived]` on their
// enclosing impl block, on the assumption that most users won't care about
// coverage for derived impls.
if let Some(impl_of) = tcx.impl_of_method(def_id.to_def_id())
&& tcx.is_automatically_derived(impl_of)
{
trace!("InstrumentCoverage skipped for {def_id:?} (automatically derived)");
return false;
}

if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
trace!("InstrumentCoverage skipped for {def_id:?} (`#[coverage(off)]`)");
return false;
}

true
}

/// Query implementation for `coverage_ids_info`.
fn coverage_ids_info<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down