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 #122423

Merged
merged 27 commits into from Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
832b23f
Tiny missed simplification
Nadrieril Mar 1, 2024
3d3b321
Use an enum instead of manually tracking indices for `target_blocks`
Nadrieril Feb 28, 2024
8c3688c
Allocate candidate vectors as we sort them
Nadrieril Mar 2, 2024
edea739
No need to collect test variants ahead of time
Nadrieril Mar 1, 2024
d46ff64
Fix a subtle regression
Nadrieril Mar 2, 2024
c1e6886
Store pattern arity in `DeconstructedPat`
Nadrieril Feb 29, 2024
6ae9fa3
Store field indices in `DeconstructedPat` to avoid virtual wildcards
Nadrieril Feb 29, 2024
d339bda
`DeconstructedPat.data` is always present now
Nadrieril Feb 6, 2024
9962a01
Use `min_exhaustive_patterns` in core & std
Nadrieril Feb 7, 2024
aa71151
Enable PR tracking review assignment
apiraino Mar 12, 2024
22a5267
std: move `Once` implementations to `sys`
joboet Mar 12, 2024
96b8225
Don't Create `ParamCandidate` When Obligation Contains Errors
veera-sivarajan Mar 12, 2024
eab1f30
Fix ICE in diagnostics for parenthesized type arguments
wutchzone Mar 12, 2024
f3b348b
rustdoc: do not preload fonts when browsing locally
rjeli Mar 12, 2024
68fc922
Add `intrinsic_name` to get plain intrinsic name
adpaco-aws Mar 8, 2024
1f544ce
coverage: Remove all unstable values of `-Cinstrument-coverage`
Zalathar Mar 12, 2024
3407fcc
coverage: Add `-Zcoverage-options` for fine control of coverage
Zalathar Mar 8, 2024
1b198ba
Rollup merge of #121820 - Nadrieril:idxpat2, r=compiler-errors
matthiaskrgr Mar 13, 2024
e6ba504
Rollup merge of #121908 - Nadrieril:dynamic-variant-collection, r=mat…
matthiaskrgr Mar 13, 2024
8d78f8e
Rollup merge of #122203 - adpaco-aws:smir-intrinsic-name, r=celinval
matthiaskrgr Mar 13, 2024
8b9ef3b
Rollup merge of #122226 - Zalathar:zcoverage-options, r=nnethercote
matthiaskrgr Mar 13, 2024
e42a702
Rollup merge of #122255 - Nadrieril:min_exh_pats-libs, r=scottmcm
matthiaskrgr Mar 13, 2024
5d13140
Rollup merge of #122360 - veera-sivarajan:bugfix-121941, r=compiler-e…
matthiaskrgr Mar 13, 2024
a18a608
Rollup merge of #122383 - apiraino:enable-pr-tracking, r=jackh726
matthiaskrgr Mar 13, 2024
dff680d
Rollup merge of #122386 - joboet:move_pal_once, r=jhpratt
matthiaskrgr Mar 13, 2024
1ffa5de
Rollup merge of #122400 - wutchzone:122345, r=fmease
matthiaskrgr Mar 13, 2024
62e9e46
Rollup merge of #122410 - rjeli:rustdoc-no-local-font-preload, r=notr…
matthiaskrgr Mar 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .reuse/dep5
Expand Up @@ -52,7 +52,7 @@ Copyright: 2019 The Crossbeam Project Developers
The Rust Project Developers (see https://thanks.rust-lang.org)
License: MIT OR Apache-2.0

Files: library/std/src/sys/locks/mutex/fuchsia.rs
Files: library/std/src/sys/sync/mutex/fuchsia.rs
Copyright: 2016 The Fuchsia Authors
The Rust Project Developers (see https://thanks.rust-lang.org)
License: BSD-2-Clause AND (MIT OR Apache-2.0)
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Expand Up @@ -355,21 +355,20 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {

let tcx = cx.tcx;

let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();

let eligible_def_ids = tcx.mir_keys(()).iter().filter_map(|local_def_id| {
let def_id = local_def_id.to_def_id();
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) {
return None;
}
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
return None;
}

// FIXME(79651): Consider trying to filter out dummy instantiations of
// unused generic functions from library crates, because they can produce
// "unused instantiation" in coverage reports even when they are actually
// used by some downstream crate in the same binary.

Some(local_def_id.to_def_id())
});

Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_interface/src/tests.rs
Expand Up @@ -4,11 +4,12 @@ use rustc_data_structures::profiling::TimePassesFormat;
use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig};
use rustc_session::config::{
build_configuration, build_session_options, rustc_optgroups, BranchProtection, CFGuard, Cfg,
CollapseMacroDebuginfo, DebugInfo, DumpMonoStatsFormat, ErrorOutputType, ExternEntry,
ExternLocation, Externs, FunctionReturn, InliningThreshold, Input, InstrumentCoverage,
InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli, NextSolverConfig,
OomStrategy, Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet, Passes, Polonius,
ProcMacroExecutionStrategy, Strip, SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
CollapseMacroDebuginfo, CoverageOptions, DebugInfo, DumpMonoStatsFormat, ErrorOutputType,
ExternEntry, ExternLocation, Externs, FunctionReturn, InliningThreshold, Input,
InstrumentCoverage, InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail, LtoCli,
NextSolverConfig, OomStrategy, Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet,
Passes, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath, SymbolManglingVersion,
WasiExecModel,
};
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
Expand Down Expand Up @@ -750,6 +751,7 @@ fn test_unstable_options_tracking_hash() {
);
tracked!(codegen_backend, Some("abc".to_string()));
tracked!(collapse_macro_debuginfo, CollapseMacroDebuginfo::Yes);
tracked!(coverage_options, CoverageOptions { branch: true });
tracked!(crate_attr, vec!["abc".to_string()]);
tracked!(cross_crate_inline_threshold, InliningThreshold::Always);
tracked!(debug_info_for_profiling, true);
Expand Down
119 changes: 59 additions & 60 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Expand Up @@ -14,7 +14,6 @@ use rustc_data_structures::{
fx::{FxHashSet, FxIndexMap, FxIndexSet},
stack::ensure_sufficient_stack,
};
use rustc_index::bit_set::BitSet;
use rustc_middle::middle::region;
use rustc_middle::mir::{self, *};
use rustc_middle::thir::{self, *};
Expand Down Expand Up @@ -1084,6 +1083,12 @@ enum TestCase<'pat, 'tcx> {
Or { pats: Box<[FlatPat<'pat, 'tcx>]> },
}

