Skip to content

Commit 5b88d65

Browse files
committed
Auto merge of #116598 - matthiaskrgr:rollup-6xra4jx, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #116586 (use env variable to control thread ids in rustc_log) - #116589 (coverage: Unbox and simplify `bcb_filtered_successors`) - #116595 (-Zmir-enable-passes: document that this may enable unsound passes) - #116596 (reorder files in solve) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 061c330 + da42858 commit 5b88d65

File tree

14 files changed

+60
-91
lines changed

14 files changed

+60
-91
lines changed

compiler/rustc_log/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,21 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
7474
Some(v) => &v != "0",
7575
};
7676

77+
let verbose_thread_ids = match env::var_os(String::from(env) + "_THREAD_IDS") {
78+
None => false,
79+
Some(v) => &v == "1",
80+
};
81+
7782
let layer = tracing_tree::HierarchicalLayer::default()
7883
.with_writer(io::stderr)
7984
.with_indent_lines(true)
8085
.with_ansi(color_logs)
8186
.with_targets(true)
8287
.with_verbose_exit(verbose_entry_exit)
8388
.with_verbose_entry(verbose_entry_exit)
84-
.with_indent_amount(2);
85-
#[cfg(all(parallel_compiler, debug_assertions))]
86-
let layer = layer.with_thread_ids(true).with_thread_names(true);
89+
.with_indent_amount(2)
90+
.with_thread_ids(verbose_thread_ids)
91+
.with_thread_names(verbose_thread_ids);
8792

