提交 58217bc9 编写于 作者: N Nicholas Nethercote

Replace uses of `parse_opt_*` with `parse_*` where possible.

This lets us specify the default at the options declaration point,
instead of using `.unwrap(default)` or `None | Some(default)` at some
use point far away. It also makes the code more concise.
上级 b9bcddc5
......@@ -347,7 +347,7 @@ pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
}
// The new pass manager is disabled by default.
config.new_llvm_pass_manager.unwrap_or(false)
config.new_llvm_pass_manager
}
pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
......
......@@ -858,18 +858,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
// *not* running dsymutil then the object files are the only source of truth
// for debug information, so we must preserve them.
if sess.target.target.options.is_like_osx {
match sess.opts.debugging_opts.run_dsymutil {
// dsymutil is not being run, preserve objects
Some(false) => return true,
// dsymutil is being run, no need to preserve the objects
Some(true) => return false,
// The default historical behavior was to always run dsymutil, so
// we're preserving that temporarily, but we're likely to switch the
// default soon.
None => return false,
}
return !sess.opts.debugging_opts.run_dsymutil;
}
false
......@@ -1324,11 +1313,11 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
// If -Zlink-native-libraries=false is set, then the assumption is that an
// external build system already has the native dependencies defined, and it
// will provide them to the linker itself.
if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
if sess.opts.debugging_opts.link_native_libraries {
add_local_native_libraries(cmd, sess, codegen_results);
}
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
if sess.opts.debugging_opts.link_native_libraries {
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
}
}
......@@ -1534,9 +1523,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
// OBJECT-FILES-NO, AUDIT-ORDER
// We want to prevent the compiler from accidentally leaking in any system libraries,
// so by default we tell linkers not to link to any default libraries.
if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
&& sess.target.target.options.no_default_libraries
{
if !sess.opts.cg.default_linker_libraries && sess.target.target.options.no_default_libraries {
cmd.no_default_libraries();
}
......
......@@ -384,7 +384,7 @@ fn debuginfo(&mut self) {
// If we are building without debuginfo enabled and we were called with
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
// found when linking to get rid of symbols from libstd.
if let Some(true) = self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
if self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
self.linker_arg("-S");
}
};
......
......@@ -115,7 +115,7 @@ pub struct ModuleConfig {
pub vectorize_slp: bool,
pub merge_functions: bool,
pub inline_threshold: Option<usize>,
pub new_llvm_pass_manager: Option<bool>,
pub new_llvm_pass_manager: bool,
}
impl ModuleConfig {
......
......@@ -375,7 +375,7 @@ fn test_codegen_options_tracking_hash() {
let mut opts = Options::default();
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
opts.cg.ar = Some(String::from("abc"));
opts.cg.ar = String::from("abc");
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
opts.cg.linker = Some(PathBuf::from("linker"));
......@@ -479,11 +479,11 @@ fn test_codegen_options_tracking_hash() {
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
opts = reference.clone();
opts.cg.debuginfo = Some(0xdeadbeef);
opts.cg.debuginfo = 0xdeadbeef;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
opts = reference.clone();
opts.cg.debuginfo = Some(0xba5eba11);
opts.cg.debuginfo = 0xba5eba11;
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
opts = reference.clone();
......
......@@ -2182,9 +2182,7 @@ fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<Poin
//
// For now, do not enable mutable_noalias by default at all, while the
// issue is being figured out.
let mutable_noalias =
tcx.sess.opts.debugging_opts.mutable_noalias.unwrap_or(false);
if mutable_noalias {
if tcx.sess.opts.debugging_opts.mutable_noalias {
PointerKind::UniqueBorrowed
} else {
PointerKind::Shared
......
......@@ -617,10 +617,6 @@ pub fn share_generics(&self) -> bool {
}
impl DebuggingOptions {
pub fn ui_testing(&self) -> bool {
self.ui_testing.unwrap_or(false)
}
pub fn diagnostic_handler_flags(&self, can_emit_warnings: bool) -> HandlerFlags {
HandlerFlags {
can_emit_warnings,
......@@ -628,7 +624,7 @@ pub fn diagnostic_handler_flags(&self, can_emit_warnings: bool) -> HandlerFlags
dont_buffer_diagnostics: self.dont_buffer_diagnostics,
report_delayed_bugs: self.report_delayed_bugs,
macro_backtrace: self.macro_backtrace,
deduplicate_diagnostics: self.deduplicate_diagnostics.unwrap_or(true),
deduplicate_diagnostics: self.deduplicate_diagnostics,
}
}
}
......@@ -1395,15 +1391,14 @@ fn parse_opt_level(
if max_o > max_c {
OptLevel::Default
} else {
match cg.opt_level.as_ref().map(String::as_ref) {
None => OptLevel::No,
Some("0") => OptLevel::No,
Some("1") => OptLevel::Less,
Some("2") => OptLevel::Default,
Some("3") => OptLevel::Aggressive,
Some("s") => OptLevel::Size,
Some("z") => OptLevel::SizeMin,
Some(arg) => {
match cg.opt_level.as_ref() {
"0" => OptLevel::No,
"1" => OptLevel::Less,
"2" => OptLevel::Default,
"3" => OptLevel::Aggressive,
"s" => OptLevel::Size,
"z" => OptLevel::SizeMin,
arg => {
early_error(
error_format,
&format!(
......@@ -1436,10 +1431,10 @@ fn select_debuginfo(
DebugInfo::Full
} else {
match cg.debuginfo {
None | Some(0) => DebugInfo::None,
Some(1) => DebugInfo::Limited,
Some(2) => DebugInfo::Full,
Some(arg) => {
0 => DebugInfo::None,
1 => DebugInfo::Limited,
2 => DebugInfo::Full,
arg => {
early_error(
error_format,
&format!(
......@@ -1502,10 +1497,10 @@ fn parse_libs(
}
fn parse_borrowck_mode(dopts: &DebuggingOptions, error_format: ErrorOutputType) -> BorrowckMode {
match dopts.borrowck.as_ref().map(|s| &s[..]) {
None | Some("migrate") => BorrowckMode::Migrate,
Some("mir") => BorrowckMode::Mir,
Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
match dopts.borrowck.as_ref() {
"migrate" => BorrowckMode::Migrate,
"mir" => BorrowckMode::Mir,
m => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
}
}
......
......@@ -613,7 +613,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
options! {CodegenOptions, CodegenSetter, basic_codegen_options,
build_codegen_options, "C", "codegen",
CG_OPTIONS, cg_type_desc, cgsetters,
ar: Option<String> = (None, parse_opt_string, [UNTRACKED],
ar: String = (String::new(), parse_string, [UNTRACKED],
"this option is deprecated and does nothing"),
linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
"system linker to link outputs with"),
......@@ -666,10 +666,10 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
"print remarks for these optimization passes (space separated, or \"all\")"),
no_stack_check: bool = (false, parse_bool, [UNTRACKED],
"the `--no-stack-check` flag is deprecated and does nothing"),
debuginfo: Option<usize> = (None, parse_opt_uint, [TRACKED],
debuginfo: usize = (0, parse_uint, [TRACKED],
"debug info emission level, 0 = no debug info, 1 = line tables only, \
2 = full debug info with variable and type information"),
opt_level: Option<String> = (None, parse_opt_string, [TRACKED],
opt_level: String = ("0".to_string(), parse_string, [TRACKED],
"optimize with possible levels 0-3, s, or z"),
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
"force use of the frame pointers"),
......@@ -681,7 +681,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
[TRACKED], "panic strategy to compile crate with"),
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
"enable incremental compilation"),
default_linker_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
"allow the linker to link its default libraries"),
linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
"linker flavor"),
......@@ -706,7 +706,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
identify_regions: bool = (false, parse_bool, [UNTRACKED],
"make unnamed regions display as '# (where # is some non-ident unique id)"),
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
"select which borrowck is used (`mir` or `migrate`)"),
time_passes: bool = (false, parse_bool, [UNTRACKED],
"measure time of each rustc pass"),
......@@ -806,7 +806,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
"print the result of the monomorphization collection pass"),
mir_opt_level: usize = (1, parse_uint, [TRACKED],
"set the MIR optimization level (0-3, default: 1)"),
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
mutable_noalias: bool = (false, parse_bool, [TRACKED],
"emit noalias metadata for mutable references (default: no)"),
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
"dump MIR state to file.
......@@ -816,7 +816,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
`foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
`foo | bar` all passes for function names containing 'foo' or 'bar'."),
dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED],
dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
"the directory the MIR is dumped into"),
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
"in addition to `.mir` files, create graphviz `.dot` files"),
......@@ -890,13 +890,16 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
`hir,typed` (HIR with types for each node),
`hir-tree` (dump the raw HIR),
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
// The default historical behavior was to always run dsymutil, so we're
// preserving that temporarily, but we're likely to switch the default
// soon.
run_dsymutil: bool = (true, parse_bool, [TRACKED],
"run `dsymutil` and delete intermediate object files"),
ui_testing: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
ui_testing: bool = (false, parse_bool, [UNTRACKED],
"format compiler diagnostics in a way that's better suitable for UI testing"),
embed_bitcode: bool = (false, parse_bool, [TRACKED],
"embed LLVM bitcode in object files"),
strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
strip_debuginfo_if_disabled: bool = (false, parse_bool, [TRACKED],
"tell the linker to strip debuginfo when building without debuginfo enabled"),
share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
"make the current crate share its generic instantiations"),
......@@ -936,7 +939,7 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
insert_sideeffect: bool = (false, parse_bool, [TRACKED],
"fix undefined behavior when a thread doesn't eventually make progress \
(such as entering an empty infinite loop) by inserting llvm.sideeffect"),
deduplicate_diagnostics: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
"deduplicate identical diagnostics"),
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [UNTRACKED],
"use Windows Control Flow Guard (`disabled`, `nochecks` or `checks`)"),
......@@ -944,9 +947,9 @@ fn parse_src_file_hash(slot: &mut Option<SourceFileHashAlgorithm>, v: Option<&st
"compile without linking"),
link_only: bool = (false, parse_bool, [TRACKED],
"link the `.rlink` file generated by `-Z no-link`"),
new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
new_llvm_pass_manager: bool = (false, parse_bool, [TRACKED],
"use new LLVM pass manager"),
link_native_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
"link native libraries in the linker invocation"),
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),
......
......@@ -899,7 +899,7 @@ fn default_emitter(
short,
macro_backtrace,
);
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing()))
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
} else {
let emitter = match dst {
None => EmitterWriter::stderr(
......@@ -920,7 +920,7 @@ fn default_emitter(
macro_backtrace,
),
};
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing()))
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
}
}
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
......@@ -931,7 +931,7 @@ fn default_emitter(
json_rendered,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing()),
.ui_testing(sopts.debugging_opts.ui_testing),
),
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
JsonEmitter::new(
......@@ -942,7 +942,7 @@ fn default_emitter(
json_rendered,
macro_backtrace,
)
.ui_testing(sopts.debugging_opts.ui_testing()),
.ui_testing(sopts.debugging_opts.ui_testing),
),
}
}
......
......@@ -185,7 +185,7 @@ pub fn new_handler(
debugging_opts.terminal_width,
false,
)
.ui_testing(debugging_opts.ui_testing()),
.ui_testing(debugging_opts.ui_testing),
)
}
ErrorOutputType::Json { pretty, json_rendered } => {
......@@ -194,7 +194,7 @@ pub fn new_handler(
});
Box::new(
JsonEmitter::stderr(None, source_map, pretty, json_rendered, false)
.ui_testing(debugging_opts.ui_testing()),
.ui_testing(debugging_opts.ui_testing),
)
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册