Skip to content

Commit f312a5e

Browse files
committed
Auto merge of rust-lang#92844 - matthiaskrgr:rollup-z5wb6yi, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#90001 (Make rlib metadata strip works with MIPSr6 architecture) - rust-lang#91687 (rustdoc: do not emit tuple variant fields if none are documented) - rust-lang#91938 (Add `std::error::Report` type) - rust-lang#92006 (Welcome opaque types into the fold) - rust-lang#92142 ([code coverage] Fix missing dead code in modules that are never called) - rust-lang#92277 (rustc_metadata: Stop passing `CrateMetadataRef` by reference (step 1)) - rust-lang#92334 (rustdoc: Preserve rendering of macro_rules matchers when possible) - rust-lang#92807 (Update cargo) - rust-lang#92832 (Update RELEASES for 1.58.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 22e491a + 1a95aa9 commit f312a5e

File tree

31 files changed

+1514
-356
lines changed

31 files changed

+1514
-356
lines changed

Cargo.lock

+70-12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ dependencies = [
2424
"rustc-std-workspace-core",
2525
]
2626

27+
[[package]]
28+
name = "ahash"
29+
version = "0.7.4"
30+
source = "registry+https://github.com/rust-lang/crates.io-index"
31+
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
32+
dependencies = [
33+
"getrandom 0.2.0",
34+
"once_cell",
35+
"version_check",
36+
]
37+
2738
[[package]]
2839
name = "aho-corasick"
2940
version = "0.7.18"
@@ -324,7 +335,7 @@ dependencies = [
324335
"cargo-test-macro",
325336
"cargo-test-support",
326337
"cargo-util",
327-
"clap",
338+
"clap 3.0.6",
328339
"crates-io",
329340
"crossbeam-utils 0.8.3",
330341
"curl",
@@ -604,13 +615,28 @@ dependencies = [
604615
"ansi_term 0.12.1",
605616
"atty",
606617
"bitflags",
607-
"strsim",
608-
"textwrap",
618+
"strsim 0.8.0",
619+
"textwrap 0.11.0",
609620
"unicode-width",
610621
"vec_map",
611622
"yaml-rust 0.3.5",
612623
]
613624

625+
[[package]]
626+
name = "clap"
627+
version = "3.0.6"
628+
source = "registry+https://github.com/rust-lang/crates.io-index"
629+
checksum = "1957aa4a5fb388f0a0a73ce7556c5b42025b874e5cdc2c670775e346e97adec0"
630+
dependencies = [
631+
"atty",
632+
"bitflags",
633+
"indexmap",
634+
"os_str_bytes",
635+
"strsim 0.10.0",
636+
"termcolor",
637+
"textwrap 0.14.2",
638+
]
639+
614640
[[package]]
615641
name = "clippy"
616642
version = "0.1.59"
@@ -641,7 +667,7 @@ version = "0.0.1"
641667
dependencies = [
642668
"bytecount",
643669
"cargo_metadata 0.14.0",
644-
"clap",
670+
"clap 2.34.0",
645671
"indoc",
646672
"itertools 0.10.1",
647673
"opener",
@@ -1579,6 +1605,7 @@ version = "0.11.0"
15791605
source = "registry+https://github.com/rust-lang/crates.io-index"
15801606
checksum = "362385356d610bd1e5a408ddf8d022041774b683f345a1d2cfcb4f60f8ae2db5"
15811607
dependencies = [
1608+
"ahash",
15821609
"compiler_builtins",
15831610
"rustc-std-workspace-alloc",
15841611
"rustc-std-workspace-core",
@@ -1746,7 +1773,7 @@ name = "installer"
17461773
version = "0.0.0"
17471774
dependencies = [
17481775
"anyhow",
1749-
"clap",
1776+
"clap 2.34.0",
17501777
"flate2",
17511778
"lazy_static",
17521779
"num_cpus",
@@ -2191,7 +2218,7 @@ dependencies = [
21912218
"ammonia",
21922219
"anyhow",
21932220
"chrono",
2194-
"clap",
2221+
"clap 2.34.0",
21952222
"elasticlunr-rs",
21962223
"env_logger 0.7.1",
21972224
"handlebars",
@@ -2396,8 +2423,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
23962423
checksum = "39f37e50073ccad23b6d09bcb5b263f4e76d3bb6038e4a3c08e52162ffa8abc2"
23972424
dependencies = [
23982425
"compiler_builtins",
2399-
"crc32fast",
2400-
"indexmap",
24012426
"memchr",
24022427
"rustc-std-workspace-alloc",
24032428
"rustc-std-workspace-core",
@@ -2415,6 +2440,18 @@ dependencies = [
24152440
"memchr",
24162441
]
24172442

2443+
[[package]]
2444+
name = "object"
2445+
version = "0.28.1"
2446+
source = "registry+https://github.com/rust-lang/crates.io-index"
2447+
checksum = "7ce8b38d41f9f3618fc23f908faae61510f8d8ce2d99cbe910641e8f1971f084"
2448+
dependencies = [
2449+
"crc32fast",
2450+
"hashbrown",
2451+
"indexmap",
2452+
"memchr",
2453+
]
2454+
24182455
[[package]]
24192456
name = "odht"
24202457
version = "0.3.1"
@@ -2512,6 +2549,15 @@ dependencies = [
25122549
"winapi",
25132550
]
25142551

2552+
[[package]]
2553+
name = "os_str_bytes"
2554+
version = "6.0.0"
2555+
source = "registry+https://github.com/rust-lang/crates.io-index"
2556+
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
2557+
dependencies = [
2558+
"memchr",
2559+
]
2560+
25152561
[[package]]
25162562
name = "output_vt100"
25172563
version = "0.1.2"
@@ -2916,7 +2962,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29162962
checksum = "7fec2e85e7a30f8fd31b7cf288ad363b5e51fd2cb6f53b416b0cfaabd84e1ccb"
29172963
dependencies = [
29182964
"bitflags",
2919-
"clap",
2965+
"clap 2.34.0",
29202966
"derive_more",
29212967
"env_logger 0.7.1",
29222968
"humantime 2.0.1",
@@ -3271,7 +3317,7 @@ dependencies = [
32713317
name = "rustbook"
32723318
version = "0.1.0"
32733319
dependencies = [
3274-
"clap",
3320+
"clap 2.34.0",
32753321
"env_logger 0.7.1",
32763322
"mdbook",
32773323
]
@@ -3801,7 +3847,7 @@ dependencies = [
38013847
"itertools 0.9.0",
38023848
"jobserver",
38033849
"libc",
3804-
"object 0.26.2",
3850+
"object 0.28.1",
38053851
"pathdiff",
38063852
"regex",
38073853
"rustc_apfloat",
@@ -5133,13 +5179,19 @@ version = "0.8.0"
51335179
source = "registry+https://github.com/rust-lang/crates.io-index"
51345180
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
51355181

5182+
[[package]]
5183+
name = "strsim"
5184+
version = "0.10.0"
5185+
source = "registry+https://github.com/rust-lang/crates.io-index"
5186+
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
5187+
51365188
[[package]]
51375189
name = "structopt"
51385190
version = "0.3.25"
51395191
source = "registry+https://github.com/rust-lang/crates.io-index"
51405192
checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c"
51415193
dependencies = [
5142-
"clap",
5194+
"clap 2.34.0",
51435195
"lazy_static",
51445196
"structopt-derive",
51455197
]
@@ -5310,6 +5362,12 @@ dependencies = [
53105362
"unicode-width",
53115363
]
53125364

5365+
[[package]]
5366+
name = "textwrap"
5367+
version = "0.14.2"
5368+
source = "registry+https://github.com/rust-lang/crates.io-index"
5369+
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
5370+
53135371
[[package]]
53145372
name = "thiserror"
53155373
version = "1.0.30"

RELEASES.md

-10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ Stabilized APIs
4343
- [`Option::unwrap_unchecked`]
4444
- [`Result::unwrap_unchecked`]
4545
- [`Result::unwrap_err_unchecked`]
46-
- [`NonZero{unsigned}::is_power_of_two`]
4746
- [`File::options`]
4847

4948
These APIs are now usable in const contexts:
@@ -56,10 +55,6 @@ These APIs are now usable in const contexts:
5655
- [`Duration::checked_mul`]
5756
- [`Duration::saturating_mul`]
5857
- [`Duration::checked_div`]
59-
- [`MaybeUninit::as_ptr`]
60-
- [`MaybeUninit::as_mut_ptr`]
61-
- [`MaybeUninit::assume_init`]
62-
- [`MaybeUninit::assume_init_ref`]
6358

6459
Cargo
6560
-----
@@ -141,7 +136,6 @@ and related tools.
141136
[`Option::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.unwrap_unchecked
142137
[`Result::unwrap_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_unchecked
143138
[`Result::unwrap_err_unchecked`]: https://doc.rust-lang.org/stable/std/result/enum.Result.html#method.unwrap_err_unchecked
144-
[`NonZero{unsigned}::is_power_of_two`]: https://doc.rust-lang.org/stable/std/num/struct.NonZeroU8.html#method.is_power_of_two
145139
[`File::options`]: https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.options
146140
[`unix::process::ExitStatusExt::core_dumped`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.core_dumped
147141
[`unix::process::ExitStatusExt::stopped_signal`]: https://doc.rust-lang.org/stable/std/os/unix/process/trait.ExitStatusExt.html#tymethod.stopped_signal
@@ -165,10 +159,6 @@ and related tools.
165159
[`Duration::div_f32`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_f32
166160
[`Duration::div_duration_f64`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f64
167161
[`Duration::div_duration_f32`]: https://doc.rust-lang.org/stable/std/time/struct.Duration.html#method.div_duration_f32
168-
[`MaybeUninit::as_ptr`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_ptr
169-
[`MaybeUninit::as_mut_ptr`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.as_mut_ptr
170-
[`MaybeUninit::assume_init`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init
171-
[`MaybeUninit::assume_init_ref`]: https://doc.rust-lang.org/stable/std/mem/union.MaybeUninit.html#method.assume_init_ref
172162

173163
Version 1.57.0 (2021-12-02)
174164
==========================

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+34-86
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use crate::llvm;
55
use llvm::coverageinfo::CounterMappingRegion;
66
use rustc_codegen_ssa::coverageinfo::map::{Counter, CounterExpression};
77
use rustc_codegen_ssa::traits::{ConstMethods, CoverageInfoMethods};
8-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
9-
use rustc_hir::def_id::{DefId, DefIdSet};
8+
use rustc_data_structures::fx::FxIndexSet;
9+
use rustc_hir::def::DefKind;
10+
use rustc_hir::def_id::DefIdSet;
1011
use rustc_llvm::RustString;
12+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
1113
use rustc_middle::mir::coverage::CodeRegion;
1214
use rustc_middle::ty::TyCtxt;
13-
use rustc_span::Symbol;
1415

1516
use std::ffi::CString;
1617

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

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

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

286284
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
287285

288-
let all_def_ids: DefIdSet = tcx
286+
let eligible_def_ids: DefIdSet = tcx
289287
.mir_keys(())
290288
.iter()
291289
.filter_map(|local_def_id| {
292290
let def_id = local_def_id.to_def_id();
293-
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
291+
let kind = tcx.def_kind(def_id);
292+
// `mir_keys` will give us `DefId`s for all kinds of things, not
293+
// just "functions", like consts, statics, etc. Filter those out.
294+
// If `ignore_unused_generics` was specified, filter out any
295+
// generic functions from consideration as well.
296+
if !matches!(
297+
kind,
298+
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Generator
299+
) {
300+
return None;
301+
} else if ignore_unused_generics
302+
&& tcx.generics_of(def_id).requires_monomorphization(tcx)
303+
{
294304
return None;
295305
}
296306
Some(local_def_id.to_def_id())
@@ -299,79 +309,17 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
299309

300310
let codegenned_def_ids = tcx.codegened_and_inlined_items(());
301311

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

313-
if unused_def_ids_by_file.is_empty() {
314-
// There are no unused functions with file names to add (in any CGU)
315-
return;
316-
}
317-
318-
// Each `CodegenUnit` (CGU) has its own function_coverage_map, and generates a specific binary
319-
// with its own coverage map.
320-
//
321-
// Each covered function `Instance` can be included in only one coverage map, produced from a
322-
// specific function_coverage_map, from a specific CGU.
323-
//
324-
// Since unused functions did not generate code, they are not associated with any CGU yet.
325-
//
326-
// To avoid injecting the unused functions in multiple coverage maps (for multiple CGUs)
327-
// determine which function_coverage_map has the responsibility for publishing unreachable
328-
// coverage, based on file name: For each unused function, find the CGU that generates the
329-
// first function (based on sorted `DefId`) from the same file.
330-
//
331-
// Add a new `FunctionCoverage` to the `function_coverage_map`, with unreachable code regions
332-
// for each region in it's MIR.
333-
334-
// Convert the `HashSet` of `codegenned_def_ids` to a sortable vector, and sort them.
335-
let mut sorted_codegenned_def_ids: Vec<DefId> = codegenned_def_ids.iter().copied().collect();
336-
sorted_codegenned_def_ids.sort_unstable();
337-
338-
let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
339-
for &def_id in sorted_codegenned_def_ids.iter() {
340-
if let Some(covered_file_name) = tcx.covered_file_name(def_id) {
341-
// Only add files known to have unused functions
342-
if unused_def_ids_by_file.contains_key(covered_file_name) {
343-
first_covered_def_id_by_file.entry(*covered_file_name).or_insert(def_id);
344-
}
315+
// If a function is marked `#[no_coverage]`, then skip generating a
316+
// dead code stub for it.
317+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_COVERAGE) {
318+
debug!("skipping unused fn marked #[no_coverage]: {:?}", non_codegenned_def_id);
319+
continue;
345320
}
346-
}
347-
348-
// Get the set of def_ids with coverage regions, known by *this* CoverageContext.
349-
let cgu_covered_def_ids: DefIdSet = match cx.coverage_context() {
350-
Some(ctx) => ctx
351-
.function_coverage_map
352-
.borrow()
353-
.keys()
354-
.map(|&instance| instance.def.def_id())
355-
.collect(),
356-
None => return,
357-
};
358321

359-
let cgu_covered_files: FxHashSet<Symbol> = first_covered_def_id_by_file
360-
.iter()
361-
.filter_map(
362-
|(&file_name, def_id)| {
363-
if cgu_covered_def_ids.contains(def_id) { Some(file_name) } else { None }
364-
},
365-
)
366-
.collect();
367-
368-
// For each file for which this CGU is responsible for adding unused function coverage,
369-
// get the `def_id`s for each unused function (if any), define a synthetic function with a
370-
// single LLVM coverage counter, and add the function's coverage `CodeRegion`s. to the
371-
// function_coverage_map.
372-
for covered_file_name in cgu_covered_files {
373-
for def_id in unused_def_ids_by_file.remove(&covered_file_name).into_iter().flatten() {
374-
cx.define_unused_fn(def_id);
375-
}
322+
debug!("generating unused fn: {:?}", non_codegenned_def_id);
323+
cx.define_unused_fn(non_codegenned_def_id);
376324
}
377325
}

0 commit comments

Comments
 (0)