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
This commit is contained in:
commit
5b88d659f8
@ -74,6 +74,11 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
|
|||||||
Some(v) => &v != "0",
|
Some(v) => &v != "0",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let verbose_thread_ids = match env::var_os(String::from(env) + "_THREAD_IDS") {
|
||||||
|
None => false,
|
||||||
|
Some(v) => &v == "1",
|
||||||
|
};
|
||||||
|
|
||||||
let layer = tracing_tree::HierarchicalLayer::default()
|
let layer = tracing_tree::HierarchicalLayer::default()
|
||||||
.with_writer(io::stderr)
|
.with_writer(io::stderr)
|
||||||
.with_indent_lines(true)
|
.with_indent_lines(true)
|
||||||
@ -81,9 +86,9 @@ pub fn init_env_logger(env: &str) -> Result<(), Error> {
|
|||||||
.with_targets(true)
|
.with_targets(true)
|
||||||
.with_verbose_exit(verbose_entry_exit)
|
.with_verbose_exit(verbose_entry_exit)
|
||||||
.with_verbose_entry(verbose_entry_exit)
|
.with_verbose_entry(verbose_entry_exit)
|
||||||
.with_indent_amount(2);
|
.with_indent_amount(2)
|
||||||
#[cfg(all(parallel_compiler, debug_assertions))]
|
.with_thread_ids(verbose_thread_ids)
|
||||||
let layer = layer.with_thread_ids(true).with_thread_names(true);
|
.with_thread_names(verbose_thread_ids);
|
||||||
|
|
||||||
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
|
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
|
||||||
match env::var(format!("{env}_BACKTRACE")) {
|
match env::var(format!("{env}_BACKTRACE")) {
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
|
use rustc_data_structures::captures::Captures;
|
||||||
use rustc_data_structures::graph::dominators::{self, Dominators};
|
use rustc_data_structures::graph::dominators::{self, Dominators};
|
||||||
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
|
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
|
||||||
use rustc_index::bit_set::BitSet;
|
use rustc_index::bit_set::BitSet;
|
||||||
use rustc_index::{IndexSlice, IndexVec};
|
use rustc_index::{IndexSlice, IndexVec};
|
||||||
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
|
use rustc_middle::mir::{self, BasicBlock, TerminatorKind};
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
@ -36,9 +37,8 @@ impl CoverageGraph {
|
|||||||
}
|
}
|
||||||
let bcb_data = &bcbs[bcb];
|
let bcb_data = &bcbs[bcb];
|
||||||
let mut bcb_successors = Vec::new();
|
let mut bcb_successors = Vec::new();
|
||||||
for successor in
|
for successor in bcb_filtered_successors(&mir_body, bcb_data.last_bb())
|
||||||
bcb_filtered_successors(&mir_body, &bcb_data.terminator(mir_body).kind)
|
.filter_map(|successor_bb| bb_to_bcb[successor_bb])
|
||||||
.filter_map(|successor_bb| bb_to_bcb[successor_bb])
|
|
||||||
{
|
{
|
||||||
if !seen[successor] {
|
if !seen[successor] {
|
||||||
seen[successor] = true;
|
seen[successor] = true;
|
||||||
@ -80,10 +80,9 @@ impl CoverageGraph {
|
|||||||
// intentionally omits unwind paths.
|
// intentionally omits unwind paths.
|
||||||
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
|
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
|
||||||
// `catch_unwind()` handlers.
|
// `catch_unwind()` handlers.
|
||||||
let mir_cfg_without_unwind = ShortCircuitPreorder::new(&mir_body, bcb_filtered_successors);
|
|
||||||
|
|
||||||
let mut basic_blocks = Vec::new();
|
let mut basic_blocks = Vec::new();
|
||||||
for (bb, data) in mir_cfg_without_unwind {
|
for bb in short_circuit_preorder(mir_body, bcb_filtered_successors) {
|
||||||
if let Some(last) = basic_blocks.last() {
|
if let Some(last) = basic_blocks.last() {
|
||||||
let predecessors = &mir_body.basic_blocks.predecessors()[bb];
|
let predecessors = &mir_body.basic_blocks.predecessors()[bb];
|
||||||
if predecessors.len() > 1 || !predecessors.contains(last) {
|
if predecessors.len() > 1 || !predecessors.contains(last) {
|
||||||
@ -109,7 +108,7 @@ impl CoverageGraph {
|
|||||||
}
|
}
|
||||||
basic_blocks.push(bb);
|
basic_blocks.push(bb);
|
||||||
|
|
||||||
let term = data.terminator();
|
let term = mir_body[bb].terminator();
|
||||||
|
|
||||||
match term.kind {
|
match term.kind {
|
||||||
TerminatorKind::Return { .. }
|
TerminatorKind::Return { .. }
|
||||||
@ -316,11 +315,6 @@ impl BasicCoverageBlockData {
|
|||||||
pub fn last_bb(&self) -> BasicBlock {
|
pub fn last_bb(&self) -> BasicBlock {
|
||||||
*self.basic_blocks.last().unwrap()
|
*self.basic_blocks.last().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn terminator<'a, 'tcx>(&self, mir_body: &'a mir::Body<'tcx>) -> &'a Terminator<'tcx> {
|
|
||||||
&mir_body[self.last_bb()].terminator()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a successor from a branching BasicCoverageBlock (such as the arms of a `SwitchInt`)
|
/// Represents a successor from a branching BasicCoverageBlock (such as the arms of a `SwitchInt`)
|
||||||
@ -362,26 +356,28 @@ impl std::fmt::Debug for BcbBranch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the `Terminator`s non-unwind successors.
|
// Returns the subset of a block's successors that are relevant to the coverage
|
||||||
|
// graph, i.e. those that do not represent unwinds or unreachable branches.
|
||||||
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
|
// FIXME(#78544): MIR InstrumentCoverage: Improve coverage of `#[should_panic]` tests and
|
||||||
// `catch_unwind()` handlers.
|
// `catch_unwind()` handlers.
|
||||||
fn bcb_filtered_successors<'a, 'tcx>(
|
fn bcb_filtered_successors<'a, 'tcx>(
|
||||||
body: &'a mir::Body<'tcx>,
|
body: &'a mir::Body<'tcx>,
|
||||||
term_kind: &'a TerminatorKind<'tcx>,
|
bb: BasicBlock,
|
||||||
) -> Box<dyn Iterator<Item = BasicBlock> + 'a> {
|
) -> impl Iterator<Item = BasicBlock> + Captures<'a> + Captures<'tcx> {
|
||||||
Box::new(
|
let terminator = body[bb].terminator();
|
||||||
match &term_kind {
|
|
||||||
// SwitchInt successors are never unwind, and all of them should be traversed.
|
let take_n_successors = match terminator.kind {
|
||||||
TerminatorKind::SwitchInt { ref targets, .. } => {
|
// SwitchInt successors are never unwinds, so all of them should be traversed.
|
||||||
None.into_iter().chain(targets.all_targets().into_iter().copied())
|
TerminatorKind::SwitchInt { .. } => usize::MAX,
|
||||||
}
|
// For all other kinds, return only the first successor (if any), ignoring any
|
||||||
// For all other kinds, return only the first successor, if any, and ignore unwinds.
|
// unwind successors.
|
||||||
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
|
_ => 1,
|
||||||
// `next().into_iter()`) into the `mir::Successors` aliased type.
|
};
|
||||||
_ => term_kind.successors().next().into_iter().chain((&[]).into_iter().copied()),
|
|
||||||
}
|
terminator
|
||||||
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable),
|
.successors()
|
||||||
)
|
.take(take_n_successors)
|
||||||
|
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maintains separate worklists for each loop in the BasicCoverageBlock CFG, plus one for the
|
/// Maintains separate worklists for each loop in the BasicCoverageBlock CFG, plus one for the
|
||||||
@ -553,66 +549,28 @@ pub(super) fn find_loop_backedges(
|
|||||||
backedges
|
backedges
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ShortCircuitPreorder<
|
fn short_circuit_preorder<'a, 'tcx, F, Iter>(
|
||||||
'a,
|
|
||||||
'tcx,
|
|
||||||
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
|
|
||||||
> {
|
|
||||||
body: &'a mir::Body<'tcx>,
|
body: &'a mir::Body<'tcx>,
|
||||||
visited: BitSet<BasicBlock>,
|
|
||||||
worklist: Vec<BasicBlock>,
|
|
||||||
filtered_successors: F,
|
filtered_successors: F,
|
||||||
}
|
) -> impl Iterator<Item = BasicBlock> + Captures<'a> + Captures<'tcx>
|
||||||
|
where
|
||||||
impl<
|
F: Fn(&'a mir::Body<'tcx>, BasicBlock) -> Iter,
|
||||||
'a,
|
Iter: Iterator<Item = BasicBlock>,
|
||||||
'tcx,
|
|
||||||
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
|
|
||||||
> ShortCircuitPreorder<'a, 'tcx, F>
|
|
||||||
{
|
{
|
||||||
pub fn new(
|
let mut visited = BitSet::new_empty(body.basic_blocks.len());
|
||||||
body: &'a mir::Body<'tcx>,
|
let mut worklist = vec![mir::START_BLOCK];
|
||||||
filtered_successors: F,
|
|
||||||
) -> ShortCircuitPreorder<'a, 'tcx, F> {
|
|
||||||
let worklist = vec![mir::START_BLOCK];
|
|
||||||
|
|
||||||
ShortCircuitPreorder {
|
std::iter::from_fn(move || {
|
||||||
body,
|
while let Some(bb) = worklist.pop() {
|
||||||
visited: BitSet::new_empty(body.basic_blocks.len()),
|
if !visited.insert(bb) {
|
||||||
worklist,
|
|
||||||
filtered_successors,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<
|
|
||||||
'a,
|
|
||||||
'tcx,
|
|
||||||
F: Fn(&'a mir::Body<'tcx>, &'a TerminatorKind<'tcx>) -> Box<dyn Iterator<Item = BasicBlock> + 'a>,
|
|
||||||
> Iterator for ShortCircuitPreorder<'a, 'tcx, F>
|
|
||||||
{
|
|
||||||
type Item = (BasicBlock, &'a BasicBlockData<'tcx>);
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
|
|
||||||
while let Some(idx) = self.worklist.pop() {
|
|
||||||
if !self.visited.insert(idx) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = &self.body[idx];
|
worklist.extend(filtered_successors(body, bb));
|
||||||
|
|
||||||
if let Some(ref term) = data.terminator {
|
return Some(bb);
|
||||||
self.worklist.extend((self.filtered_successors)(&self.body, &term.kind));
|
|
||||||
}
|
|
||||||
|
|
||||||
return Some((idx, data));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
})
|
||||||
|
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
||||||
let size = self.body.basic_blocks.len() - self.visited.count();
|
|
||||||
(size, Some(size))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ fn print_coverage_graphviz(
|
|||||||
" {:?} [label=\"{:?}: {}\"];\n{}",
|
" {:?} [label=\"{:?}: {}\"];\n{}",
|
||||||
bcb,
|
bcb,
|
||||||
bcb,
|
bcb,
|
||||||
bcb_data.terminator(mir_body).kind.name(),
|
mir_body[bcb_data.last_bb()].terminator().kind.name(),
|
||||||
basic_coverage_blocks
|
basic_coverage_blocks
|
||||||
.successors(bcb)
|
.successors(bcb)
|
||||||
.map(|successor| { format!(" {:?} -> {:?};", bcb, successor) })
|
.map(|successor| { format!(" {:?} -> {:?};", bcb, successor) })
|
||||||
|
@ -95,6 +95,7 @@ pub struct EarlyOtherwiseBranch;
|
|||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
||||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||||
|
// unsound: https://github.com/rust-lang/rust/issues/95162
|
||||||
sess.mir_opt_level() >= 3 && sess.opts.unstable_opts.unsound_mir_opts
|
sess.mir_opt_level() >= 3 && sess.opts.unstable_opts.unsound_mir_opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@ pub struct EnumSizeOpt {
|
|||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for EnumSizeOpt {
|
impl<'tcx> MirPass<'tcx> for EnumSizeOpt {
|
||||||
fn is_enabled(&self, sess: &Session) -> bool {
|
fn is_enabled(&self, sess: &Session) -> bool {
|
||||||
|
// There are some differences in behavior on wasm and ARM that are not properly
|
||||||
|
// understood, so we conservatively treat this optimization as unsound:
|
||||||
|
// https://github.com/rust-lang/rust/pull/85158#issuecomment-1101836457
|
||||||
sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3
|
sess.opts.unstable_opts.unsound_mir_opts || sess.mir_opt_level() >= 3
|
||||||
}
|
}
|
||||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||||
|
@ -34,7 +34,7 @@ pub struct RenameReturnPlace;
|
|||||||
|
|
||||||
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
||||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||||
// #111005
|
// unsound: #111005
|
||||||
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
|
sess.mir_opt_level() > 0 && sess.opts.unstable_opts.unsound_mir_opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1599,9 +1599,10 @@ options! {
|
|||||||
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
|
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
|
||||||
(default: no)"),
|
(default: no)"),
|
||||||
mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
|
mir_enable_passes: Vec<(String, bool)> = (Vec::new(), parse_list_with_polarity, [TRACKED],
|
||||||
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the specified passes to be \
|
"use like `-Zmir-enable-passes=+DestinationPropagation,-InstSimplify`. Forces the \
|
||||||
enabled, overriding all other checks. Passes that are not specified are enabled or \
|
specified passes to be enabled, overriding all other checks. In particular, this will \
|
||||||
disabled by other flags as usual."),
|
enable unsound (known-buggy and hence usually disabled) passes without further warning! \
|
||||||
|
Passes that are not specified are enabled or disabled by other flags as usual."),
|
||||||
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
|
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
|
||||||
"use line numbers relative to the function in mir pretty printing"),
|
"use line numbers relative to the function in mir pretty printing"),
|
||||||
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
|
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
|
||||||
|
@ -32,14 +32,11 @@ mod assembly;
|
|||||||
mod canonicalize;
|
mod canonicalize;
|
||||||
mod eval_ctxt;
|
mod eval_ctxt;
|
||||||
mod fulfill;
|
mod fulfill;
|
||||||
mod inherent_projection;
|
|
||||||
pub mod inspect;
|
pub mod inspect;
|
||||||
mod normalize;
|
mod normalize;
|
||||||
mod opaques;
|
|
||||||
mod project_goals;
|
mod project_goals;
|
||||||
mod search_graph;
|
mod search_graph;
|
||||||
mod trait_goals;
|
mod trait_goals;
|
||||||
mod weak_types;
|
|
||||||
|
|
||||||
pub use eval_ctxt::{
|
pub use eval_ctxt::{
|
||||||
EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt, UseGlobalCache,
|
EvalCtxt, GenerateProofTree, InferCtxtEvalExt, InferCtxtSelectExt, UseGlobalCache,
|
||||||
|
@ -18,6 +18,10 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
|
|||||||
use rustc_middle::ty::{ToPredicate, TypeVisitableExt};
|
use rustc_middle::ty::{ToPredicate, TypeVisitableExt};
|
||||||
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
|
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
|
||||||
|
|
||||||
|
mod inherent_projection;
|
||||||
|
mod opaques;
|
||||||
|
mod weak_types;
|
||||||
|
|
||||||
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
#[instrument(level = "debug", skip(self), ret)]
|
#[instrument(level = "debug", skip(self), ret)]
|
||||||
pub(super) fn compute_projection_goal(
|
pub(super) fn compute_projection_goal(
|
@ -7,7 +7,7 @@ use rustc_middle::traits::Reveal;
|
|||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_middle::ty::util::NotUniqueParam;
|
use rustc_middle::ty::util::NotUniqueParam;
|
||||||
|
|
||||||
use super::{EvalCtxt, SolverMode};
|
use crate::solve::{EvalCtxt, SolverMode};
|
||||||
|
|
||||||
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
pub(super) fn normalize_opaque_type(
|
pub(super) fn normalize_opaque_type(
|
Loading…
x
Reference in New Issue
Block a user