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 9 pull requests #92844

Merged
merged 40 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
59df6c8
Try commiting again
seanchen1991 Oct 22, 2021
6a59d0e
Have `pretty` and `show_backtrace` accept booleans
seanchen1991 Oct 22, 2021
c6de413
Change `source` field to `error`
seanchen1991 Oct 22, 2021
c0f14cb
Attempt to fix tidy errors
seanchen1991 Oct 27, 2021
aa853bd
Add `rust` annotation to doctest
seanchen1991 Oct 27, 2021
d2f49ee
Format doctest
seanchen1991 Oct 27, 2021
32bcb81
Fix broken doctest
seanchen1991 Oct 27, 2021
1386a15
Update std::error::Report based on feedback
yaahc Dec 14, 2021
689a868
Remove some noise from opaque type errors around associated types
oli-obk Dec 16, 2021
5c46002
Eagerly instantiate opaque types
oli-obk Dec 16, 2021
bdeeb07
Prove obligations to termination instead of ignoring ambiguities.
oli-obk Dec 16, 2021
4420cc3
Update report output and fix examples
yaahc Dec 16, 2021
078b112
add a panicking example
yaahc Dec 16, 2021
9be1cc9
more docs improvements
yaahc Dec 16, 2021
5b3902f
attempt to make Report usable with Box dyn Error and fn main
yaahc Dec 17, 2021
341d65d
Add test case for #86177 and #85718
wesleywiser Dec 20, 2021
ef57f24
[code coverage] Fix missing dead code in modules that are never called
wesleywiser Dec 20, 2021
ebc0d0d
Address review comments
wesleywiser Dec 21, 2021
336c85a
rustdoc: Preserve rendering of macro_rules matchers when possible
dtolnay Dec 27, 2021
544a6bb
Replace &DocCtxt -> TyCtxt in macro matcher rendering
dtolnay Dec 28, 2021
0f8415b
Add a test of rustdoc on macro-generated macro
dtolnay Dec 28, 2021
579e8bc
Make rlib metadata strip works with MIPSr6 architecture
Fearyncess Jan 7, 2022
11f180f
rustc_codegen_ssa: set static lifetime for object::write::Object
Fearyncess Jan 7, 2022
9a337b6
update Cargo.lock and gimli-rs/object for rustc_codegen_ssa
Fearyncess Jan 7, 2022
72cb1bd
silence tidy errors
yaahc Jan 7, 2022
cf36c21
tidy: add `ahash` to permitted dep list
Fearyncess Jan 8, 2022
c4471b0
rustc_metadata: Stop passing `CrateMetadataRef` by reference
petrochenkov Dec 24, 2021
e9cac4c
Ignore `unused_mod.rs` file in code coverage results
wesleywiser Jan 10, 2022
4193f2d
rustdoc: do not emit tuple variant fields if none are documented
euclio Dec 9, 2021
66f1e32
Update cargo
ehuss Jan 12, 2022
5b2d5da
Update RELEASES for 1.58.
ehuss Jan 13, 2022
c7ada00
Rollup merge of #90001 - Fearyncess:master, r=alexcrichton
matthiaskrgr Jan 13, 2022
3e7bc08
Rollup merge of #91687 - euclio:tuple-variant-field-section, r=Guilla…
matthiaskrgr Jan 13, 2022
e045c79
Rollup merge of #91938 - yaahc:error-reporter, r=m-ou-se
matthiaskrgr Jan 13, 2022
b45a819
Rollup merge of #92006 - oli-obk:welcome_opaque_types_into_the_fold, …
matthiaskrgr Jan 13, 2022
5e04f51
Rollup merge of #92142 - wesleywiser:fix_codecoverage_partitioning, r…
matthiaskrgr Jan 13, 2022
f84d35f
Rollup merge of #92277 - petrochenkov:cmrval2, r=jackh726
matthiaskrgr Jan 13, 2022
ac81a13
Rollup merge of #92334 - dtolnay:rustdocmatcher, r=camelid,GuillaumeG…
matthiaskrgr Jan 13, 2022
a9fe2b9
Rollup merge of #92807 - ehuss:update-cargo, r=ehuss
matthiaskrgr Jan 13, 2022
1a95aa9
Rollup merge of #92832 - ehuss:1.58-releases, r=Mark-Simulacrum
matthiaskrgr Jan 13, 2022
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
82 changes: 70 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "ahash"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
dependencies = [
"getrandom 0.2.0",
"once_cell",
"version_check",
]