impl<'pat, 'tcx> TestCase<'pat, 'tcx> {
fn as_range(&self) -> Option<&'pat PatRange<'tcx>> {
if let Self::Range(v) = self { Some(*v) } else { None }
}
}

#[derive(Debug, Clone)]
pub(crate) struct MatchPair<'pat, 'tcx> {
/// This place...
Expand All @@ -1108,19 +1113,10 @@ enum TestKind<'tcx> {
Switch {
/// The enum type being tested.
adt_def: ty::AdtDef<'tcx>,
/// The set of variants that we should create a branch for. We also
/// create an additional "otherwise" case.
variants: BitSet<VariantIdx>,
},

/// Test what value an integer or `char` has.
SwitchInt {
/// The (ordered) set of values that we test for.
///
/// We create a branch to each of the values in `options`, as well as an "otherwise" branch
/// for all other values, even in the (rare) case that `options` is exhaustive.
options: FxIndexMap<Const<'tcx>, u128>,
},
SwitchInt,

/// Test what value a `bool` has.
If,
Expand Down Expand Up @@ -1152,6 +1148,25 @@ pub(crate) struct Test<'tcx> {
kind: TestKind<'tcx>,
}

/// The branch to be taken after a test.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
enum TestBranch<'tcx> {
/// Success branch, used for tests with two possible outcomes.
Success,
/// Branch corresponding to this constant.
Constant(Const<'tcx>, u128),
/// Branch corresponding to this variant.
Variant(VariantIdx),
/// Failure branch for tests with two possible outcomes, and "otherwise" branch for other tests.
Failure,
}

impl<'tcx> TestBranch<'tcx> {
fn as_constant(&self) -> Option<&Const<'tcx>> {
if let Self::Constant(v, _) = self { Some(v) } else { None }
}
}