8893
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
8994
match env::var(format!("{env}_BACKTRACE")) {

compiler/rustc_mir_transform/src/coverage/graph.rs

+37-79
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use rustc_data_structures::captures::Captures;
12
use rustc_data_structures::graph::dominators::{self, Dominators};
23
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
34
use rustc_index::bit_set::BitSet;
45
use rustc_index::{IndexSlice, IndexVec};
5-
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
6+
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
67

78
use std::cmp::Ordering;
89
use std::ops::{Index, IndexMut};
@@ -36,9 +37,8 @@ impl CoverageGraph {
3637
}
3738
let bcb_data = &bcbs[bcb];
3839
let mut bcb_successors = Vec::new();
39-
for successor in
40-
bcb_filtered_successors(&mir_body, &bcb_data.terminator(mir_body).kind)
41-
.filter_map(|successor_bb| bb_to_bcb[successor_bb])
40+
for successor in bcb_filtered_successors(&mir_body, bcb_data.last_bb())
41+
.filter_map(|successor_bb| bb_to_bcb[successor_bb])
4242
{
4343
if !seen[successor] {
4444
seen[successor] = true;
@@ -80,10 +80,9 @@ impl CoverageGraph {
8080
// intentionally omits unwind paths.
8181
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
8282
// `catch_unwind()` handlers.
83-
let mir_cfg_without_unwind = ShortCircuitPreorder::new(&mir_body, bcb_filtered_successors);
8483

8584
let mut basic_blocks = Vec::new();
86-
for (bb, data) in mir_cfg_without_unwind {
85+
for bb in short_circuit_preorder(mir_body, bcb_filtered_successors) {
8786
if let Some(last) = basic_blocks.last() {
8887
let predecessors = &mir_body.basic_blocks.predecessors()[bb];
8988
if predecessors.len() > 1 || !predecessors.contains(last) {
@@ -109,7 +108,7 @@ impl CoverageGraph {
109108
}
110109
basic_blocks.push(bb);
111110

112-
let term = data.terminator();
111+
let term = mir_body[bb].terminator();
113112

114113
match term.kind {
115114
TerminatorKind::Return { .. }
@@ -316,11 +315,6 @@ impl BasicCoverageBlockData {
316315
pub fn last_bb(&self) -> BasicBlock {
317316
*self.basic_blocks.last().unwrap()
318317
}
319-
320-
#[inline(always)]
321-
pub fn terminator<'a, 'tcx>(&self, mir_body: &'a mir::Body<'tcx>) -> &'a Terminator<'tcx> {
322-
&mir_body[self.last_bb()].terminator()
323-
}
324318
}
325319

326320
/// Represents a successor from a branching BasicCoverageBlock (such as the arms of a `SwitchInt`)
@@ -362,26 +356,28 @@ impl std::fmt::Debug for BcbBranch {
362356
}
363357
}
364358

365-
// Returns the `Terminator`s non-unwind successors.
359+
// Returns the subset of a block's successors that are relevant to the coverage
360+
// graph, i.e. those that do not represent unwinds or unreachable branches.
366361
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
367362
// `catch_unwind()` handlers.
368363
fn bcb_filtered_successors<'a, 'tcx>(
369364
body: &'a mir::Body<'tcx>,
370-
term_kind: &'a TerminatorKind<'tcx>,
371-
) -> Box<dyn Iterator<Item = BasicBlock> + 'a> {
372-
Box::new(
373-
match &term_kind {
374-
// SwitchInt successors are never unwind, and all of them should be traversed.
375-
TerminatorKind::SwitchInt { ref targets, .. } => {
376-
None.into_iter().chain(targets.all_targets().into_iter().copied())
377-
}
378-
// For all other kinds, return only the first successor, if any, and ignore unwinds.
379-
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
380-
// `next().into_iter()`) into the `mir::Successors` aliased type.
381-
_ => term_kind.successors().next().into_iter().chain((&[]).into_iter().copied()),
382-
}
383-
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable),
384-
)
365+
bb: BasicBlock,
366+
) -> impl Iterator<Item = BasicBlock> + Captures<'a> + Captures<'tcx> {
367+
let terminator = body[bb].terminator();
368+
369+
let take_n_successors = match terminator.kind {
370+
// SwitchInt successors are never unwinds, so all of them should be traversed.
371+
TerminatorKind::SwitchInt { .. } => usize::MAX,
372+
// For all other kinds, return only the first successor (if any), ignoring any
373+
// unwind successors.
374+
_ => 1,
375+
};
376+
377+
terminator
378+
.successors()
379+
.take(take_n_successors)
380+
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable)
385381
}
386382

387383
/// Maintains separate worklists for each loop in the BasicCoverageBlock CFG, plus one for the
@@ -553,66 +549,28 @@ pub(super) fn find_loop_backedges(
553549
backedges
554550
}
555551

556-
pub struct ShortCircuitPreorder<
557-
'a,
558-
'tcx,
559-
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
560-
> {
552+
fn short_circuit_preorder<'a, 'tcx, F, Iter>(
561553
body: &'a mir::Body<'tcx>,
562-
visited: BitSet<BasicBlock>,
563-
worklist: Vec<BasicBlock>,
564554
filtered_successors: F,
565-
}
566-
567-
impl<
568-
'a,
569-
'tcx,
570-
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
571-
> ShortCircuitPreorder<'a, 'tcx, F>
555+
) -> impl Iterator<Item = BasicBlock> + Captures<'a> + Captures<'tcx>
556+
where
557+
F: Fn(&'a mir::Body<'tcx>, BasicBlock) -> Iter,
558+
Iter: Iterator<Item = BasicBlock>,
572559
{
573-
pub fn new(
574-
body: &'a mir::Body<'tcx>,
575-
filtered_successors: F,
576-
) -> ShortCircuitPreorder<'a, 'tcx, F> {
577-
let worklist = vec![mir::START_BLOCK];
578-
579-
ShortCircuitPreorder {
580-
body,
581-
visited: BitSet::new_empty(body.basic_blocks.len()),
582-
worklist,
583-
filtered_successors,
584-
}
585-
}
586-
}
587-
588-
impl<
589-
'a,
590-
'tcx,
591-
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
592-
> Iterator for ShortCircuitPreorder<'a, 'tcx, F>
593-
{
594-
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
560+
let mut visited = BitSet::new_empty(body.basic_blocks.len());
561+
let mut worklist = vec![mir::START_BLOCK];
595562

596-
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
597-
while let Some(idx) = self.worklist.pop() {
598-
if !self.visited.insert(idx) {
563+
std::iter::from_fn(move || {
564+
while let Some(bb) = worklist.pop() {
565+
if !visited.insert(bb) {
599566
continue;
600567
}
601568

602-
let data = &self.body[idx];
603-
604-
if let Some(ref term) = data.terminator {
605-
self.worklist.extend((self.filtered_successors)(&self.body, &term.kind));
606-
}
569+
worklist.extend(filtered_successors(body, bb));
607570

608-
return Some((idx, data));
571+
return Some(bb);
609572
}
610573

611574
None
612-
}
613-
614-
fn size_hint(&self) -> (usize, Option<usize>) {
615-
let size = self.body.basic_blocks.len() - self.visited.count();
616-
(size, Some(size))
617-
}
575+
})
618576
}

compiler/rustc_mir_transform/src/coverage/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ fn print_coverage_graphviz(
241241
" {:?} [label=\"{:?}: {}\"];\n{}",
242242
bcb,
243243
bcb,
244-
bcb_data.terminator(mir_body).kind.name(),
244+
mir_body[bcb_data.last_bb()].terminator().kind.name(),
245245
basic_coverage_blocks
246246
.successors(bcb)
247247
.map(|successor| { format!(" {:?} -> {:?};", bcb, successor) })

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub struct EarlyOtherwiseBranch;
9595

9696
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
9797
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
98+
// unsound: https://github.com/rust-lang/rust/issues/95162
9899
sess.mir_opt_level() >= 3 && sess.opts.unstable_opts.unsound_mir_opts
99100
}
100101

compiler/rustc_mir_transform/src/large_enums.rs

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pub struct EnumSizeOpt {
3030

3131
impl<'tcx> MirPass<'tcx> for EnumSizeOpt {
3232
fn is_enabled(&self, sess: &Session) -> bool {
33+
// There are some differences in behavior on wasm and ARM that are not properly
34+
// understood, so we conservatively treat this optimization as unsound:
35+
// https://github.com/rust-lang/rust/pull/85158#issuecomment-1101836457
3336
sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3
3437
}
3538
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/nrvo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct RenameReturnPlace;
3434

3535
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
3636
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
37-
// #111005
37+
// unsound: #111005
3838
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
3939
}
4040

compiler/rustc_session/src/options.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1599,9 +1599,10 @@ options! {
15991599
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
16001600
(default: no)"),
16011601
mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
1602-
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the specified passes to be \
1603-
enabled, overriding all other checks. Passes that are not specified are enabled or \
1604-
disabled by other flags as usual."),
1602+
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the \
1603+
specified passes to be enabled, overriding all other checks. In particular, this will \
1604+
enable unsound (known-buggy and hence usually disabled) passes without further warning! \
1605+
Passes that are not specified are enabled or disabled by other flags as usual."),
16051606
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
16061607
"use line numbers relative to the function in mir pretty printing"),
16071608
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],

compiler/rustc_trait_selection/src/solve/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,11 @@ mod assembly;
3232
mod canonicalize;
3333
mod eval_ctxt;
3434
mod fulfill;
35-
mod inherent_projection;
3635
pub mod inspect;
3736
mod normalize;
38-
mod opaques;
3937
mod project_goals;
4038
mod search_graph;
4139
mod trait_goals;
42-
mod weak_types;
4340

4441
pub use eval_ctxt::{
4542
EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt, UseGlobalCache,

compiler/rustc_trait_selection/src/solve/project_goals.rs renamed to compiler/rustc_trait_selection/src/solve/project_goals/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
1818
use rustc_middle::ty::{ToPredicate, TypeVisitableExt};
1919
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
2020

21+
mod inherent_projection;
22+
mod opaques;
23+
mod weak_types;
24+
2125
impl<'tcx> EvalCtxt<'_, 'tcx> {
2226
#[instrument(level = "debug", skip(self), ret)]
2327
pub(super) fn compute_projection_goal(

compiler/rustc_trait_selection/src/solve/opaques.rs renamed to compiler/rustc_trait_selection/src/solve/project_goals/opaques.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::traits::Reveal;
77
use rustc_middle::ty;
88
use rustc_middle::ty::util::NotUniqueParam;
99

10-
use super::{EvalCtxt, SolverMode};
10+
use crate::solve::{EvalCtxt, SolverMode};
1111

1212
impl<'tcx> EvalCtxt<'_, 'tcx> {
1313
pub(super) fn normalize_opaque_type(

0 commit comments

Comments
 (0)