[[package]]
name = "aho-corasick"
version = "0.7.18"
Expand Down Expand Up @@ -324,7 +335,7 @@ dependencies = [
"cargo-test-macro",
"cargo-test-support",
"cargo-util",
"clap",
"clap 3.0.6",
"crates-io",
"crossbeam-utils 0.8.3",
"curl",
Expand Down Expand Up @@ -604,13 +615,28 @@ dependencies = [
"ansi_term 0.12.1",
"atty",
"bitflags",
"strsim",
"textwrap",
"strsim 0.8.0",
"textwrap 0.11.0",
"unicode-width",
"vec_map",
"yaml-rust 0.3.5",
]

[[package]]
name = "clap"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1957aa4a5fb388f0a0a73ce7556c5b42025b874e5cdc2c670775e346e97adec0"
dependencies = [
"atty",
"bitflags",
"indexmap",
"os_str_bytes",
"strsim 0.10.0",
"termcolor",
"textwrap 0.14.2",
]

[[package]]
name = "clippy"
version = "0.1.59"
Expand Down Expand Up @@ -641,7 +667,7 @@ version = "0.0.1"
dependencies = [
"bytecount",
"cargo_metadata 0.14.0",
"clap",
"clap 2.34.0",
"indoc",
"itertools 0.10.1",
"opener",
Expand Down Expand Up @@ -1579,6 +1605,7 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "362385356d610bd1e5a408ddf8d022041774b683f345a1d2cfcb4f60f8ae2db5"
dependencies = [
"ahash",
"compiler_builtins",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand Down Expand Up @@ -1746,7 +1773,7 @@ name = "installer"
version = "0.0.0"
dependencies = [
"anyhow",
"clap",
"clap 2.34.0",
"flate2",
"lazy_static",
"num_cpus",
Expand Down Expand Up @@ -2191,7 +2218,7 @@ dependencies = [
"ammonia",
"anyhow",
"chrono",
"clap",
"clap 2.34.0",
"elasticlunr-rs",
"env_logger 0.7.1",
"handlebars",
Expand Down Expand Up @@ -2396,8 +2423,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
dependencies = [
"compiler_builtins",
"crc32fast",
"indexmap",
"memchr",
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
Expand All @@ -2415,6 +2440,18 @@ dependencies = [
"memchr",
]

[[package]]
name = "object"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ce8b38d41f9f3618fc23f908faae61510f8d8ce2d99cbe910641e8f1971f084"
dependencies = [
"crc32fast",
"hashbrown",
"indexmap",
"memchr",
]

[[package]]
name = "odht"
version = "0.3.1"
Expand Down Expand Up @@ -2512,6 +2549,15 @@ dependencies = [
"winapi",
]

[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]

[[package]]
name = "output_vt100"
version = "0.1.2"
Expand Down Expand Up @@ -2916,7 +2962,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fec2e85e7a30f8fd31b7cf288ad363b5e51fd2cb6f53b416b0cfaabd84e1ccb"
dependencies = [
"bitflags",
"clap",
"clap 2.34.0",
"derive_more",
"env_logger 0.7.1",
"humantime 2.0.1",
Expand Down Expand Up @@ -3271,7 +3317,7 @@ dependencies = [
name = "rustbook"
version = "0.1.0"
dependencies = [
"clap",
"clap 2.34.0",
"env_logger 0.7.1",
"mdbook",
]
Expand Down Expand Up @@ -3801,7 +3847,7 @@ dependencies = [
"itertools 0.9.0",
"jobserver",
"libc",
"object 0.26.2",
"object 0.28.1",
"pathdiff",
"regex",
"rustc_apfloat",
Expand Down Expand Up @@ -5133,13 +5179,19 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"

[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"

[[package]]
name = "structopt"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
dependencies = [
"clap",
"clap 2.34.0",
"lazy_static",
"structopt-derive",
]
Expand Down Expand Up @@ -5310,6 +5362,12 @@ dependencies = [
"unicode-width",
]

[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"

[[package]]
name = "thiserror"
version = "1.0.30"
Expand Down
10 changes: 0 additions & 10 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Stabilized APIs
- [`Option::unwrap_unchecked`]
- [`Result::unwrap_unchecked`]
- [`Result::unwrap_err_unchecked`]
- [`NonZero{unsigned}::is_power_of_two`]
- [`File::options`]

These APIs are now usable in const contexts:
Expand All @@ -56,10 +55,6 @@ These APIs are now usable in const contexts:
- [`Duration::checked_mul`]
- [`Duration::saturating_mul`]
- [`Duration::checked_div`]
- [`MaybeUninit::as_ptr`]
- [`MaybeUninit::as_mut_ptr`]
- [`MaybeUninit::assume_init`]
- [`MaybeUninit::assume_init_ref`]

Cargo
-----
Expand Down Expand Up @@ -141,7 +136,6 @@ and related tools.
[`Option::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.unwrap_unchecked
[`Result::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_unchecked
[`Result::unwrap_err_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_err_unchecked
[`NonZero{unsigned}::is_power_of_two`]: https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html#method.is_power_of_two
[`File::options`]: https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.options
[`unix::process::ExitStatusExt::core_dumped`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.core_dumped
[`unix::process::ExitStatusExt::stopped_signal`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal
Expand All @@ -165,10 +159,6 @@ and related tools.
[`Duration::div_f32`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_f32
[`Duration::div_duration_f64`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f64
[`Duration::div_duration_f32`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f32
[`MaybeUninit::as_ptr`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_ptr
[`MaybeUninit::as_mut_ptr`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_mut_ptr
[`MaybeUninit::assume_init`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init
[`MaybeUninit::assume_init_ref`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref

Version 1.57.0 (2021-12-02)
==========================
Expand Down
120 changes: 34 additions & 86 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ use crate::llvm;
use llvm::coverageinfo::CounterMappingRegion;
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_hir::def_id::{DefId, DefIdSet};
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefIdSet;
use rustc_llvm::RustString;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::CodeRegion;
use rustc_middle::ty::TyCtxt;
use rustc_span::Symbol;

use std::ffi::CString;

Expand Down Expand Up @@ -46,7 +47,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
// functions exist. Generate synthetic functions with a (required) single counter, and add the
// MIR `Coverage` code regions to the `function_coverage_map`, before calling
// `ctx.take_function_coverage_map()`.
if !tcx.sess.instrument_coverage_except_unused_functions() {
if cx.codegen_unit.is_code_coverage_dead_code_cgu() {
add_unused_functions(cx);
}

Expand Down Expand Up @@ -271,26 +272,35 @@ fn save_function_record(
/// `DefId`s (`tcx` query `mir_keys`) minus the codegenned `DefId`s (`tcx` query
/// `codegened_and_inlined_items`).
///
/// *HOWEVER* the codegenned `DefId`s are partitioned across multiple `CodegenUnit`s (CGUs), and
/// this function is processing a `function_coverage_map` for the functions (`Instance`/`DefId`)
/// allocated to only one of those CGUs. We must NOT inject any unused functions's `CodeRegion`s
/// more than once, so we have to pick a CGUs `function_coverage_map` into which the unused
/// function will be inserted.
/// These unused functions are then codegen'd in one of the CGUs which is marked as the
/// "code coverage dead code cgu" during the partitioning process. This prevents us from generating
/// code regions for the same function more than once which can lead to linker errors regarding
/// duplicate symbols.
fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
let tcx = cx.tcx;
assert!(cx.codegen_unit.is_code_coverage_dead_code_cgu());

// FIXME(#79622): Can this solution be simplified and/or improved? Are there other sources
// of compiler state data that might help (or better sources that could be exposed, but
// aren't yet)?
let tcx = cx.tcx;

let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();

let all_def_ids: DefIdSet = tcx
let eligible_def_ids: DefIdSet = tcx
.mir_keys(())
.iter()
.filter_map(|local_def_id| {
let def_id = local_def_id.to_def_id();
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
let kind = tcx.def_kind(def_id);
// `mir_keys` will give us `DefId`s for all kinds of things, not
// just "functions", like consts, statics, etc. Filter those out.
// If `ignore_unused_generics` was specified, filter out any
// generic functions from consideration as well.
if !matches!(
kind,
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator
) {
return None;
} else if ignore_unused_generics
&& tcx.generics_of(def_id).requires_monomorphization(tcx)
{
return None;
}
Some(local_def_id.to_def_id())
Expand All @@ -299,79 +309,17 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {

let codegenned_def_ids = tcx.codegened_and_inlined_items(());

let mut unused_def_ids_by_file: FxHashMap<Symbol, Vec<DefId>> = FxHashMap::default();
for &non_codegenned_def_id in all_def_ids.difference(codegenned_def_ids) {
// Make sure the non-codegenned (unused) function has at least one MIR
// `Coverage` statement with a code region, and return its file name.
if let Some(non_codegenned_file_name) = tcx.covered_file_name(non_codegenned_def_id) {
let def_ids =
unused_def_ids_by_file.entry(*non_codegenned_file_name).or_insert_with(Vec::new);
def_ids.push(non_codegenned_def_id);
}
}
for &non_codegenned_def_id in eligible_def_ids.difference(codegenned_def_ids) {
let codegen_fn_attrs = tcx.codegen_fn_attrs(non_codegenned_def_id);

if unused_def_ids_by_file.is_empty() {
// There are no unused functions with file names to add (in any CGU)
return;
}

// Each `CodegenUnit` (CGU) has its own function_coverage_map, and generates a specific binary
// with its own coverage map.
//
// Each covered function `Instance` can be included in only one coverage map, produced from a
// specific function_coverage_map, from a specific CGU.
//
// Since unused functions did not generate code, they are not associated with any CGU yet.
//
// To avoid injecting the unused functions in multiple coverage maps (for multiple CGUs)
// determine which function_coverage_map has the responsibility for publishing unreachable
// coverage, based on file name: For each unused function, find the CGU that generates the
// first function (based on sorted `DefId`) from the same file.
//
// Add a new `FunctionCoverage` to the `function_coverage_map`, with unreachable code regions
// for each region in it's MIR.

// Convert the `HashSet` of `codegenned_def_ids` to a sortable vector, and sort them.
let mut sorted_codegenned_def_ids: Vec<DefId> = codegenned_def_ids.iter().copied().collect();
sorted_codegenned_def_ids.sort_unstable();

let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
for &def_id in sorted_codegenned_def_ids.iter() {
if let Some(covered_file_name) = tcx.covered_file_name(def_id) {
// Only add files known to have unused functions
if unused_def_ids_by_file.contains_key(covered_file_name) {
first_covered_def_id_by_file.entry(*covered_file_name).or_insert(def_id);
}
// If a function is marked `#[no_coverage]`, then skip generating a
// dead code stub for it.
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
debug!("skipping unused fn marked #[no_coverage]: {:?}", non_codegenned_def_id);
continue;
}
}

// Get the set of def_ids with coverage regions, known by *this* CoverageContext.
let cgu_covered_def_ids: DefIdSet = match cx.coverage_context() {
Some(ctx) => ctx
.function_coverage_map
.borrow()
.keys()
.map(|&instance| instance.def.def_id())
.collect(),
None => return,
};

let cgu_covered_files: FxHashSet<Symbol> = first_covered_def_id_by_file
.iter()
.filter_map(
|(&file_name, def_id)| {
if cgu_covered_def_ids.contains(def_id) { Some(file_name) } else { None }
},
)
.collect();

// For each file for which this CGU is responsible for adding unused function coverage,
// get the `def_id`s for each unused function (if any), define a synthetic function with a
// single LLVM coverage counter, and add the function's coverage `CodeRegion`s. to the
// function_coverage_map.
for covered_file_name in cgu_covered_files {
for def_id in unused_def_ids_by_file.remove(&covered_file_name).into_iter().flatten() {
cx.define_unused_fn(def_id);
}
debug!("generating unused fn: {:?}", non_codegenned_def_id);
cx.define_unused_fn(non_codegenned_def_id);
}
}
Loading