/// `ArmHasGuard` is a wrapper around a boolean flag. It indicates whether
/// a match arm has a guard expression attached to it.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -1561,30 +1576,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
) -> (PlaceBuilder<'tcx>, Test<'tcx>) {
// Extract the match-pair from the highest priority candidate
let match_pair = &candidates.first().unwrap().match_pairs[0];
let mut test = self.test(match_pair);
let test = self.test(match_pair);
let match_place = match_pair.place.clone();

debug!(?test, ?match_pair);
// Most of the time, the test to perform is simply a function of the main candidate; but for
// a test like SwitchInt, we may want to add cases based on the candidates that are
// available
match test.kind {
TestKind::SwitchInt { ref mut options } => {
for candidate in candidates.iter() {
if !self.add_cases_to_switch(&match_place, candidate, options) {
break;
}
}
}
TestKind::Switch { adt_def: _, ref mut variants } => {
for candidate in candidates.iter() {
if !self.add_variants_to_switch(&match_place, candidate, variants) {
break;
}
}
}
_ => {}
}

(match_place, test)
}
Expand Down Expand Up @@ -1627,23 +1621,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
match_place: &PlaceBuilder<'tcx>,
test: &Test<'tcx>,
mut candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>],
) -> (&'b mut [&'c mut Candidate<'pat, 'tcx>], Vec<Vec<&'b mut Candidate<'pat, 'tcx>>>) {
// For each of the N possible outcomes, create a (initially empty) vector of candidates.
// Those are the candidates that apply if the test has that particular outcome.
let mut target_candidates: Vec<Vec<&mut Candidate<'pat, 'tcx>>> = vec![];
target_candidates.resize_with(test.targets(), Default::default);
) -> (
&'b mut [&'c mut Candidate<'pat, 'tcx>],
FxIndexMap<TestBranch<'tcx>, Vec<&'b mut Candidate<'pat, 'tcx>>>,
) {
// For each of the possible outcomes, collect vector of candidates that apply if the test
// has that particular outcome.
let mut target_candidates: FxIndexMap<_, Vec<&mut Candidate<'_, '_>>> = Default::default();

let total_candidate_count = candidates.len();

// Sort the candidates into the appropriate vector in `target_candidates`. Note that at some
// point we may encounter a candidate where the test is not relevant; at that point, we stop
// sorting.
while let Some(candidate) = candidates.first_mut() {
let Some(idx) = self.sort_candidate(&match_place, &test, candidate) else {
let Some(branch) =
self.sort_candidate(&match_place, test, candidate, &target_candidates)
else {
break;
};
let (candidate, rest) = candidates.split_first_mut().unwrap();
target_candidates[idx].push(candidate);
target_candidates.entry(branch).or_insert_with(Vec::new).push(candidate);
candidates = rest;
}

Expand Down Expand Up @@ -1784,31 +1782,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
otherwise_block
};

// For each outcome of test, process the candidates that still
// apply. Collect a list of blocks where control flow will
// branch if one of the `target_candidate` sets is not
// exhaustive.
let target_blocks: Vec<_> = target_candidates
// For each outcome of test, process the candidates that still apply.
let target_blocks: FxIndexMap<_, _> = target_candidates
.into_iter()
.map(|mut candidates| {
if !candidates.is_empty() {
let candidate_start = self.cfg.start_new_block();
self.match_candidates(
span,
scrutinee_span,
candidate_start,
remainder_start,
&mut *candidates,
);
candidate_start
} else {
remainder_start
}
.map(|(branch, mut candidates)| {
let candidate_start = self.cfg.start_new_block();
self.match_candidates(
span,
scrutinee_span,
candidate_start,
remainder_start,
&mut *candidates,
);
(branch, candidate_start)
})
.collect();

// Perform the test, branching to one of N blocks.
self.perform_test(span, scrutinee_span, start_block, &match_place, &test, target_blocks);
self.perform_test(
span,
scrutinee_span,
start_block,
remainder_start,
&match_place,
&test,
target_blocks,
);
}

/// Determine the fake borrows that are needed from a set of places that
Expand Down