Convenience funcs for some_option.unwrap_or(...)
This ensures consistent handling of default values for options that are None if not specified on the command line.
This commit is contained in:
parent
4f550f1f93
commit
36c639a2ce
15 changed files with 29 additions and 55 deletions
|
@ -561,7 +561,7 @@ fn test_debugging_options_tracking_hash() {
|
|||
tracked!(link_only, true);
|
||||
tracked!(merge_functions, Some(MergeFunctions::Disabled));
|
||||
tracked!(mir_emit_retag, true);
|
||||
tracked!(mir_opt_level, Some(3));
|
||||
tracked!(mir_opt_level, 3);
|
||||
tracked!(mutable_noalias, true);
|
||||
tracked!(new_llvm_pass_manager, true);
|
||||
tracked!(no_codegen, true);
|
||||
|
|
|
@ -663,12 +663,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
no_builtins: tcx.sess.contains_name(&attrs, sym::no_builtins),
|
||||
panic_runtime: tcx.sess.contains_name(&attrs, sym::panic_runtime),
|
||||
profiler_runtime: tcx.sess.contains_name(&attrs, sym::profiler_runtime),
|
||||
symbol_mangling_version: tcx
|
||||
.sess
|
||||
.opts
|
||||
.debugging_opts
|
||||
.symbol_mangling_version
|
||||
.unwrap_or(SymbolManglingVersion::default()),
|
||||
symbol_mangling_version: tcx.sess.opts.debugging_opts.get_symbol_mangling_version(),
|
||||
|
||||
crate_deps,
|
||||
dylib_dependency_formats,
|
||||
|
|
|
@ -22,7 +22,6 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
|||
use rustc_middle::ty::{
|
||||
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeFoldable,
|
||||
};
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{def_id::DefId, Span};
|
||||
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout};
|
||||
|
@ -709,7 +708,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
return None;
|
||||
}
|
||||
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) >= 3 {
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 3 {
|
||||
self.eval_rvalue_with_identities(rvalue, place)
|
||||
} else {
|
||||
self.use_ecx(|this| this.ecx.eval_rvalue_into_place(rvalue, place))
|
||||
|
@ -887,8 +886,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
|
||||
/// Returns `true` if and only if this `op` should be const-propagated into.
|
||||
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
|
||||
let mir_opt_level =
|
||||
self.tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT);
|
||||
let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
|
||||
|
||||
if mir_opt_level == 0 {
|
||||
return false;
|
||||
|
@ -1058,7 +1056,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
|
|||
|
||||
// Only const prop copies and moves on `mir_opt_level=2` as doing so
|
||||
// currently slightly increases compile time in some cases.
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) >= 2 {
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
|
||||
self.propagate_operand(operand)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,6 @@ use rustc_middle::mir::{
|
|||
Rvalue, Statement, StatementKind, Terminator, TerminatorKind,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
|
||||
// Empirical measurements have resulted in some observations:
|
||||
// - Running on a body with a single block and 500 locals takes barely any time
|
||||
|
@ -130,7 +129,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
|
|||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
// Only run at mir-opt-level=2 or higher for now (we don't fix up debuginfo and remove
|
||||
// storage statements at the moment).
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) <= 1 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::{transform::MirPass, util::patch::MirPatch};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::{Ty, TyCtxt};
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use super::simplify::simplify_cfg;
|
||||
|
@ -27,7 +26,7 @@ pub struct EarlyOtherwiseBranch;
|
|||
|
||||
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) < 2 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
|
||||
return;
|
||||
}
|
||||
trace!("running EarlyOtherwiseBranch on {:?}", body.source);
|
||||
|
|
|
@ -9,7 +9,6 @@ use rustc_middle::mir::visit::*;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::subst::Subst;
|
||||
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
|
@ -38,7 +37,7 @@ struct CallSite<'tcx> {
|
|||
|
||||
impl<'tcx> MirPass<'tcx> for Inline {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) < 2 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::transform::MirPass;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
|
||||
pub struct MatchBranchSimplification;
|
||||
|
||||
|
@ -39,7 +38,7 @@ pub struct MatchBranchSimplification;
|
|||
|
||||
impl<'tcx> MirPass<'tcx> for MatchBranchSimplification {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) <= 1 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level <= 1 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ use rustc_middle::mir::visit::Visitor as _;
|
|||
use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::borrow::Cow;
|
||||
|
||||
|
@ -374,7 +373,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
|
|||
}
|
||||
|
||||
fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT);
|
||||
let mir_opt_level = tcx.sess.opts.debugging_opts.mir_opt_level;
|
||||
|
||||
// Lowering generator control-flow and variables has to happen before we do anything else
|
||||
// to them. We run some optimizations before that, because they may be harder to do on the state
|
||||
|
|
|
@ -5,13 +5,12 @@ use crate::transform::{simplify, MirPass};
|
|||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
|
||||
pub struct MultipleReturnTerminators;
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for MultipleReturnTerminators {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) < 3 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ use rustc_index::bit_set::HybridBitSet;
|
|||
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
|
||||
use rustc_middle::mir::{self, BasicBlock, Local, Location};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
|
||||
use crate::transform::MirPass;
|
||||
|
||||
|
@ -35,7 +34,7 @@ pub struct RenameReturnPlace;
|
|||
|
||||
impl<'tcx> MirPass<'tcx> for RenameReturnPlace {
|
||||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut mir::Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) == 0 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,12 @@ use crate::transform::MirPass;
|
|||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::MIR_OPT_LEVEL_DEFAULT;
|
||||
|
||||
pub struct UnreachablePropagation;
|
||||
|
||||
impl MirPass<'_> for UnreachablePropagation {
|
||||
fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level.unwrap_or(MIR_OPT_LEVEL_DEFAULT) < 3 {
|
||||
if tcx.sess.opts.debugging_opts.mir_opt_level < 3 {
|
||||
// Enable only under -Zmir-opt-level=3 as in some cases (check the deeply-nested-opt
|
||||
// perf benchmark) LLVM may spend quite a lot of time optimizing the generated code.
|
||||
return;
|
||||
|
|
|
@ -174,8 +174,6 @@ pub enum MirSpanview {
|
|||
Block,
|
||||
}
|
||||
|
||||
pub const MIR_OPT_LEVEL_DEFAULT: usize = 1;
|
||||
|
||||
#[derive(Clone, PartialEq, Hash)]
|
||||
pub enum LinkerPluginLto {
|
||||
LinkerPlugin(PathBuf),
|
||||
|
@ -214,12 +212,6 @@ pub enum SymbolManglingVersion {
|
|||
V0,
|
||||
}
|
||||
|
||||
impl SymbolManglingVersion {
|
||||
pub fn default() -> Self {
|
||||
SymbolManglingVersion::Legacy
|
||||
}
|
||||
}
|
||||
|
||||
impl_stable_hash_via_hash!(SymbolManglingVersion);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Hash)]
|
||||
|
@ -700,6 +692,10 @@ impl DebuggingOptions {
|
|||
deduplicate_diagnostics: self.deduplicate_diagnostics,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_symbol_mangling_version(&self) -> SymbolManglingVersion {
|
||||
self.symbol_mangling_version.unwrap_or(SymbolManglingVersion::Legacy)
|
||||
}
|
||||
}
|
||||
|
||||
// The type of entry function, so users can have their own entry functions
|
||||
|
@ -1779,18 +1775,15 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
|||
Some(SymbolManglingVersion::V0) => {}
|
||||
}
|
||||
|
||||
match debugging_opts.mir_opt_level {
|
||||
Some(level) if level > 1 => {
|
||||
early_warn(
|
||||
error_format,
|
||||
&format!(
|
||||
"`-Z mir-opt-level={}` (any level > 1) enables function inlining, which \
|
||||
limits the effectiveness of `-Z instrument-coverage`.",
|
||||
level,
|
||||
),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
if debugging_opts.mir_opt_level > 1 {
|
||||
early_warn(
|
||||
error_format,
|
||||
&format!(
|
||||
"`-Z mir-opt-level={}` (any level > 1) enables function inlining, which \
|
||||
limits the effectiveness of `-Z instrument-coverage`.",
|
||||
debugging_opts.mir_opt_level,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -970,7 +970,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||
mir_emit_retag: bool = (false, parse_bool, [TRACKED],
|
||||
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
|
||||
(default: no)"),
|
||||
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED],
|
||||
mir_opt_level: usize = (1, parse_uint, [TRACKED],
|
||||
"MIR optimization level (0-3; default: 1)"),
|
||||
mutable_noalias: bool = (false, parse_bool, [TRACKED],
|
||||
"emit noalias metadata for mutable references (default: no)"),
|
||||
|
|
|
@ -245,11 +245,7 @@ fn compute_symbol_name(
|
|||
// 2. we favor `instantiating_crate` where possible (i.e. when `Some`)
|
||||
let mangling_version_crate = instantiating_crate.unwrap_or(def_id.krate);
|
||||
let mangling_version = if mangling_version_crate == LOCAL_CRATE {
|
||||
tcx.sess
|
||||
.opts
|
||||
.debugging_opts
|
||||
.symbol_mangling_version
|
||||
.unwrap_or(SymbolManglingVersion::default())
|
||||
tcx.sess.opts.debugging_opts.get_symbol_mangling_version()
|
||||
} else {
|
||||
tcx.symbol_mangling_version(mangling_version_crate)
|
||||
};
|
||||
|
|
|
@ -85,7 +85,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
|
|||
// run on the unoptimized MIR. On the other hand this results in some false negatives. If
|
||||
// MIR passes can be enabled / disabled separately, we should figure out, what passes to
|
||||
// use for Clippy.
|
||||
config.opts.debugging_opts.mir_opt_level = Some(0);
|
||||
config.opts.debugging_opts.mir_opt_level = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue